supercluster
supercluster copied to clipboard
getClusters returns 0 or 1 points when given 2
I am trying to represent random points on a map using superclusters and mapbox.
I ran into an issue while testing for the two points: [ -60.44, -1.77]
and [-55.44, -5.77]
; running getClusters
with a supercluster instance set up as follows:
const index = new Supercluster({
log: true,
radius: 20,
extent: 256,
maxZoom: 3
})
Returns a single point (not cluster of 2) at zoom > 5
Can you provide a minimal live test case (e.g. on JSFiddle) for this?
Hey there @mourner, here is JSFiddle example of what I am facing. (Please check the console, I am logging all the clusters array generated by getClusters)
It also seems getCluster returns an empty array when given a single point
I think that I'm running into this issue as well, but it seems to work in production. @AsnelChristian were you able to resolve your issue?
Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib.
I have had a similar problem. I was not receiving points on a lower zoom level but I was receiving them on a higher one. I changed my radius to a higher number and that fixed the problem for me. Points that where before excluded are now part of the same cluster.
@AsnelChristian: Regarding your JSFiddle:
Hey there @mourner, here is JSFiddle example of what I am facing. (Please check the console, I am logging all the clusters array generated by getClusters)
This code hits a numerical precision issue. To see this, change your one line
const bbox = [_sw.lng, _sw.lat, _ne.lng, _ne.lat];
to:
const bbox = [_sw.lng, _sw.lat, _ne.lng, _ne.lat+0.000277777];
Although the LatLngBounds.extend() method tells us it will
Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
which would seem to indicate the LatLngBounds object would always be mutated to be inclusive of the points, the JSFiddle shows it's not so. One guess would be that the search bounds test goes wrong by one or two least-significant bits of a floating-point abscissa.
A workaround is to subtract or add some small epsilon to all the corners of the search box. My +0.000277777
above (one second) is probably much more than necessary. I added it to only ne.lat
to test a guess that only a single comparison happened to be exposing the failure mode.
p.s. I tried updating the JSFiddle's use of mapbox-gl-js/v1.11.0 to the latest v2.1.1, but saw the same failure.
Неа@mikeslinkman, я не смог получить исправление для этого. и пришлось переключиться на другую библиотеку.
what is the library?
Неа@mikeslinkman, я не смог получить исправление для этого. и пришлось переключиться на другую библиотеку.
what is the library?
I havent switched libraries for this if I remember correctly. So supercluster and mapbox
@mikeslinkman sorry, why can't a cluster with a zoom of 5-6 display clusters? I logged the whole tree and there is clusters on these zooms, but on the bbox that I give it - it cannot display the clusters...
Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib. what is the library?
Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib.
what is the library?
Like I've just said, I haven't switched libraries. Still using the ones mentioned above.
In regard to your question about the zoom levels I would not know either since I'm pretty sure I don't have that issue
@AsnelChristian what is the library?
Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib.
what is the library?
Like I've just said, I haven't switched libraries. Still using the ones mentioned above.
In regard to your question about the zoom levels I would not know either since I'm pretty sure I don't have that issue
sorry , accidentally pinged the wrong person 2 times