2011-12-21 98 views
1

單擊一個按鈕時,會向返回多個多邊形路徑的服務器端發出AJAX請求。這些多邊形然後被繪製到地圖上。鼠標懸停事件不會觸發Polygon

問題:我爲mouseovermouseout事件添加了事件處理程序。但是,他們似乎並沒有開火。處理程序包含console.log,它不在mouseover上執行。這可能是什麼造成的?

JS代碼

$("#button").click(function() { 
    $.getJSON(base_url + 'main/get', 
       function(json) { 

        for(var i = 0; i < json.length; i++) { 

         decoded_path = google.maps.geometry.encoding.decodePath(json[i].encoded_path); 

         var polyOptions = { 
            strokeColor: "#4794b8", 
            strokeOpacity: 0.7, 
            strokeWeight: 1.5, 
            fillColor: "#000", 
            fillOpacity: 0.1, 
            path: decoded_path, 
            clickable: false, 
            map: map 
          } 
         var polygon = new google.maps.Polygon(polyOptions); 
         array_polyline.push(polygon); 

         // Add Mouseover/Mouseout Listeners 
         google.maps.event.addListener(polygon, "mouseover", function(){ console.log('Mouseover'); this.setOptions({fillOpacity: 0}); }); 
         google.maps.event.addListener(polygon, "mouseout", function(){ this.setOptions({fillOpacity: 0.1}); }); 

        } 

     }); 
}); 
+0

當代碼運行時,你得到任何錯誤? – ManseUK 2011-12-21 22:28:51

+0

@ManseUK代碼運行時沒有錯誤 – Nyxynyx 2011-12-21 22:29:43

+0

你可以看到地圖上的形狀? (對於愚蠢的基本問題抱歉 - 只要確保 - 因爲我可以看到你的代碼沒有錯) – ManseUK 2011-12-21 22:30:06

回答

2

你需要或者刪除clickable: false或使其clickable: true(默認)

你不必綁定到所有事件(即點擊),但clickable: false禁用所有的鼠標事件...

相關問題