最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can i prevent leaflet from dragging the map to fit marker popups? - Stack Overflow

programmeradmin5浏览0评论

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 es 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?

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 es 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?

Share Improve this question edited May 23, 2013 at 11:45 Hariharan 3,2634 gold badges21 silver badges31 bronze badges asked May 23, 2013 at 11:22 gies0rgies0r 5,2394 gold badges46 silver badges55 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

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./reference.html#popup

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

发布评论

评论列表(0)

  1. 暂无评论