鼠标悬停事件不会触发Polygon
问题描述:
单击一个按钮时,会向返回多个多边形路径的服务器端发出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}); });
}
});
});
答
你需要或者删除clickable: false
或使其clickable: true
(默认)
你不必绑定到所有事件(即点击),但clickable: false
禁用所有的鼠标事件...
当代码运行时,你得到任何错误? – ManseUK 2011-12-21 22:28:51
@ManseUK代码运行时没有错误 – Nyxynyx 2011-12-21 22:29:43
你可以看到地图上的形状? (对于愚蠢的基本问题抱歉 - 只要确保 - 因为我可以看到你的代码没有错) – ManseUK 2011-12-21 22:30:06