我喜欢跟踪在Google Maps界面上打开的所有信息窗口(我将它们的名称存储在一个数组中),但是当它们通过每个窗口右上角的"x"关闭时,我想不出如何将它们从数组中删除.
Is there some sort of callback I can listen for? Or maybe I can do something like
addListener("close", infowindow1, etc
?
我喜欢跟踪在Google Maps界面上打开的所有信息窗口(我将它们的名称存储在一个数组中),但是当它们通过每个窗口右上角的"x"关闭时,我想不出如何将它们从数组中删除.
Is there some sort of callback I can listen for? Or maybe I can do something like
addListener("close", infowindow1, etc
?
我在这里找到的唯一一致的解决方案是保留指向infoWindow
的指针,并在需要验证它是否已关闭时判断其.getMap()
方法.
The reason for this is that clicking another element can cause the infoWindow to be dismissed for other reasons... without the closeclick
event firing.
var infoWindow = new google.maps.InfoWindow({ content: 'Something to put here.' });
infoWindow.open(map, infoWindow);
setInterval(function ()
{
console.log("infoWindow is bound to map: "+(infoWindow.getMap() ? true : false));
}, 1000);
... 如果你真的只关心infoWindow
是否使用"X"按钮关闭,那么监控closeclick
就可以了.然而,它可能或已经关闭还有其他原因.