使用Leaflet标记群集,如何在不更改缩放级别的情况下在群集和非群集之间切换? [英] With Leaflet markercluster, how can I switch between clustered and unclustered without changing zoom level?

查看:578
本文介绍了使用Leaflet标记群集,如何在不更改缩放级别的情况下在群集和非群集之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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()时都应该小心,因为您可以立即将标记全部全部加载到地图上(如果将其全部缩小).如果尝试加载数千个标记,则可能会冻结浏览器甚至崩溃.

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.

免责声明:我是该插件的作者.

Disclaimer: I am the author of this plugin.

这篇关于使用Leaflet标记群集,如何在不更改缩放级别的情况下在群集和非群集之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆