clusteradd and clusterremove events
See original GitHub issueI am trying to execute some logic when a few markers are sucked into a cluster, and then I want to do the inverse of that, when the markers become unclustered and just separate markers again. I assumed I would be able to use clusteradd and clusterremove, since plain markers have an add and remove event, but it doesn’t seem to work. Should it be working or is there another way to do this that you can think of?
To elaborate, I have some markers that are in the center of geoJson shapes. So whenever those markers become part of a cluster, I also want the shape to get sucked into the cluster, then when unclustered, I need the geoJson shape to come back.
I’ve been poking around in the source code, trying to figure out how to do this, and I came across this:
//Don't cluster non point data
if (!layer.getLatLng) {
this._nonPointGroup.addLayer(layer);
return this;
}
Is it possible to have other layers clustered? This looks by the comment like it is keeping anything other than markers from being clustered?
Alternatively, if you could point me to which section of the code is executed when points are sucked into a cluster, and which section of code executes when the cluster is unclustered, I’d be glad to fork and do a PR with another two parameters allowing the user to pass in functions that will be called when points are sucked into a cluster, and when points are separated back out of a cluster.
Issue Analytics
- State:
- Created 9 years ago
- Comments:16 (6 by maintainers)
Top GitHub Comments
Leaflet provides a getCenter method, which I am using to find the center of my bounds. It’s not always exact, but it works pretty well. Knowing that center position, would it be easier to implement?
I realize solving my specific problem might take a lot of work, but how about just implementing the ability to pass in a function that would be called when a cluster is created or destroyed? Since you already know when to merge or split, couldn’t we just add an optional function param to be called when a merge or split occurs?
Workaround to cluster Polygons (https://stackoverflow.com/a/45813585/2124535) using Turf.js’ centroid