supercluster icon indicating copy to clipboard operation
supercluster copied to clipboard

Handle invalid input more gracefully

Open ademidun opened this issue 5 years ago • 2 comments

Some of my zoom levels are returning an empty list cluster, while other zoom levels are properly returning a list of clusters.

Screen Shot 2019-07-04 at 4 02 45 PM


  const index = new Supercluster({
    radius: 200,
    maxZoom: 16,
  });
  index.load(markers);
  const clusterResponse = {};

  const ZOOM_LEVELS = [9, 10, 11, 12, 13, 14, 15];
  ZOOM_LEVELS.forEach((zoomLevel) => {
    const clusters = index.getClusters([-180, -85, 180, 85], zoomLevel);
    clusterResponse[zoomLevel.toString()] = clusters
      .map(cluster => ({
        id: cluster.id || cluster.properties.id,
        count: cluster.properties.cluster ? cluster.properties.point_count : 1,
        longitude: cluster.geometry.coordinates[0],
        latitude: cluster.geometry.coordinates[1],
      }));
  });

ademidun avatar Jul 04 '19 20:07 ademidun

Can you please provide a full reproducible minimal test case (including data)? There's isn't enough information to diagnose the issue.

mourner avatar Jul 05 '19 11:07 mourner

It turns out the problem is that if you have a list of markers and one of the points has a null latitude or longitude. All the clusters will fail to be created. Even if all the other markers have valid latitude or longitudes.

You can recreate it yourself if you have a list of markers with lat long values and set one of the points lat or long values to null.

I think this is a bug, currently we are working around it ourselves by filtering out points with lat or long. But I think the expected behavior would be:

  1. index. load() function to filter out invalid markers.

  2. A warning could be raised to let user know Warning: 5 markers were dropped due to invalid lat or long values

  3. Create a function index.getWarningMessages() to let the user know that certain points had to be filtered out due to invalid lat or long values and let the user know what points those were.

Here is the current workaround we are doing

const filteredMarkers = markers.map(marker => marker.latitude && marker.longitude)

@mourner curious to hear your thoughts?

ademidun avatar Jul 16 '19 13:07 ademidun