[GIS] Labeling expressions on AGOL with Arcade for certain features

arcadearcgis-onlineexpressionlabeling

I am working on a web map in AGOL for the indoor office map. I have some issues writing custom expressions with Arcade in order to label the types of rooms (office rooms) based on another attribute name.

I have 2 attributes:

  1. attribute "Room_type", which has at least 10 different values, and
  2. attribute "Name", which has the labels I need for different types of rooms.

So what I want to do is to label only those room types that correspond to "Meeting" type, and labels should come from attribute "Name", because it contains the titles of each "Meeting" room type.

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

a) var room_type = $feature["Room_type"]

var meetlabel = $feature.Name

`If (room_type == 'Meeting') {
return meetlabel;
} else {
return 'None';
}`

b)
iif ($feature["Room_type"] == 'Meeting', $feature.Name, 'None')

c)

`If ($feature["Room_type"] == 'Meeting') {
return $feature.Name;
} else {
return 'None';
}`

d) When( $feature["Room_type"] == 'Meeting', $feature.Name, 'None')

e) Decode( $feature["Room_type"], 'Meeting', $feature.Name, 'None')

I've started thinking to just calculate a new field for each building floor that has the required labels in place with Field Calculator in ArcMap.
But hopefully it's possible to do with Arcade, as it would definitely shorten my workload!

Best Answer

The below codes, especially the version c) are actually correct and working. I've been having general Arcade expression window bugs which would not show me the results on the map or just wouldn't close or freeze.

For example, this has been working well:

If ($feature.NAME1 == 'Office_space') {
return "Department: " + $feature.NAME1
}
else if ($feature.NAME1 == 'Meeting') {
return "Meeting room: " + $feature.NAME1;
}
else {
return '';
}