Google Maps API v3 信息窗口关闭事件/回调? [英] Google Maps API v3 infowindow close event/callback?

查看:26
本文介绍了Google Maps API v3 信息窗口关闭事件/回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢跟踪在我的 Google 地图界面上打开的任何和所有信息窗口(我将它们的名称存储在一个数组中),但是当它们关闭时我不知道如何将它们从我的数组中删除每一个右上角的x".

I like to keep track of any and all infowindows that are open on my Google Maps interface (I store their names in an array), but I can't figure out how to remove them from my array when they are closed via the "x" in the upper right hand corner of each one.

有什么我可以听的回调吗?或者我可以做类似的事情addListener("close", infowindow1, etc ?

Is there some sort of callback I can listen for? Or maybe I can do something like addListener("close", infowindow1, etc ?

推荐答案

我在这里找到的唯一一致的解决方案是保留一个指向 infoWindow 的指针并检查它的 .getMap() 方法,只要您需要验证它是否已关闭.

The only consistent solution I've found here is to retain a pointer to the infoWindow and check its .getMap() method whenever you need to validate whether it has been closed.

这样做的原因是点击另一个元素可能会导致 infoWindow 由于其他原因被关闭......没有 closeclick 事件触发.

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);

... 如果您实际上只关心是否使用X"按钮关闭了 infoWindow,那么监控 closeclick 就可以了.但是,它可能或已经关闭还有其他原因.

... If you literally only care if the infoWindow was closed using the "X" button, then monitoring closeclick is fine. However, there are other reasons it may be or have been closed.

这篇关于Google Maps API v3 信息窗口关闭事件/回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆