mapbox / supercluster

A very fast geospatial point clustering library for browsers and Node.
ISC License
2.08k stars 298 forks source link

Small density of clusters - parameters tweak ? #208

Closed pierreleripoll closed 1 year ago

pierreleripoll commented 1 year ago

Hi ! I tried supercluster with a d3 map in an Observable notebook : https://observablehq.com/@pierreleripoll/hello-supercluster-empty-problem I noticed that with "correct" parameters (my cluster radius is 40px and tile size is 512 px) the result is sometimes very bad in terms of visible cluster density on the map, as seen below :

Capture d’écran du 2022-10-09 11-15-45

While tweaking parameters, such as 2px cluster radius or huge tile extent size 4000px and +, can create nice results :

Capture d’écran du 2022-10-09 11-16-06

So I was wondering, maybe I'm not understanding the parameters correctly ? I can definitely live with tweaking parameters for a result that suits me, but I would appreciate a no-brainer where I just type my parameters and the result is always perfect :angel:

pierreleripoll commented 1 year ago

Hi ! I found my problem : the zoom level wasn't appropriate. I would to see a solid documentation about that but it's a bit complicated to translate d3 scale values to appropriate zoom level (as for leaflet or supercluster for example). If anyone experiences this problem in the futur I found this formula that fixes everything inside d3-tile docs

const z = Math.log2(zoom / tileSize); const z0 = Math.round(Math.max(z, 0));

And z0 is the parameter we should give to supercluster as zoom level.

My notebook works fine now :) https://observablehq.com/@pierreleripoll/hello-supercluster