-
I have a data set that I coerce into geojson format, like so: function toGeoJson(locations) {
const features = [];
locations?.forEach(location => {
features.push({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [location.geolocation.lon, location.geolocation.lat],
},
properties: {
_id: location._id, // add this property
}
})
});
return {
type: 'FeatureCollection',
features,
}
} The important part is that each feature has a custom I then create a cluster-enabled map with two layers - one symbol-type with a cluster configuration (i.e. <Map
...
onClick={onClick}
interactiveLayerIds={['points', 'clusters']}
>
<Source id="my-data" type="geojson" data={mapLocations} cluster={true} clusterRadius={50}>
<Layer {...pointLayerStyle} />
<Layer {...clusterLayerStyle} />
</Source>
</Map> Setting Is there a way to access the properties of the child points in a cluster on click, i.e. if I click a cluster am I able to access an array of all the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've answered my own question - in the if (mapRef.current) {
const map = mapRef.current.getMap();
const selectedFeatures = e.features[0];
const src = map.getSource('my-data');
src.getClusterLeaves(selectedFeatures.properties.cluster_id, selectedFeatures.properties.cluster_id, 0, (err, features) => {
if (err) console.log(err);
console.log('features from cluster', features);
});
} |
Beta Was this translation helpful? Give feedback.
I've answered my own question - in the
onClick
handler you can get a reference to the map, retrieve the source data and query usinggetClusterLeaves()
: