如何阻止传单拖动地图以适应标记弹出窗口?

gie*_*s0r 8 javascript leaflet

目前我们正在制作一个带有gmaps的传单项目,我遇到了一些问题.

添加多个标记(每个都有一个弹出窗口)后,我们要打开它们.

为此,我使用以下代码安静:

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

    return this.addLayer(popup).fire('popupopen', {
        popup: this._popup
    });
    }
});
Run Code Online (Sandbox Code Playgroud)

在页面加载上一切都按预期工作.

但是这里出现了失败的情况:

之后pageload,用户zooms in和一些标记是out of the “view area”用户的.

几秒钟后,网站加载new position data(用于标记)using a rest interface.

在发送位置数据之后,我当前移除所有标记并在发送的位置重新创建它们并打开它们.

而这就marker.openPopup()触发了,那map moves就是那个popup fits in the “view area” of the user.

prevent leaflet to drag the map在这种情况下我该怎么办?

Pat*_*k D 12

我相信你指的是autoPan房产?来自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

因此,在创建Popup时,只需传入选项即可 autoPan: false