PruneCluster
PruneCluster copied to clipboard
Spiderfy at any zoom level
Hello,
First, thanks for a great plugin. I'm using this one instead of the other cluster plugin for a number of reasons, perhaps the primary one being the easy filtering.
Basically I am trying to cause close items to spiderfy at any zoom level, not just at the closest zoom level. I have set the cluster size and margin to small amounts so that it will not do much clustering at certain zoom levels. I'd like to use this plugin: https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet with this library, but it uses regular leaflet markers not the custom ones used here. I noticed that this plugin was mentioned in another issue, so I wanted to see if anyone has any experience/guidance in using it before I set out trying to figure it out myself.
Hello,
This plugin has his own "spiderfier" implementation, based on OverlappingMarkerSpiderfier's algorithm. It's not documented but you can use it like this :
leafletMap.fire('overlappingmarkers',{
cluster: pruneCluster,
markers: markersInArea,
center: spiderfierCenter,
marker: sourceMarker
});
cluster
is the prunecluster instance,
markers
is an array of PruneCluster markers,
center
is the center of the spiderfier (a Leaflet L.LatLng object).
marker
is the L.Marker object, clicked by the user. In your case you may not have one, so you can use a unattached L.Marker object. (for example : var sourceMarker = L.marker();
)
How can i get the markersInArea if i only can get the marker?
Like this:
var markersInArea = pruneCluster.Cluster.FindMarkersInArea(cluster.bounds);
if i have only marker and PruneCluster, and i want to open it not by click on cluster. As in markercluster zoomToShowLayer(marker) function. Can you help, please? I have found that PruneCluster has _objectsOnMap array of clusters, but i can't find my marker in these cluster. It just have the lastMarker. Is it possible to have not only the lastMarker, it is better to have all markers which are in a cluster.
@bekakst
I think PruneCluster.Cluster._clusters is an array of the clusters displayed on the map. Using the bounds of these clusters, you can determine which one contains your marker. You can then use the cluster bounds to zoom. Note: The bounds are a plain javascript object (with a typescript interface) and not Leaflet bounds.