mapbox/supercluster

the points with exactly the same coordinates are not clustered together

dbssAlan opened this issue · 2 comments

Hello, I found that the points with exactly the same coordinates are not clustered together, but overlapped. Excuse me, is this a bug or an aggregation strategy?

"supercluster": "^7.1.3",
"mapbox-gl": "1.13.1",
"react-mapbox-gl": "4.8.2"

code:


export function geoToCluster(
  features: Supercluster.PointFeature<Supercluster.AnyProps>[],
  map: mapboxgl.Map,
  minZoom: number,
  maxZoom: number,
  radius: number
) {
  let zoom: number = Math.round(map.getZoom());
  let points: Supercluster.PointFeature<Supercluster.AnyProps>[] = features;

  if (!points) {
    return [];
  }

  const index: Supercluster = new Supercluster({
    minZoom: Math.floor(minZoom),
    maxZoom: Math.floor(maxZoom),
    radius: radius,
  });

  index.load(points);

  let bounds: LngLatBounds = map.getBounds();
  let clusterList = index.getClusters(
    [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()],
    zoom
  );

 ...
}

use:

newFeatures = geoToCluster(geoJson.features, map, 4, zoom, 40);

mockData:

[
{
    basic: {
      sn: "123",
      type: "string",
      name: "point5",
      location: "string",
      location_type: "string",
      operator: "string",
      longitude: 120,
      latitude: 31,
    },
    activated: true,
    online: true,
  },
  {
    basic: {
      sn: "123",
      type: "string",
      name: "point6",
      location: "string",
      location_type: "string",
      operator: "string",
      longitude: 120.001,
      latitude: 30.001,
    },
    activated: true,
    online: true,
  },
  {
    basic: {
      sn: "123",
      type: "string",
      name: "point6.2",
      location: "string",
      location_type: "string",
      operator: "string",
      longitude: 120.001,
      latitude: 30.001,
    },
    activated: true,
    online: true,
  }]

Points with the same coordinates should be clustered together. I won't be able to reproduce this from chunks of code above alone — please set up a minimal live test case (e.g. with JSBin or JSFiddle) that uses Supercluster without anything else.

Thank you! The problem is solved. I have a problem understanding the parameters. Pass a real-time changing value zoom into maxZoom. So sometimes there is a problem with zoom and Math.floor(zoom)