Leaflet.markercluster icon indicating copy to clipboard operation
Leaflet.markercluster copied to clipboard

Disable clustering for clusters below a certain number?

Open Ethan925 opened this issue 9 years ago • 14 comments

Hello, quick question about your great leaflet plugin. Is there any way that I could make it so that my markers will no longer cluster if the cluster is below a certain number. For example, I don't want to see clusters smaller than a size of 5. Instead, I'd like to see all 5 (or 4, 3, 2) markers being displayed individually on the map. Thank you for your help!

Ethan925 avatar Sep 25 '14 16:09 Ethan925

Another possible solution to my issue that maybe you could help me with: Is it possible to toggle the clustering on/off? So a user could click on a button that's on the same page as the map and then enable and disable the clustering by clicking that button. That way they have the option to see individual markers rather than clusters if they wish to. Thanks!

Ethan925 avatar Sep 25 '14 19:09 Ethan925

  1. Nope, it's sort of complicated to implement well, so it hasn't been done. (There have been a few requests for it now, so maybe worth implementing)

  2. Nope. Remove the MCG from the map and add a FeatureGroup with the same markers to do achieve this.

danzel avatar Sep 25 '14 20:09 danzel

Ok, thank you for your quick response, I appreciate it!

Ethan925 avatar Sep 26 '14 15:09 Ethan925

Here's another vote for a parameter to set minimum number of markers to form a cluster. Perhaps as an option to set when the cluster in instantiated?

I'm using your markerCluster for the first time and it's very impressive. Nice bit of work! Thanks.

rbarkas avatar Oct 18 '14 06:10 rbarkas

Not sure how well this helps your guy's problems, but maxClusterRadius option set pretty low will prevent a lot of clusters from occurring and instead set smaller clusters.

rdenniston avatar Nov 01 '14 21:11 rdenniston

Love the clustering UI-- but I'm having the same issue as Ethan925. As the PM, I'd like to set a minimum number of items that form a cluster, so that any set of 5 or fewer items don't cluster. I'm not sure if using a fixed number or perhaps a minimum distance to determine when a cluster forms makes more sense...

smerrill7777 avatar Mar 03 '15 21:03 smerrill7777

:+1: for both options. Set a minimum number of markers and the posibility to toggle clustering with a function :-D

Liquid2Sky avatar Jun 22 '15 14:06 Liquid2Sky

  1. No clustering if less than X markers in it: similar to #499 (based on total markers in visible bounds) and #392 (but more about dynamic option change)

  2. Toggle clustering on/off: similar to #552 and #534. The current solution for this is to switch between a MCG and a standard layer/featureGroup. However if it were built in MCG, it could benefit from its awesome animation and functionality to remove markers outside view port (even though this should be straight forward to port into a featureGroup, if not already done).

ghybs avatar Sep 29 '15 21:09 ghybs

:+1: for no clustering below a certain number of markers!

Phyks avatar Oct 06 '15 18:10 Phyks

:+1: (bookmarking this issue)

johnnybaloney avatar Nov 20 '15 13:11 johnnybaloney

i think the maxClusterRadius will work pretty well . you should have a function that return the zoom level and another function that changes the maxClusterRadius according to zoom level. so with zoom level increase you should decrease the cluster radius to your preference .

emmjk avatar May 19 '16 19:05 emmjk

Hi, I have a question about mavrkercluster, which by the way is just amazing :-)

I have two things I would like to achieve:

  1. I have some data with people but I want to make sure that I don´t expose anyone´s home on the map as I have actual LongLat, My ideal would be to have a min cluster size say 5 so clusters always contain 5 elements and never become markers.

  2. The second one is more a feature suggestions. I would be very cool if the clusters were formed by data that belong together in a shape (for example post nr shape, or commune, or city) Then the cluster were formed based on the data in your results, a good example could be car manufacture, so in one post area you would have clusters forming based on the shape (in this case a particular post number) and then a cluster for each brand of car in different colors and when you get down to markers a marker for each brand of car in the color of the cluster or as an actual car brand icon/image

OK first one is a problem for me right now I need to solve, the second would be so awesome :-D

skranson avatar Nov 30 '16 20:11 skranson

i think the maxClusterRadius will work pretty well . you should have a function that return the zoom level and another function that changes the maxClusterRadius according to zoom level. so with zoom level increase you should decrease the cluster radius to your preference .

That is exactly the inverse what I personally want to achieve - I want to only have "worthwhile" clusters beyond a certain size - decreasing the maxClusterRadius would create even more smaller clusters ^^

xeruf avatar Feb 03 '21 11:02 xeruf

Still interested in disabling clustering below a certain number of markers.

I'm also interested if possible in not clustering markers that are on the exact same position, or seeing them as only one marker.

maudvd avatar Nov 19 '21 08:11 maudvd