2013-02-13 44 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