Mat*_*iby 4 google-maps google-maps-api-3
var polygon = new GPolygon(polylines[0],"#FFFFFF", 1, 1.0, color,opacity);
polygon.hid = this.id;
polygon.heat = this.heat;
google.maps.event.addListener(polygon, 'click', function(point) {
HoodsUnselect(active_hood_id);
active_hood_id = polygon.hid;
polygon.setOptions({fillColor: '#2948e4', fillOpacity: 0.50 });
//polygon.setFillStyle( { color:'#2948e4',opacity:'0.50' } );
if (point) {
map.openInfoWindowHtml(point, the_list); // open info window where user clicked
} else {
map.openInfoWindowHtml(polygon.getBounds().getCenter(), the_list); // open info window at the center of polygon
}
});
Run Code Online (Sandbox Code Playgroud)
Dan*_*llo 15
除了Tony的回答,openInfoWindowHtml()v3 API中没有方法.您必须创建一个InfoWindow对象,您可以在其上调用open()或close()方法.InfoWindow如果您只想同时看到一个对象,通常只需要一个对象:
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(yourOverlay, 'click', function () {
infoWindow.setContent('Some info on yourOverlay');
infoWindow.open(map);
});
Run Code Online (Sandbox Code Playgroud)
在Info Windows中,v2 API和v3 API之间的主要区别在于,在v3 API中,您可以同时打开多个信息窗口.这在v2 API中是不可能的.要打开多个Info窗口,您需要创建多个InfoWindow对象,而不是只创建一个所有标记(叠加层).
至于多边形,这是如何在v3 API中创建一个多边形(借用@Tony提到的例子):
var bermudaTriangle = new google.maps.Polygon({
paths: [
new google.maps.LatLng(25.774252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(32.321384, -64.75737)
],
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#FF0000",
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
Run Code Online (Sandbox Code Playgroud)