[英]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 . 目前我们正在制作一个带有gmaps的传单项目,我遇到了一些问题。
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. 在
pageload
之后,用户zooms in
并且一些标记out of the “view area”
用户out of the “view area”
。
few seconds later, the website loads new position data
(for the markers) using a rest interface
. 几秒钟后,网站
using a rest interface
加载new position data
(用于标记)。
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
. 并且此
marker.openPopup()
触发, map moves
, popup fits in the “view area” of the user
。
How can i prevent leaflet to drag the map
in this case? 在这种情况下,如何
prevent leaflet to drag the map
?
I believe you are referring to the autoPan
property? 我相信你指的是
autoPan
属性? From the API: Set it to false if you don't want the map to do panning animation to fit the opened popup.
从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 http://leafletjs.com/reference.html#popup
So when creating your Popup, just pass in the option autoPan: false
因此,在创建Popup时,只需传入选项
autoPan: false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.