Attribute Expressions in AGOL

5044
13
09-18-2017 12:43 PM
VishalShah2
Occasional Contributor II

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! 

0 Kudos
13 Replies
XanderBakker
Esri Esteemed Contributor

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 

VishalShah2
Occasional Contributor II

Do you know of any examples where people have tried to change the color of the expressions?

0 Kudos
Greg_Mattis
Occasional Contributor II

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 

Greg Mattis, GISP
GIS Analyst
City of Visalia
VishalShah2
Occasional Contributor II

Thank you Greg! This is my first time working with Arcade and Attribute Expressions in AGOL!

0 Kudos
XanderBakker
Esri Esteemed Contributor

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:

VishalShah2
Occasional Contributor II

Thank you Xander! This is my first time working with Arcade and Attribute Expressions in AGOL!

0 Kudos
VishalShah2
Occasional Contributor II
// #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?

0 Kudos
XanderBakker
Esri Esteemed Contributor

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

VishalShah2
Occasional Contributor II

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
0 Kudos