mapbox / supercluster

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

Range function doesn't work with decimal zoom levels #247

Closed mrmascott10 closed 3 months ago

mrmascott10 commented 3 months ago

I use Leaflet.SmoothWheelZoom for most of my leaflet projects.

This means that the zoom level on my map is nearly always a decimal. When using this in conjunction with supercluster this causes an error. TypeError: Cannot read properties of undefined (reading 'range') at SuperCluster.getClusters (supercluster.js:281:24)

I've managed to fix this for my project by rounding the zoom level in the getClusters function. I changed the line below.

const tree = this.trees[this._limitZoom(Math.round(zoom))];

mourner commented 3 months ago

Yes, getClusters expects an integer zoom level because this is how hierarchical clustering works — by generating clusters at each integer zoom level. If you look at the docs for the method, it explicitly says it expects an integer zoom.