I am using Clustering Featured Reduction (ArcGIS Maps SDK 4.30) on a Feature Layer with UniqueValueRender for symbols for a category. By default, the API will symbolize the cluster based on the "predominant category". Where predominant seems to refer to the most frequent category in the cluster.
I want to use the symbol for the category with the highest value of a particular field in the cluster. As an example, my data contains a category called animals, and a particular cluster has 3 cats and a dog, the API assigns the cluster the symbol of a cat. In my data, I have an additional field, the price for each animal, and the dog has the highest cost of all animals, I would like to assign the cluster the symbol of a dog.
What I have tried:
Using UniqueValueRender value expression Arcade. From here I am able to access the cluster feature, summary stats (computed in the cluster configuration), but the attributes here do not contain the aggregated features. So I am not able to find out which of the cluster elements contain the highest value.
//Expects($Feature, '*')
{
"attributes": {
"aggregateId": "266.187",
"cluster_count": 12,
"max_price": 100.0001,
"avg_price": 23.674746264166668,
"count_animals": 12,
"unique_id": "db4120ae-b6be-4cc2-b20e-0a10c388d829",
"category": "Dog"
},
"geometry": {
"x": 108,
"y": 178
},
"centroid": {
"x": 108,
"y": 178
}
}
I have also tried creating a new category field from the aggregated features. The Arcade below will work fine to present this information in a pop up, so I would be able to find out the category with the highest value from $aggregatedFeatures
{
label: 'Predominant category',
type:'expression',
expressionInfo: {
expression: `
Expects($aggregatedFeatures, '*');
var statsFs = GroupBy($aggregatedFeatures,
[
{ name: 'Type', expression: 'category'}
],
[
{ name: 'MaxPrice', expression: 'price', statistic: 'MAX' }
]
);
var ordered = Top(OrderBy(statsFs, 'MaxPrice DESC'), 5);
// create an HTML ordered list as a string and return in a rich text element
var list = "<p>Top animals (Price)</p><ol>";
for (var cat in ordered){
list += \`<li>\${cat.Type} (\${Text(cat.MaxPrice)}) </li>\`
}
list += "</ol>";
return {
type: "text",
text: list
}
`
}
}
However trying the same approach in the fields definition does not work, as $aggregatedFeatures does not seem to exist.
{
name: 'pred_cat',
onStatisticExpression: {
title: 'category',
returnType: 'string',
expression: `
//Works fine, but I have only access to a single feature not all cluster features
Expects($feature, '*')
//Error
Expects($aggregatedFeatures, '*')
return "Dog"
`
}
,statisticType: 'mode'
}
How can I achieve this? Thank you.