Google Map V3 - 一次只允许显示一个信息框 [英] Google Map V3 - Allow only one infobox to be displayed at a time

查看:28
本文介绍了Google Map V3 - 一次只允许显示一个信息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 infoWindow 移动到 infoBox 以获得更好看的信息窗口.

I'm moving from infoWindow to infoBox for better looking info windows.

我在地图上有许多标记.我想要做的是当一个 infoBox 已经打开时,如果用户点击其他标记,当前的 infoBox 将自动关闭和新的 infoBox> 会打开,这样用户就不需要关闭当前的infoBox,并且每次只会显示一个infoBox.

I have a number of markers on the map. What I want to do is when one infoBox is already opened, if the user clicks on other markers, the current infoBox will close automatically and new infoBox will open so that the user does not need to close the current infoBox, and there will always be only one infoBox displayed at a time.

这是我当前解决方案的演示和代码http://jsfiddle.net/neo3000ultra/9jhAy/

Here's the demo and code of my current solution http://jsfiddle.net/neo3000ultra/9jhAy/

提前致谢!

推荐答案

更改此部分:

        google.maps.event.addListener(marker, "click", function (e) {
            ib.open(map, this);
        });

        var ib = new InfoBox(myOptions);

       google.maps.event.addListener(marker2, "click", function (e) {
            ib2.open(map, this);
        });

        var ib2 = new InfoBox(myOptions2);

以下内容:

    var ib = new InfoBox();

    google.maps.event.addListener(marker, "click", function (e) {
        ib.close();
        ib.setOptions(myOptions)
        ib.open(map, this);
    });

   google.maps.event.addListener(marker2, "click", function (e) {
        ib.close();
        ib.setOptions(myOptions2)
        ib.open(map, this);
    });

适用于我,也在 IE9 中:http://jsfiddle.net/doktormolle/9jhAy/1/

Works for me, also in IE9: http://jsfiddle.net/doktormolle/9jhAy/1/

注意在打开 infoBox 之前使用 ib.close(),这似乎是诀窍.

Note the use of ib.close() before opening the infoBox, seems to be the trick.

这篇关于Google Map V3 - 一次只允许显示一个信息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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