2013-02-13 31 views
0

多边形显示正常,我在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); 

      }); 


     <%} %> 
+1

的可能重复[我怎么打开每个多边形不同的信息我已经创建了? Google maps api v3](http://stackoverflow.com/questions/13020757/how-do-i-open-different-information-for-each-polygon-ive-created-google-maps-a) – geocodezip 2013-02-13 21:26:19

+0

我还在引用该链接后有相同的问题。该用户能够使信息气泡工作,而不是他们想要的内容。我甚至不能让泡沫显示 – 2013-02-13 21:53:08

回答

2

对多边形打开信息窗口的关键是理解它是从一个标记(google.maps.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"? 
}); 

是什么“这“在你的代码?它是一个MVC对象的出口位置? A google.maps.Polygon没有。

that example我的代码:

google.maps.event.addListener(poly,'click', function(event) { 
    infowindow.setContent(contentString); 
    infowindow.setPosition(event.latLng); 
    infowindow.open(map); 
}); 
+0

这可以忽略 – 2013-02-13 23:02:18

+0

你为什么这么说? – geocodezip 2013-02-13 23:09:11

+0

你是对的。我错过了设置。谢谢你的帮助 – 2013-02-14 00:18:45