maplibre / maplibre-gl-js

MapLibre GL JS - Interactive vector tile maps in the browser
https://maplibre.org/maplibre-gl-js/docs/
Other
6.59k stars 708 forks source link

"undefined is not iterable" when adding GeometryCollection feature to cluster source #3560

Open rsimon opened 9 months ago

rsimon commented 9 months ago

maplibre-gl-js version: 3.6.2

browser: Chrome

If a GeoJSON FeatureCollection contains a Feature with a geometry of type: 'GeometryCollection', adding that FeatureCollection to a cluster data source currently seems to cause an error. I understand that this might simply not be a supported use case (given that clustering really only works with point features). But just want to report this, in case anyone has thoughts.

Link to Demonstration

Here's a minimal CodeSandbox, which adds the following FeatureCollection to a cluster layer:

{
  type: "FeatureCollection",
  features: [
    {
      id: 1,
      type: "Feature",
      properties: {},
      geometry: {
        type: "GeometryCollection",
        geometries: [
          {
            coordinates: [-80.845666, 32.0002152],
            type: "Point",
          },
          {
            coordinates: [-80.87, 32.1],
            type: "Point"
          }
        ]
      }
    }
  ]
}

CodeSandbox: https://codesandbox.io/p/sandbox/busy-cache-r8r5k9

Expected Behavior

Ideally, GeometryCollections with multiple points would end up in multiple clusters. If not possible, a more descriptive error message would be great to make spotting the problem easier.

Actual Behavior

When adding the FeatureCollection, the cluster layer breaks during rendering. The console prints an error:

maplibre-gl.js?v=6005537a:397 

Error {message: 'undefined is not iterable (cannot read property Symbol(Symbol.iterator))'}
message:  "undefined is not iterable (cannot read property Symbol(Symbol.iterator))"
HarelM commented 9 months ago

I think geometry collection is not well supported in general, not just in clustering...