Skip to content

Same cluster is returned from two tiles #254

@HarelM

Description

@HarelM

I'm guessing this is related to a precision issue, but I wanted to report this anyway to make sure that's the root cause.
In the following example a cluster is requested from two different tiles and is returned from both of them.
This creates a duplication of the cluster (although one can filter by unique ID).
Let me know if you need more information in order to look into it.
This was originally reported here:

I just removed most of the code around it that maplibre/mapbox uses.

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/supercluster@8.0.0/dist/supercluster.min.js"></script>
  </head>
  <body>
    <script>
      const mountains = [
        {
            "name": "Ben More",
            "height": 966,
            "longitude": -6.0152005136723,
            "latitude": 56.424106997002,
            "description": ""
        },
        {
            "name": "A' Chioch",
            "height": 868,
            "longitude": -5.9993112842696,
            "latitude": 56.427318748488,
            "description": ""
        },
    ];

    const mountainFeatures = mountains.reduce(
        (acc, mountain) => {
            acc.features.push({
                type: "Feature",
                geometry: {
                    type: "Point",
                    coordinates: [mountain.longitude, mountain.latitude],
                },
                properties: {
                    name: mountain.name,
                    description: mountain.description,
                    height: mountain.height,
                },
            });
            return acc;
        },
        {
            type: "FeatureCollection",
            features: [],
        }
    );
      try {
        const index = new Supercluster({
          clusterRadius: 27
        });
        index.load(mountainFeatures.features);
        const a = index.getTile(1, 0, 0);
        const b = index.getTile(1, 1, 0);
        console.log(a.features.length + (b != null ? b.features.length : 0));
      } catch (ex) {
        console.log(ex.message);
      }
    </script>
  </body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions