When you use clustering it will only show one pin. If you want to show a different pin for a cluster based on what's inside of it, you will want to use a cluster aggregate to aggregate some metric that can be used in a data driven style. https://learn.microsoft.com/en-us/azure/azure-maps/clustering-point-data-web-sdk#aggregating-data-in-clusters For example, the following is a modified version of the sample in the docs that uses a symbol layer and uses a red marker if there is one or more restaurants in a cluster, and a blue marker otherwise.
var map, datasource;
//GeoJSON feed that contains the data we want to map.
var geojsonFeed = 'https://azuremapscodesamples.azurewebsites.net/Common//data/geojson/SamplePoiDataSet.json';
//Colors for each EntityType property in point data: [Gas Station, Grocery Store, Restaurant, School]
var entityTypes = ['Gas Station', 'Grocery Store', 'Restaurant', 'School'];
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
center: [-97, 39],
zoom: 3,
view: 'Auto',
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: 'szw7L2B0SNkxRapuYhVLZUimqMUHfraJD-joQ65gd4M'
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource(null, {
cluster: true,
//The radius in pixels to cluster points together.
clusterRadius: 50,
//Calculate counts for each entity type in a cluster as custom aggregate properties.
clusterProperties: {
'Gas Station': ['+', ['case', ['==', ['get', 'EntityType'], 'Gas Station'], 1, 0]],
'Grocery Store': ['+', ['case', ['==', ['get', 'EntityType'], 'Grocery Store'], 1, 0]],
'Restaurant': ['+', ['case', ['==', ['get', 'EntityType'], 'Restaurant'], 1, 0]],
'School': ['+', ['case', ['==', ['get', 'EntityType'], 'School'], 1, 0]]
}
});
map.sources.add(datasource);
map.layers.add([
//Create a symbol layer to render the count of locations in a cluster.
new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
image: [
'case',
['>', ['get', 'Restaurant'], 0],
'marker-red',
'marker-blue'
]
},
textOptions: {
textField: ['get', 'point_count_abbreviated'],
offset: [0, -1],
color: 'white'
}
}),
//Create a layer to render the individual locations.
new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
image: 'pin-blue'
},
filter: ['!', ['has', 'point_count']] //Filter out clustered points from this layer.
})
]);
//Import the GeoJSON data into the data source.
datasource.importDataFromUrl(geojsonFeed);
});
}