Search code examples
javascriptmapboxgeojsonmapbox-gl-js

Excluding certain features from clustering in MapBox GL JS


I have a data-source for which clustering is switched on:

map.addSource('MySource', { 'type': 'geojson', 'data': GeoJSON, 'buffer': 0, 'cluster': true, 'clusterRadius': 1 });

However, there are certain features that I do NOT want to be clustered under any circumstances. I appreciate that I could move those features into a different un-clustered data-source, but it would be far easier for me if I could keep everything in one data source and simply mark some features to be not-clustered.

I was thinking that I could add a property for each feature like cluster: false and I was wondering if, using such a property, it's possible to exclude some features from clustering...? Possibly using the clusterProperties?

Has anyone else managed to do this?


Solution

  • I don't believe it's possible to achieve what you want. A separate geojson source is the way to go.