Arcade Basics: Part 2

Hunter Ray, GISP

Technical Services Manager

This blog explores a few of the various ways to use Arcade expressions in ArcGIS Online's web map viewer. Arcade expressions are a powerful tool for creating dynamic and interactive map elements. By looking at different use case scenarios within a web map and the different Arcade variables and functions needed, you will gain a better understanding of how to apply Arcade across the Esri platform.

Background on Arcade

Arcade is a scripting language designed for use in ArcGIS. It allows you to create expressions that can be used to calculate values, control the visibility of features, and customize pop-up content. Arcade expressions are especially useful when you want to perform calculations or apply logic based on feature attributes, without the need for external data processing.

For more on the basics of Esri’s Arcade expression language, you can find the documentation here and also watch Part 1 of this two-part series here.

Scenario 1: Calculating Asset IDs

A common task for asset data management is keeping asset IDs unique and calculating them automatically as new assets are added. With hosted feature layers in ArcGIS Online, this can now be done with an Arcade expression in a layers edit form within a web map. To achieve this, the Arcade expression needs to do four basic steps in order:

  1. create a FeatureSet of the current layer with only the field holding asset ID values

  2. Sort the FeatureSet by asset ID in descending order to get the highest number as the first row

  3. Access the specific asset ID value in the first row of the FeatureSet

  4. Add one to the highest existing asset ID and return as the expression output

Once the expression has been constructed and tested, it can be applied and will generate a new sequential asset ID in real time as features are collected.

Scenario 2: Calculating Latitude and Longitude

Calculating latitude and longitude is particularly useful when you want to automatically populate these values in fields within the feature layer whenever a feature is added or edited. This expression is a little more complicated and can be performed using a custom function to output a set of values based on a feature’s geometry properties. When constructing this expression in an ArcGIS Online web map, the expression will need to access the geometry of a feature, then convert meters into latitude and longitude and return those values. To learn more about converting data between coordinate systems using a function and to get a starting point for the function in Arcade, visit MapTiler.

Scenario 3: Summarizing Data in Pop-ups

Another common use case is to summarize data from other layers within a web map popup. To achieve this, the Arcade expression will need to follow these steps:

  1. Create a FeatureSet of the desired layer in the map with a single field (i.e. GlobalID)

  2. Create a FeatureSet of features that intersect the current feature

  3. Return a count of the number of features in the intersection FeatureSet

Scenario 4: Custom HTML in a Popup

Take pop-up customization to the next level by creating custom HTML outputs by using expressions in the relatively new Arcade element for web map popups. Expressions in the Arcade element can be used to produce HTML elements such as a dynamic hyperlink using attributes from a feature. These expressions can also be used to create HTML tables summarizing data for layers in a web map and even from external sources.

To see the construction of the expressions noted above and more please view the Playing the Game: Applying Arcade to ArcGIS Online webinar.

Conclusion

Arcade expressions in ArcGIS Online's web map viewer open up a world of possibilities for creating dynamic and interactive maps. From calculating values to customizing pop-ups and creating dynamic hyperlinks, Arcade empowers you to make your maps more informative and engaging. By mastering these techniques, users can take full advantage of the power of Arcade and create maps that deliver valuable insights. If you’re interested in Cloudpoint’s help putting Arcade to use in your GIS, contact us at 877.377.8124 or fill out an inquiry on our contact page.