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
}
});
发布于 2010-07-17 03:39:44
除了Tony's answer之外,v3接口中没有openInfoWindowHtml()
方法。您必须创建一个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);
});
当涉及到Info窗口时,Info API和v3 API之间的主要区别在于,在v3 API中,您可以同时打开多个Info窗口。这在v2应用编程接口中是不可能的。要打开多个信息窗口,您需要创建多个InfoWindow
对象,而不仅仅是为所有标记(覆盖)创建一个对象。
对于多边形,这是如何在v3接口(借用示例mentioned by @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);
发布于 2010-07-17 03:32:25
GPolyline的v3等效项是Polyline,GPolygon是Polygon。这两个都有你可以监听的点击事件。
更好的是,谷歌提供了Polyline examples和Polygon examples,包括one that listens for clicks and opens an infowindow。
https://stackoverflow.com/questions/3268099
复制相似问题