-1

我正在使用集群组。但是如何限制集群扩展级别。假设默认集群组加载大陆级别,然后单击。它扩展到更深层次,当第三次再次单击集群组时,它会扩展到国家级别。我想修复三个扩展级别的集群组不低于国家级别。

我尝试了 freezeAtZoom() 但它阻止集群组从第一级扩展..

4

1 回答 1

0

Your issue is still a little bit unclear.

Note first that when clicking on a cluster, it zooms to the extent of its child markers. This could represent a few zoom levels, depending on the actual child markers. It could even be directly the map's maximum zoom level, if all markers are really close one to each other. So there is no predefined target zoom level that the map will go to when you click, it all depends on the markers in that cluster.

Now if these markers do not change, and you can record the exact map's zoom level at which you want your clusters to no longer split apart on clicking, you have several ways to achieve that:

  • Define the map's maxZoom option to that zoom level, so that your users cannot go any deeper.
  • Add a map's "zoomend" event listener, so that if user goes deeper that your known zoom level, you freeze the cluster group to that recorded zoom. Remember that .freezeAtZoom(frozenZoom) can take an argument to specify at which zoom level the clusters should be frozen at, no matter the current zoom level.
  • Replace your individual markers by their equivalent cluster at your recorded zoom level ("country level"), maybe use Leaflet.markercluster singleMarkerMode option for styling, and iconCreateFunction option to override the counts and make them appear as if the clusters had many markers.
于 2016-08-03T09:58:31.723 回答