Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i prevent leaflet from dragging the map to fit marker popups?

currently we are working on a leaflet-project with gmaps and i´ve got a little problem .

After adding multiple markers (with a popup each) we want to open them all.

To do so, i´m using the following peace of code:

L.Map = L.Map.extend({
    openPopup: function(popup) {
    //        this.closePopup(); 
    this._popup = popup;

    return this.addLayer(popup).fire('popupopen', {
        popup: this._popup
    });
    }
});

On pageload everything works as expected.

But here comes the fail scenario:

After pageload the user zooms in and some markers are out of the “view area” of the user.

few seconds later, the website loads new position data (for the markers) using a rest interface.

After position data transmitted, i currently remove all markers and recreate them at the transmitted positions and open them.

And this marker.openPopup() triggers, that the map moves so, that the popup fits in the “view area” of the user.

How can i prevent leaflet to drag the map in this case?

like image 558
gies0r Avatar asked May 23 '13 11:05

gies0r


1 Answers

I believe you are referring to the autoPan property? From the API: Set it to false if you don't want the map to do panning animation to fit the opened popup.

http://leafletjs.com/reference.html#popup

So when creating your Popup, just pass in the option autoPan: false

like image 90
Patrick D Avatar answered Nov 01 '22 18:11

Patrick D