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

Empty clusters #135

Closed
itzsaga opened this issue Aug 23, 2019 · 1 comment
Closed

Empty clusters #135

itzsaga opened this issue Aug 23, 2019 · 1 comment

Comments

@itzsaga
Copy link

itzsaga commented Aug 23, 2019

I'm consistently having points disappear off the map at zoom levels of 9 or 10. It's not consistent on which zoom level is. I thought it might be #128 but then I cleaned the data. I'm hypothesizing there's something else about the data that I need to change/fix but I don't know what it is.

Video here: https://cargo.teamairship.com/EihXdM

I instantiate the cluster like this.

const collection = MapboxGL.geoUtils.makeFeatureCollection(groupFeatures);
const cluster = new Supercluster({ radius: 40, maxZoom: 16 });
cluster.load(collection.features);

I then call this function for onRegionDidChange on the MapboxGL.MapView component.

updateClusters = async () => {
  const sc = this.state.superCluster;
  if (sc) {
    type Bounds = [[number, number], [number, number]];
    const bounds: Bounds = await this._map.getVisibleBounds();

    const westLng = Math.round(bounds[1][0]);
    const southLat = Math.round(bounds[1][1]);
    const eastLng = Math.round(bounds[0][0]);
    const northLat = Math.round(bounds[0][1]);
    const zoom = Math.round(await this._map.getZoom());

    this.setState({
      superClusterClusters: sc.getClusters(
        [westLng, southLat, eastLng, northLat],
        zoom
      )
    });
  }
};

If I put a

console.log(sc.getClusters(
  [westLng, southLat, eastLng, northLat],
  zoom
))

in the callback I see when the clusters disappear.

Of note, this.state.superCluster is where I save the initial cluster and how I reference it afterwards. Although, all things considered I don't think how I'm managing things is what's causing it to fail.

Here's a gist of the dataset which is === to collection in the first code snippet.

@itzsaga
Copy link
Author

itzsaga commented Aug 23, 2019

So I figured this out. I originally added in the Math.round() because I was seeing issues. However, that might have been unrelated to my Supercluster implementation at the time. After removing that all is working correctly. The issue was the rounding was causing two numbers to be equal at times and thus there was no "box" for the clusters to be generated inside of.

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

No branches or pull requests

1 participant