How to format Arcade expression in AGOL to show labels for only select features in a layer?

2780
5
Jump to solution
11-21-2018 10:53 AM
ChelseyKnuth
New Contributor

I am working on a web map in AGOL showcasing an interior floor plan for a building. Only one of the building's floors is currently added to the map, but others will be added as they become available.

Features in the floor plan polygon layer have been symbolized by their unique values in the "Category" field (office, conference room, bathroom, corridor, etc.) There are seventeen different 'categories' in all, and three of them are column, partition, and wall. While I want these three features to be displayed/symbolized along with the others in the map, I do not want them to be labeled.

What should my Arcade expression look like in the Custom Expression window of 'Manage Labels' if I want features in the Floor_Plans layer to be labeled by Category EXCEPT if that category is "Column" or "Partition" or "Wall" ?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
StephenM
Occasional Contributor II

Something like this might be what you're looking for:

Decode($feature["Category"],"Column","","Partition","","Wall","",$feature["Category"])

Some references:

Logical Functions | ArcGIS for Developers

Multiple IIF() Statements in Arcade Expression

View solution in original post

5 Replies
StephenM
Occasional Contributor II

Something like this might be what you're looking for:

Decode($feature["Category"],"Column","","Partition","","Wall","",$feature["Category"])

Some references:

Logical Functions | ArcGIS for Developers

Multiple IIF() Statements in Arcade Expression

Aurelija_RutaViluckyte
New Contributor III

Hello there, 

I have been working on a very similar project, also related to the indoor floor plans. I also have an attribute, called "Room_type" with many different room types, and an attribute "Name", which contains the labels for each room type. I am also creating a map on ArcGIS Online and want to learn to use Arcade, but haven't found anything similar yet. So what I want to do is to label only those room types that correspond to "Meeting" type, and labels shoul come from attribute "Name". 

I've been trying something like this, but it only returns Null values for me:

var room_type = $feature["Room_type"]
var meetlabel = When(room_type == "Meeting", $feature.Name, 'none')
return $feature.Name

So far I started thinking just to calculate a new field for each floor of the building that has the required labels in place with Field Calculator in Arcmap. But hopefully it's possible to do with Arcade!

Thanks in advance for any tip!

Regards, 

Aurelija

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Aurelija Ruta Viluckyte ,

In your expression, you just return the attribute Name. The first two lines do not influence the result. You should be returning the variable meetlabel in your expression.

Could you try to do this?

if ($feature.Room_type == "Meeting") {
    $feature.Name;
} else {
    return "";
}

This will only work if the exact content of the Room_type field is "Meeting". If you have additional information in the field or something simple as an additional space at the end, the expression will return an empty string.

Aurelija_RutaViluckyte
New Contributor III

Hello there. I posted a new question regarding this (the code in my comment isnt correct, my apologies) on GIS Stack Exchange and I already answered it too. You can view it here: arcgis online - Labeling expressions on AGOL with Arcade for certain features - Geographic Informati... 

All of my Arcade expressions work on ArcGIS Pro, however, none of them work on ArcGIS Online. I think it is the issue with ESRI, because the Arcade expression dialog box just doesn't respond, once I click "OK" , or "Close", or "Cancel". It just freezes. And once I refresh the web map window, no changes apply. I try opening again, write an expression, and when click these buttons again, it freezes again. It is sad I cannot use Arcade on AGOL, such an inconvenience. 

0 Kudos
LorinCrandall1
New Contributor III

This worked great for me, thanks for posting.