I'm currently looking at/researching how to edit attribute expressions and even change the color of text in the expressions. My problem is, I do not know how to go about it or which language to use that would be best.
Any links to articles/discussion/resources or even solutions are welcome!
The scripting language is called Arcade (ArcGIS Arcade | ArcGIS for Developers ) which is similar to JavaScript (not Python). Use a script to create new results based on multiple attributes. When using Arcade in the pop-up windows, you can get some fancy results. See also this thread: https://community.esri.com/thread/197406-insert-html-with-arcade
Do you know of any examples where people have tried to change the color of the expressions?
Hi Vishal,
Here is the documentation that I think you are looking for. It is at the very bottom talking about using If Then statements to drive font color and it gives you the arcade statement.
Specify text for labels—ArcGIS Pro | ArcGIS Desktop
Thank you Greg! This is my first time working with Arcade and Attribute Expressions in AGOL!
To show an example of what can be done, your html code for a pop-up could be like this:
<font color="{expression/expr0}"><b>{GRAVEDAD}</b></font>
In this case my field is called "GRAVEDAD" with three possible values: SOLO DAÑOS (only material damage), HERIDOS (injuries), MUERTO (diseased). If you would like to vary the color of the text, you can use an Arcade expression inside the color tag (switch to HTML view to reveal the html code).
The expression in my case would be:
// #800080 purple
// #ff0000 red
// #ff8c00 orange
var dct_grav = {"SOLO DAÑOS": "#ff8c00", "HERIDO": "#ff0000", "MUERTO": "#800080"};
var gravedad = $feature.GRAVEDAD;
var color = dct_grav[gravedad];
Console(color);
return color
This will return the color code (purple, red or orange) depending the field value GRAVEDAD, resulting in:
Thank you Xander! This is my first time working with Arcade and Attribute Expressions in AGOL!
// #FAAF41 Primary Color
var primaryColor = "#FAAF41";
var networkID = $feature.NetworkID;
var color = primaryColor[networkID];
Console(color);
return color
<font color="{expression/expr0}"><b>{networkID}</b></font>
Xander,
In line 10, I get an Unexpected identifier error. Do you know why that is?
Yes, line 10 should not be part of the Arcade expression. It is the html code that should be used in the pop-up configuration.
In the pop-up configuration, select "A custom attribute display" and hit CONFIGURE:
Then switch to HTML with the "View HTML source" button:
and past the HTML here
Yea removing line 10 took out the error for unexpected identifier, however with this code now for Attribute Expressions, i get the execution error: runtime error: cannot call member property on object of this type. I'm fairly new to Arcade and such and do not understand these errors. Any assistance on this bit then?
// #FAAF41 Primary Color
var primaryColor = "#FAAF41";
var networkID = $feature.NetworkID;
var color = primaryColor[networkID];
Console(color);
return color