【问题标题】:Leaflet: Markers hidden when panning map传单:平移地图时隐藏的标记
【发布时间】:2018-01-31 12:01:18
【问题描述】:

我已经使用 DivIcons 实现了一个带有几个不同自定义标记的 Leaflet 地图。

它在桌面浏览器中运行良好,但是当我在移动设备上平移地图时,当前在视口中不可见的标记似乎被隐藏了,直到我停止平移地图。

是否有任何选项可以禁用此行为?理想情况下,我希望始终保持标记。

我应该提到我也在使用 MarkerCluster 插件。

【问题讨论】:

    标签: leaflet


    【解决方案1】:

    这就是 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.
      }
    });
    

    【讨论】:

    • 谢谢! removeOutsideVisibleBounds 正是我想要的。
    猜你喜欢
    • 2017-08-18
    • 2018-11-28
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多