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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With