问题描述
我正在使用 Leaflet.markercluster 插件来聚集我的积分.
I am using the Leaflet.markercluster plugin to cluster my points.
但是,用户要求在集群视图和非集群视图之间切换的功能(基本上,他们希望以高缩放查看所有点).
However, users are asking for the functionality to switch between clustered and unclustered views (basically, they want to see all their points at a high zoom).
我知道我可以在特定缩放级别禁用集群:
I know that I can disable clustering at a specific zoom level:
markers = new L.MarkerClusterGroup({
disableClusteringAtZoom: 8,
})
但是,当我进一步缩小时,如何强制所有内容取消聚类?
How can I force everything to uncluster when I am further zoomed out, though?
推荐答案
您可能会对 感兴趣Leaflet.MarkerCluster.Freezable 插件.
它在 Leaflet.markercluster 上提供了额外的方法,包括 disableClustering()
和 enableClustering()
,它们使您能够以编程方式取消集群/集群(例如单击按钮)无需用户放大/缩小.
It provides extra methods on Leaflet.markercluster, including disableClustering()
and enableClustering()
, which enable you to uncluster / cluster programmatically (e.g. on a button click) without needing the user to zoom in/out.
另请参阅插件演示页面.
当然,每次调用 disableClustering()
时都应该小心,因为您可能会立即在地图上加载 all 标记(如果您将其缩小到最大程度).如果尝试加载数千个标记,您可能会冻结浏览器甚至崩溃.
Of course, you should be careful whenever you call disableClustering()
, since you may instantly load all your markers on map (if you are zoomed out to their full extent). If that tries loading thousands of markers, you may freeze your browser or even crash it.
免责声明:我是这个插件的作者.
这篇关于使用 Leaflet markercluster,如何在不更改缩放级别的情况下在集群和非集群之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!