HOW TO

Rearrange text strings of labels using Arcade in ArcGIS Online and Portal for ArcGIS Map Viewer

Last Published: March 24, 2023

Summary

In ArcGIS Online and Portal for ArcGIS Map Viewer, Arcade expressions with multiple statements can be used to split and reposition text strings of labels. The repositioned text strings can be used for data management. This article provides an example and instructions using Arcade expressions to split and rearrange text strings of labels for Map Viewer.

The image below shows a map in Map Viewer with labels.

The map with labels in ArcGIS Online Map Viewer

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar and select the layer with the pop-up for editing.
  2. On the Settings (light) toolbar, click More > Labels.
  3. Click Use expression The Use expression icon to open the Arcade expression editor window.
  4. In the editor window, specify a name for the new expression.
  5. In the Expression dialog box, insert the appropriate Arcade expression, as described below.
    1. Define the variable with the function to split the text string and the blank space as a separator.
var <variableName1> = Split($feature.<featureName>, ' ')
  1. Define the variable with the function to count the number of splits for each record.
var <variableName2> = Count(<variableName1>)
  1. Specify the following statement to return a blank value when the field value is empty.
if (<variableName2> == 0) {
return ''
}
  1. Specify the following statement to return the same text value when the field is a single word.
if (<variableName2> == 1) {
return $feature.<featureName>
}
  1. Specify the following statement to rearrange the position of the second word to the first position when the field has two words.
if (<variableName2> == 2) {
return <variableName1>[1] + ' ' + <variableName1>[0]
}
  1. Specify the following statement to rearrange the position of the first word to the third position when the field has three words.
if (<variableName2> == 3) {
return <variableName1>[1] + ' ' + <variableName1>[2] + ' ' + <variableName1>[0]
}

The code block below shows the full working expression.

var arrName = Split($feature.Forest_Name, ' ')
var lenName = Count(arrName)
if (lenName == 0) {
return ''
}
if (lenName == 1) {
return $feature.Forest_Name
}
if (lenName == 2) {
return arrName[1] + ' ' + arrName[0]
}
if (lenName == 3) {
return arrName[1] + ' ' + arrName[2] + ' ' + arrName[0]
}
  1. Click Run for a preview of the expression result. If the required result is achieved, click Done.
Specifying the Arcade expression in the ArcGIS Online Map Viewer editor window

The image below shows the newly configured labels after using the Arcade expression.

The map in ArcGIS Online Map Viewer with the newly configured labels

Article ID: 000029552

Software:
  • ArcGIS Online
  • Portal for ArcGIS

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