显示所有信息窗口打开 [英] Show all infowindows open

查看:106
本文介绍了显示所有信息窗口打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将自定义infowindows浮动在标记上,但是我注意到在任何时候只能打开一个标记。是否有解决方法?

I'm trying to have custom infowindows float above markers, however I noticed that only one marker can be opened at any one time. Is there a workaround to this?

下面是我现在制作的代码:

Here's the code I have produced at the moment:

downloadUrl("AllActivityxml.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
        var name = markers[i].getAttribute("id");
        var address = markers[i].getAttribute("id");
        var type = markers[i].getAttribute("venue_type");
        var point = new google.maps.LatLng(
            parseFloat(markers[i].getAttribute("lat")),
            parseFloat(markers[i].getAttribute("lng"))
        );

        var infowindow = new google.maps.InfoWindow();
        var html = "<b>" + point + "</b>hello <br/>" + type;
        var icon = customIcons[type] || {};
        var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow,
            zIndex: Math.round(latlng.lat()*-100000)<<5
        });

        markersArray.push(marker);
        bindInfoWindow(marker, map, infoWindow, html);        


        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(html); 
            infowindow.open(map,marker);
        });
    }
});

当您检查此地图,注意我无法一次打开2个以上的infowindows。为什么会这样?

And when you check this map, notice that I cannot open more than 2 infowindows at once. Why is that?

推荐答案

Google Maps API v3没有任何限制,一次只能提供一个InfowWindow。你需要编写你的代码来做到这一点。如果你想为每个标记设置一个InfoWindow,请打一个。

There is no limitation implicit to the Google Maps API v3 that makes only one InfowWindow available at a time. You need to write your code to do that. If you want an InfoWindow for each marker, make one.

有些东西像(未测试):

Some thing like (not tested):

function createMarker(latlng, html) {
   var contentString = html;
    var infowindow = new google.maps.InfoWindow();
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        zIndex: Math.round(latlng.lat()*-100000)<<5
        });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString); 
        infowindow.open(map,marker);
        });
}

这篇关于显示所有信息窗口打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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