【问题标题】:How can i prevent leaflet from dragging the map to fit marker popups?如何防止传单拖动地图以适应标记弹出窗口?
【发布时间】:2013-05-23 11:22:58
【问题描述】:

目前我们正在使用 gmaps 进行传单项目,但我遇到了一个小问题。

添加多个标记(每个标记都有一个弹出窗口)后,我们希望将它们全部打开。

为此,我使用以下代码:

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

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

页面加载时一切正常。

但是失败的场景来了:

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

【问题讨论】:

    标签: javascript leaflet


    【解决方案1】:

    我相信您指的是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

    【讨论】:

    • omg... 我一直认为这是一个错误,它是由openAllPopUp-Hack 引起的。从未想过弹出对象中的简单选项.. 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2012-06-07
    相关资源
    最近更新 更多