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:
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:
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?
That can be done using Arcade.
To begin with, In the web map I DISABLED popups for the County and State layers.
I ENABLED the popups for the ZIP Codes layer.
I then added an attribute expression to specify the Arcade code to be run when I click on the map.
I named the Arcade expression "ZIP Code, County, State"
I wrote this code in the expression window
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
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
Once you have saved your changes, you should see this for the map popup when you click on the map.
You could also turn off other fields you don’t want to show and change th title to something meaningful
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
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