Select to view content in your preferred language

Create a single popup for multiple layers using Arcade

204
1
4 weeks ago
Labels (3)
MikeSweeney
Esri Contributor

I was recently asked how to use Arcade to generate a single popup for multiple layers, rather than having to page through multiple popups (one per layer).

Here is how I did that.

I began by creating a map with the ZIP Codes, Census Tracts and State boundaries:

MikeSweeney_23-1743521159911.png

By default, when I click on a location on the map, the Map Viewer will display a single popup window, with an arrow to page through all of the layers:

MikeSweeney_26-1743521259469.png

MikeSweeney_27-1743521268728.png

MikeSweeney_28-1743521282017.png

What if you want a single popup window displaying information from each of the layers, with no need to page through the layers popup windows as above.  Something like this?

MikeSweeney_29-1743521348783.png

That can be done using Arcade.

To begin with, In the web map I DISABLED popups for the County and State layers.

MikeSweeney_30-1743521443305.png

MikeSweeney_31-1743521449351.png

I ENABLED the popups for the ZIP Codes layer.

MikeSweeney_32-1743521455464.png

I then added an attribute expression to specify the Arcade code to be run when I click on the map.

MikeSweeney_33-1743521509088.png

I named the Arcade expression "ZIP Code, County, State"

MikeSweeney_34-1743521517026.png

I wrote this code in the expression window

MikeSweeney_35-1743521616808.png

This code does the following:

First, get the FeatureSet for the states, counties and zip codes layers

https://developers.arcgis.com/arcade/guide/types/#featureset

https://developers.arcgis.com/arcade/function-reference/featureset_functions/

 

var states = FeatureSetByName($map, "USA Census States", ["STATE_NAME"], false)

var counties = FeatureSetByName($map, "USA Census Counties", ["NAME"], false)

var zips = FeatureSetByName($map, "United States ZIP Code Boundaries", ["ZIP_CODE"], false)

 

Next, we want to use the location where you clicked on the map ( $userInput ) to find the intersecting state, county, and zip code

 

MikeSweeney_37-1743521714978.png

https://developers.arcgis.com/arcade/profiles/popup/

 

var state = Intersects(states, $userInput)

var county = Intersects(counties, $userInput)

var zip = Intersects(zips, $userInput)

 

Then, we want to pull the values for the fields we are looking for and assign them to variables.  So we get the first record (there should only be one) and extract the field value we want

https://developers.arcgis.com/arcade/function-reference/array_functions/#first

 

var stateName = first(state).STATE_NAME

var countyName = first(county).NAME

var zipName = first(zip).ZIP_CODE

 

Then finally we build an array [var, var, var] of the variables and pass it back to the attribute expression

 

Return [zipName, countyName, stateName]

 

In the ZIP Code layer popup we use the Fields List to add the attribute expression to the list of fields to be displayed

Click  Select Fields and add the ZIP Code, County, State attribute expression to the fields to be displayed

MikeSweeney_41-1743522135270.png

Once you have saved your changes, you should see this for the map popup when you click on the map.

MikeSweeney_42-1743522232216.png

You could also turn off other fields you don’t want to show and change th title to something meaningful

MikeSweeney_43-1743522261017.png

 

MikeSweeney_44-1743522276910.png

 

You can do additional formatting to control the look and feel of the popup.

 

If you want to play with the web map with this popup configured, you can find it here:

https://arcgis.com/apps/mapviewer/index.html?webmap=3d2f9e31e1d44ab8bf41b19465bb5507

In addition, I created an Instant App using the Basic viewer and you can check that out here:

https://arcgis.com/apps/instant/basic/index.html?appid=8719093f943242b2a885513a43def915

 

 

 

 

 

 

1 Reply
CodyPatterson
MVP Regular Contributor

Hey @MikeSweeney 

Great example! Thanks for sharing how it's done, this has been something that I've wanted to work with for quite a bit, but never got to it!

Cody

0 Kudos