Unique label colors using Arcade Expression?

1357
1
05-15-2020 08:40 PM
JeanetteHarlow1
New Contributor III

Is there a method to write an Arcade expression to allow unique label colors based on different attribute values?  This would help to keep from splitting a feature layer into multiple feature layers to have the desired effect, only to have competing labeling rankings between the layers which end up overlapping.  I have seen this question posed previously with no positive answers.

Generate different label styles/colors based on different attribute value in ArcGIS Online. 

Custom arcade expression to change the colours of text labels on an ArcGIS Online web map? - Geograp... 

1 Reply
AlderMaps
Occasional Contributor

Since this question is the top google result for my search for the same thing, I thought I'd post what I came up with after a bit of synthesizing various bits and pieces I found across the web. I'm still sort of fumbling around with Arcade so there may be a better way to do it...but this is working for me in Pro 3.1 (have not tested in AGOL but assuming it should work there too...)

The following successfully applies my symbology color scheme (green-yellow-orange-scarlet-red, grey for no data) to labels for the Esri Living Atlas AirNow point feature service (https://services.arcgis.com/cJ9YHowT8TU7DUyn/arcgis/rest/services/Air%20Now%20Current%20Monitor%20Da...)

 

var aqi = $feature.OZONEPM_AQI_LABEL

if(aqi <= 50){
    return "<CLR red='50' green='200' blue='100' >" + aqi + "</CLR>";
}
else if(aqi <= 100){
    return "<CLR red='175' green='255' blue='0' >" + aqi + "</CLR>";
}
else if(aqi <= 150){
    return "<CLR red='255' green='255' blue='50' >" + aqi + "</CLR>";
}
else if(aqi <= 200){
    return "<CLR red='255' green='150' blue='0' >" + aqi + "</CLR>";
}
else if(aqi <= 300){
    return "<CLR red='255' green='75' blue='0' >" + aqi + "</CLR>";
}
else if(aqi <= 500){
    return "<CLR red='255' green='0' blue='75' >" + aqi + "</CLR>";
}
else {
    return "<CLR red='150' green='150' blue='150' >" + aqi + "</CLR>";
}

 

Color-coded labels w/Arcade ExpressionColor-coded labels w/Arcade Expression

Update: Welp. It doesn't work in AGOL (new Map Viewer). For the time being I'm going to create label classes there and come back to this battle another day.