PruneCluster icon indicating copy to clipboard operation
PruneCluster copied to clipboard

Spiderfy at any zoom level

Open turbobuilt opened this issue 9 years ago • 5 comments

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.

turbobuilt avatar May 22 '15 18:05 turbobuilt

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();)

fungiboletus avatar May 24 '15 16:05 fungiboletus

How can i get the markersInArea if i only can get the marker?

bekakst avatar Jul 15 '15 08:07 bekakst

Like this: var markersInArea = pruneCluster.Cluster.FindMarkersInArea(cluster.bounds);

fungiboletus avatar Jul 15 '15 09:07 fungiboletus

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 avatar Jul 15 '15 09:07 bekakst

@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.

fungiboletus avatar Jul 17 '15 07:07 fungiboletus