我有一个使用Leaflet.markercluster的传单 map 插件。
簇在 map 上正确绘制,但我注意到即使我将 removeOutsideVisibleBounds
选项设置为 true
, View 之外的簇仍在渲染。
我可以判断的是,如果我通过按住鼠标按钮来平移 map ,则在平移时所有簇仍然可见。
集群组的配置如下:
let myCluster = L.markerClusterGroup({ spiderfyOnMaxZoom: false, removeOutsideVisibleBounds: true });
为了确保删除 View 之外的簇,我还缺少什么?
该项目在 Angular 5 中使用 ngx-leaflet。
最佳答案
您可能刚刚错过了 removeOutsideVisibleBounds
选项说明的这一部分(重点是我的):
removeOutsideVisibleBounds: Clusters and markers too far from the viewport are removed from the map for performance.
这个“太远”的意思是,它仍然将标记和簇保留在每个方向 1 个视口(viewport)大小的“缓冲区”区域内;除移动设备外,其缓冲区为0,以便更轻地占用设备内存。
因此,在桌面浏览器上,您必须将 map 平移超过 1 个 map 视口(viewport)大小,然后才能看到丢失的标记和簇,只有当您停止平移(释放鼠标)时,这些标记和簇才会重新出现。
如果您检查 source code :
Gets the maps visible bounds expanded in each direction by the size of the screen (so the user cannot see an area we do not cover in one pan)
关于angular - Leaflet MarkerCluster removeOutsideVisibleBounds 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50418715/