HOW TO

Configure a popup using Arcade to group and count features based on a spatial relate to other features

Last Published: December 31, 2021

Summary

When configuring pop-ups for feature layers, the content and how the content is displayed can be customized. Pop-up elements support related data, hyperlinks, ArcGIS Arcade expressions, and HTML mode.

Arcade can perform mathematical calculations, manipulate text, and evaluate logical statements. It also supports multi-statement expressions, variables, and flow control statements. Arcade was designed specifically for creating custom visualizations and labeling expressions in the ArcGIS Platform.

It is intended for evaluating embedded expressions such as those used in the visualization, labeling, popup, and alias contexts of applications built with the ArcGIS platform. It can only be executed within the context of a designated profiles, such as labeling, visualization, popups, calculation, and constraints. Each profile defines the parameters that are available to the script as global variables, and the output expected from the script.

Procedure

The steps to view a 'grouped by count' of features that are spatially related to the identified feature in the map are as follows.

  1. In ArcGIS Pro, add the two spatially related layers to a map.
29-09-2021 3-10-26 PM.jpg
  1. In the Contents pane, right-click the layer for the popup to configure, and click Configure Pop-ups.
29-09-2021 3-13-33 PM.jpg
  1. Click Expressions to create a new Arcade expression.
29-09-2021 3-15-37 PM.jpg
  1. Give the expression a title and set the expression. Below is an example of using the Intersect and GroupBy functions to count all the features that intersect the polygon feature identified and then group the features by an attribute field:
// Reference the sample points feature layer
var samples = FeatureSetByName($map,"samples")

// Count the number of samples within each polygon
var sampleCount = Intersects(samples, $feature)

// Group samples by their date and count
var stats = GroupBy(sampleCount, "Year", [
{name: "NumSamples", expression: "1", statistic: "COUNT"}
])

// Order the results in descending order by the total counts
var topSamples = OrderBy(Filter(stats, "Year <> ''"), "Year desc")

// Popup placeholder
var result = 'Number of samples per year:'

// Write the results to the popup
if(Count(topSamples) == 0){
return "No samples in this area"
}

var num = 0

// Format the results for display in popup
for(var item in topSamples){
num++
var num_samples = item["NumSamples"]
var sample_year = item["Year"]
result += TextFormatting.NewLine + num + ". " + sample_year + ": " + num_samples
}
return result
29-09-2021 5-15-36 PM.jpg

Identifying polygon features displays a popup with the summarized results

29-09-2021 5-18-16 PM.jpg

Article ID: 000026504

Software:
  • ArcGIS Pro

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