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

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

问题描述

我从 infoWindow 移动到 infoBox ,以获得更好的信息窗口。

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



以下是我当前解决方案的演示和代码
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 =新的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/



注意使用 ib.close()在打开infoBox之前,似乎是一招。


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

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.

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

Thanks in advance!

解决方案

Change this part:

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

to the following:

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

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

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

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

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