Google Map V3 - Allow only one infobox to be displayed at a time

后端 未结 2 1474
庸人自扰
庸人自扰 2020-11-29 13:52

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 o

2条回答
  •  自闭症患者
    2020-11-29 14:24

    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.

提交回复
热议问题