How can I Open Multiple Popups in Leaflet Marker a

2019-06-14 09:23发布

Map` like this:

L.Map = L.Map.extend({
openPopup: function(popup) {
this._popup = popup;
        return this.addLayer(popup).fire('popupopen', {
            popup: this._popup
        });
    }
});

But I am using leaflet. Is there anyway to extent like so that i can prevent closing my marker popup?

L.mapbox.accessToken = constant.accessToken;
var map = L.mapbox.map('map', 'mapbox.streets', {zoomControl: true});

2条回答
地球回转人心会变
2楼-- · 2019-06-14 09:56

Update Dec 2017 Leaflet popup options have been extended to include { autoClose: false } which has the required effect :

 var my_marker = L.marker([my_lat, my_lng], {icon: my_icon})
                  .addTo(map)
                  .bindPopup('My Popup HTML', {closeOnClick: false, autoClose: false});
查看更多
老娘就宠你
3楼-- · 2019-06-14 10:01

Let me quote the Leaflet documentation on L.Popup:

Used to open popups in certain places of the map. Use Map.openPopup to open popups while making sure that only one popup is open at one time (recommended for usability), or use Map.addLayer to open as many as you want.

In order to open several popups, instantiate them using L.popup(latlng, options), then .addTo(map) them.

查看更多
登录 后发表回答