2
当创建像这样我的Google map markers,添加监听
我添加事件监听器 -
var infowindow = new google.maps.InfoWindow({
content: 'Hi there from Alabama!'
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.open(map, marker); // this displays the infowindow on mouseover
});
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close(); // this close the infowindow on mouseout
});
marker.addListener('click', function() {
google.maps.event.clearListeners(marker, 'mouseout');
// this removes the mouseout listener when the marker is clicked so that it stays
// present after mouseout.
});
上述作品一种享受,但是我也希望能够重新 - 在信息窗口关闭后添加mouseout
事件。
我试过新增这给我的功能 -
google.maps.event.addListener(infowindow, 'closeclick', function() {
google.maps.event.addListener(marker, 'mouseout');
// when the info window is closed the mouseout event is reinstated
// I also previously added an alert here to make sure it was hit!
});
这将创建标记好了,但是在行动上,我可以点击标记>鼠标移出和信息窗口保持目前>关闭infowindow。所有需要的行为。
但是再次悬停在标记信息窗口显示(如预期),但在碰到mouseout
事件,我得到 -
JavaScript runtime error: Unable to get property 'apply' of undefined or null reference
该错误是居住在谷歌API的JS文件,所以它是非常很难确定问题的根源在哪里。如何正确地恢复mouseout
事件infowindow
关闭?
亚瑟,好答案,我完全理解我们的逻辑,然而遗憾的是(甚至更具体减速)我仍然得到相同的未定义错误鼠标,任何其他想法? – Ebikeneser