1
votes

I built a mapbox-gl js (v0.52) map where points are getting aggregated into clusters; much like in the clusters example from mapbox page.

The cluster color needs to be a function of an aggregation of individual points properties: For simplicity, say each point has a status property, which determine its color, and the color of a cluster should just be the color corresponding to the max of each of its points' status values.

Example geojson data would look like:

const geoData = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {
        id: 'fakeid11',
        status: 20,
      },
      geometry: {
        type: 'Point',
        coordinates: [-151.5129, 63.1016, 0]
      }
    },
    {
      type: 'Feature',
      properties: {
        id: 'fakeid22',
        status: 10,
      },
      geometry: {
        type: 'Point',
        coordinates: [-150.4048, 63.1224, 105.5]
      }
    }
  ]
};

I am trying to use clusterProperties to compute the aggregation as described in the api docs, similar to this example from the source code, to create this layer:

map.addSource('earthquakes', {
  type: 'geojson',
  data: geoData,
  cluster: true,
  clusterMaxZoom: 14, // Max zoom to cluster points on
  clusterRadius: 50, // Radius of each cluster when clustering points (defaults to 50)
  clusterProperties: {
    status: ['max', ['get', 'status']]
  }
});

This snippet is exactly like the clusters example from mapbox page, just replacing the data by my static 2-elements copy, and adding clusterProperties.

However this throws a validation error (a bit mangled from the minified mapbox-gl version):

Error: sources.earthquakes: unknown property "clusterProperties"
    at Object.Jr [as emitValidationErrors] (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504146)
    at De (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504150)
    at i._validate (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504150)

What is wrong with this clusterProperties usage? It would seem it is simply refusing to validate this property. Note that the map works ok (without the status aggregated property of course) if I comment the last 3 lines that set it.

1

1 Answers

2
votes

I found the answer days later: The version of react-map-gl we were using had dependency on mapbox-gl ~0.52.0, which did not yet support clusterProperties. Support for these aggregated properties comes in mapbox-gl 0.53. (And since the react wrapper uses undocumented features of mapbox-gl, they depend on exact versions at patch level). This was confirmed by the react library developers.

Now react-map-gl 4.0.14 is released and it works ok with clusterProperties, using internally mapbox-gl 0.53.0.