关闭谷歌地图api v3中的任何开放信息窗口 [英] Closing any open info windows in google maps api v3

查看:196
本文介绍了关闭谷歌地图api v3中的任何开放信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,在给定的事件中(对于我来说,这恰好是在打开一个新的 google.maps.InfoWindow 时我想关闭任何其他当前打开的信息窗口,现在,我可以一次打开很多...但是我一次只打开一个。

As the title states, on a given event (for me this happens to be upon opening a new google.maps.InfoWindow I want to be able to close any other currently open info windows. Right now, I can open many at a time..but I want only 1 open at a time.

我正在动态创建信息窗口(即,我不知道会提前生成多少),所以在当前信息窗口的单击事件中(这是我希望所有其他打开的窗口关闭的位置),我没有任何参考其他打开的信息窗口上调用 close()。我想知道如何实现这一点。我不是一个有经验的JavaScript程序员,所以我不知道我是否需要在这里使用反射或类似的东西。

I am creating the info windows dynamically (i.e. I don't know ahead of time how many will be generated), so in the click event of the current info window (which is where I want all the other open ones closed) I don't have a reference to any of the other open info windows on which to call close(). I am wondering how I can achieve this. I am not an experienced JavaScript programmer so I don't know if I need to use reflection or something similar here.

最好的方法是将所有引用保存在某种集合中,然后循环遍历整个关闭它们的列表?

Would the best way be just to save all the references in some sort of collection, then loop through the list closing them all?

谢谢。

推荐答案

并通过创建全局信息窗口来修复它。

I ran into the same problem and fixed it by creating a global info window.

var infowindow = new google.maps.InfoWindow();

然后我有一个函数在click监听器上执行以下操作:

Then I have a function to do the following on the click listener:

function getInfoWindowEvent(marker) {
    infowindow.close()
    infowindow.setContent("This is where my HTML content goes.");
    infowindow.open(map, marker);
}

这实现了我认为您现在正在寻找的B / C在地图上只有一个信息窗口,我只需关闭它,重新加载内容并再次打开给定的标记。

This achieves what I think you're looking for b/c there is now only one info window on the map and I just close it, reload the content and open it again for the given marker.

这篇关于关闭谷歌地图api v3中的任何开放信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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