1
單擊一個按鈕時,會向返回多個多邊形路徑的服務器端發出AJAX請求。這些多邊形然後被繪製到地圖上。鼠標懸停事件不會觸發Polygon
問題:我爲mouseover
和mouseout
事件添加了事件處理程序。但是,他們似乎並沒有開火。處理程序包含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}); });
}
});
});
當代碼運行時,你得到任何錯誤? – ManseUK 2011-12-21 22:28:51
@ManseUK代碼運行時沒有錯誤 – Nyxynyx 2011-12-21 22:29:43
你可以看到地圖上的形狀? (對於愚蠢的基本問題抱歉 - 只要確保 - 因爲我可以看到你的代碼沒有錯) – ManseUK 2011-12-21 22:30:06