多边形显示正常,我在chrome中调试时没有看到任何错误。在c#代码中查询多边形的数据点,但与此问题无关。当我单击多边形时,js代码似乎会触发,但我没有得到任何信息气泡。我将在关于多边形的信息泡泡中添加信息,但需要首先让它弹出。任何帮助将不胜感激!
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: new google.maps.LatLng(30.2979536, -97.7470835),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
<%for(int i = 0; i < this.zips2.Count; ++i )%>
<%{ %>
<%if ( layerType == "Orders" )
{
GetOrderColor(zips3[i]);
}
else
{
GetAptColor(zips3[i]);
} %>
var paths = [<%=zips2[i]%>];
var color = "<%=color%>";
var shape = new google.maps.Polygon({
paths: paths,
strokeColor: color,
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: color,
fillOpacity: 0.35,
clickable: true
});
shape.setMap(map);
google.maps.event.addListener(shape, 'rightclick', function(event) {
var contentString = '<div id="content:">' + "Test" + '</div>';
infowindow1 = new google.maps.InfoWindow();
infowindow1.setContent(contentString);
infowindow1.open(map, this);
});
<%} %>
答案 0 :(得分:2)
在多边形上打开infoWindow的关键是要理解它与在标记(google.maps.InfoWindow)上打开infoWindow不同:
您的代码:
google.maps.event.addListener(shape, 'rightclick', function(event) {
var contentString = '<div id="content:">' + "Test" + '</div>';
infowindow1 = new google.maps.InfoWindow();
infowindow1.setContent(contentString);
infowindow1.open(map, this); // <--- what is "this"?
});
代码中的“this”是什么?是出口位置的MVC对象吗? google.maps.Polygon没有。
我的代码来自that example:
google.maps.event.addListener(poly,'click', function(event) {
infowindow.setContent(contentString);
infowindow.setPosition(event.latLng);
infowindow.open(map);
});