Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getClusters returns 0 or 1 points when given 2 #165

Open
AsnelChristian opened this issue Aug 11, 2020 · 14 comments
Open

getClusters returns 0 or 1 points when given 2 #165

AsnelChristian opened this issue Aug 11, 2020 · 14 comments
Labels

Comments

@AsnelChristian
Copy link

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

@mourner
Copy link
Member

mourner commented Aug 12, 2020

Can you provide a minimal live test case (e.g. on JSFiddle) for this?

@AsnelChristian
Copy link
Author

AsnelChristian commented Aug 12, 2020

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)

@AsnelChristian
Copy link
Author

It also seems getCluster returns an empty array when given a single point

@mikeslinkman
Copy link

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?

@AsnelChristian
Copy link
Author

Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib.

@lsmienk
Copy link

lsmienk commented Dec 2, 2020

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.

@dmullis
Copy link

dmullis commented Mar 9, 2021

@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.

@Wimmind
Copy link

Wimmind commented May 6, 2022

Неа@mikeslinkman, я не смог получить исправление для этого. и пришлось переключиться на другую библиотеку.

what is the library?

@mikeslinkman
Copy link

Неа@mikeslinkman, я не смог получить исправление для этого. и пришлось переключиться на другую библиотеку.

what is the library?

I havent switched libraries for this if I remember correctly. So supercluster and mapbox

@Wimmind
Copy link

Wimmind commented May 6, 2022

@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...

@Wimmind
Copy link

Wimmind commented May 6, 2022

Nope @mikeslinkman , I wasn't able to get a fix for this. and had to switch to a different lib.
what is the library?

@mikeslinkman
Copy link

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

@Wimmind
Copy link

Wimmind commented May 6, 2022

@AsnelChristian what is the library?

@Wimmind
Copy link

Wimmind commented May 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants