I have 3 editable fields, each of which is related to a 4th, 5th and 6th field. The idea is that field 4,5,6 are the held quantities of fields 1,2,3. I want to base the layer style on the highest held quantity of whatever item.
Eg.
Feature 1: Style based on Grapes=60
Field 1: Oranges ------------ Field 4: 45
Field 2: Apples ------------- Field 5: 10
Field 3: Grapes ------------- Field 6: 60
Feature 2: Style based on Bananas = 80
Field 1: Apples ------------- Field 4: 15
Field 2: Bananas ------------- Field 5: 80
I've got the following code together which logically functions (finds and returns the appropriate pair of values), but I think I have an incorrect format being returned.
var fields = [
{ name: $feature.item1 , value: $feature.quantity1 },
{ name: $feature.item2 , value: $feature.quantity2 },
{ name: $feature.item3 , value: $feature.quantity3 },
];
function comparevalue(a,b){
if (a['value']>b['value'])
return -1;
if (a['value']<b['value'])
return 1;
return 0;
};
return First(Sort(fields,comparevalue))
The above code returns:
dictionary
name: Grapes
value: 60
but this is not usable to set a style apparrently.
Solved! Go to Solution.
I got what I wanted working like this:
var fields = [
{ alias: $feature.variety1 , value: $feature.var1_perc },
{ alias: $feature.variety2 , value: $feature.var2_perc },
{ alias: $feature.variety3 , value: $feature.var3_perc },
];
function getPredominantCategory(fields){
var maxValue = null;
var maxCategory = "";
for(var k in fields){
if(fields[k].value > maxValue){
maxValue = fields[k].value;
maxCategory = fields[k].alias;
} else if (fields[k].value == maxValue){
maxCategory = maxCategory + "/" + fields[k].alias;
}
}
return IIF(maxValue <= 0, null, maxCategory);
}
getPredominantCategory(fields);
The Arcade visualization profile, used for styling your data based on an Arcade expression, only accepts a return type of Number or Text. Dictionaries are not a supported return type in this profile.
You could create two separate expressions -- the first which finds the field name, and the second which gets the quantity/value of that field. Basically, you could use the same expression twice but specify either the name or value in the return.
First(Sort(fields,comparevalue)).name // or value depending on expression
Then use that with the "Types and Size" style.
Thanks for your response! Sorry for my slow reply. I'm going to check out your solution as well.
I got what I wanted working like this:
var fields = [
{ alias: $feature.variety1 , value: $feature.var1_perc },
{ alias: $feature.variety2 , value: $feature.var2_perc },
{ alias: $feature.variety3 , value: $feature.var3_perc },
];
function getPredominantCategory(fields){
var maxValue = null;
var maxCategory = "";
for(var k in fields){
if(fields[k].value > maxValue){
maxValue = fields[k].value;
maxCategory = fields[k].alias;
} else if (fields[k].value == maxValue){
maxCategory = maxCategory + "/" + fields[k].alias;
}
}
return IIF(maxValue <= 0, null, maxCategory);
}
getPredominantCategory(fields);