【发布时间】:2018-01-31 12:01:18
【问题描述】:
我已经使用 DivIcons 实现了一个带有几个不同自定义标记的 Leaflet 地图。
它在桌面浏览器中运行良好,但是当我在移动设备上平移地图时,当前在视口中不可见的标记似乎被隐藏了,直到我停止平移地图。
是否有任何选项可以禁用此行为?理想情况下,我希望始终保持标记。
我应该提到我也在使用 MarkerCluster 插件。
【问题讨论】:
标签: leaflet
我已经使用 DivIcons 实现了一个带有几个不同自定义标记的 Leaflet 地图。
它在桌面浏览器中运行良好,但是当我在移动设备上平移地图时,当前在视口中不可见的标记似乎被隐藏了,直到我停止平移地图。
是否有任何选项可以禁用此行为?理想情况下,我希望始终保持标记。
我应该提到我也在使用 MarkerCluster 插件。
【问题讨论】:
标签: leaflet
这就是 Leaflet.markercluster 插件removeOutsideVisibleBounds 选项的效果。
在桌面上,它将标记和集群保留在视口内 + 每个方向上 1 个额外的视口。
在移动设备上,它仅将它们保留在可见视口中。
另见https://github.com/Leaflet/Leaflet.markercluster/issues/316
您可以修改https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerClusterGroup.js#L1071-L1079 处的行以满足您的需要:
L.MarkerClusterGroup.include({
_getExpandedVisibleBounds: function() {
/*if (!this.options.removeOutsideVisibleBounds) {
return this._mapBoundsInfinite;
} else if (L.Browser.mobile) {
return this._checkBoundsMaxLat(this._map.getBounds());
}*/
// Always return the current viewport extended by 1 extra viewport in each direction.
return this._checkBoundsMaxLat(this._map.getBounds().pad(1)); // Padding expands the bounds by its own dimensions but scaled with the given factor.
}
});
【讨论】: