HOW TO

Create custom labels for features in ArcGIS Online using Arcade

Last Published: December 12, 2023

Summary

Arcade expressions can be used to write label expressions in ArcGIS Online web maps. It is possible to customize web map labels on a feature by feature basis using a simple conditional expression. This can be useful to differentiate features, for example, to give clarity to an urgent feature. The conditional syntax for Arcade expressions consists of 'if', 'else if', and 'else'. The condition is placed within parentheses, and the result is placed between curly brackets.

This article provides the steps to create custom labels using Arcade expressions in ArcGIS Online Map Viewer Classic.

Procedure

For ArcGIS Online Map Viewer Classic

  1. Open the web map in ArcGIS Online Map Viewer Classic.
  2. Click More Optionsthe image of the More Options button, and select Create Labels, or if labels are available, Manage Labels.
  3. In the Label Features side panel, select New Expression under the Text drop-down box to open the Arcade Expression window.
The image of the Text drop-down box
  1. Use the following sample code to customize labels for specific features. In the following example, the script is set to only label features with OBJECTID 1 and 2.
if ($feature.OBJECTID == 1) {
return 'One'
} 

else if ($feature.OBJECTID == 2) {
return 'Two'
}

The image below demonstrates the resulting label.

Image of the resulting label

Alternatively, the script in Step 4 can also be modified to create custom labels to differentiate certain features. In the following example, only the feature with OBJECTID 1 is labeled with a text, and the remaining feature is labeled using the numeric OBJECTID value.

if ($feature.OBJECTID == 1) {
    return 'One'
}

else {
    return $feature.OBJECTID
}

The image below demonstrates the resulting label.

Image of the resulting label

For ArcGIS Online Map Viewer

  1. Open the web map in ArcGIS Online Map Viewer.
  2. In the Setting (light) toolbar, click Labels.
  3. Click Add label class.
  4. On the new label class, select the desired field under the Label field drop-down selection, and click Expression The expression button.
The Label features settings toolbar
  1. Use the following sample code to customize labels for specific features. In the following example, the script is set to only label features with OBJECTID 1 and 2.
if ($feature.OBJECTID == 1) {
    return 'One'
}

else {
    return $feature.OBJECTID
}
Alternatively, the script can also be modified to create custom labels to differentiate certain features. In the following example, only the feature with OBJECTID 1 is labeled with a text, and the remaining feature is labeled using the numeric OBJECTID value.
if ($feature.OBJECTID == 1) {
    return 'One'
}

else {
    return $feature.OBJECTID
}

Article ID:000017839

Software:
  • ArcGIS Online

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options