Select to view content in your preferred language

Can arcade return the coordinates of a map click?

1968
8
Jump to solution
08-31-2023 05:42 PM
Labels (1)
Trippetoe
Frequent Contributor

Hello.

My webmap has two polygon layers - a city boundaries layer on top and an annexation layer underneath.  I'm trying to show the specific annexations at a given map click location when just the City layer is visible on the map. And i want to display the annexations in the city boundaries layer popup.

i need the x,y coordinates of the map click in order to intersect with the Annexations layer. Is it possible to use Arcade to get the mouse click coordinates?

I can certainly use the maps default behavior to show the multiple popups of the city boundary layer and the annexation layer. Ideally, though, i'd like to have a single popup on the City layer to show the annexation information.

Thank you

 

0 Kudos
1 Solution

Accepted Solutions
MikeSweeney
Esri Contributor

Hey, I thought I would follow up with an example of how $userInput would be used.  I have 3 polygon layers I want to show in a single popup instead of paging through 3 popup layers.

MikeSweeney_0-1743520560930.png

I disable to popups for layer 1 & 2. 

On layer 3, I then add an Arcade expression to get the featureset for each of the 3 polygon layers and then use the $userInput location to do an intersect to find the polygons where my mouse click fell into.

MikeSweeney_1-1743520638382.png

MikeSweeney_2-1743520647307.png

 

 

I set some variables and then return an array with an attribute from each layer.  Check it out.

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)

 

var state = Intersects(states, $userInput)

var county = Intersects(counties, $userInput)

var zip = Intersects(zips, $userInput)

 

var stateName = first(state).STATE_NAME

var countyName = first(county).NAME

var zipName = first(zip).ZIP_CODE

 

Return [zipName, countyName, stateName]

 

In the popup setting for the ZIP Code layer, I just show the ZIP Code, County, State Arcade expression.

 

MikeSweeney_4-1743520909962.png

 

 

MikeSweeney_3-1743520769386.png

 

View solution in original post

8 Replies
ArmstKP
Frequent Contributor

@Trippetoe Are you trying to actually write those values to a table or just manually copy the coordinates?

 

0 Kudos
Trippetoe
Frequent Contributor

I want to use the coordinates to create a point/geometry that i can then use to run an intersection against the Annexation layer. That will enable me to identify any annexations that encompassed that point (maybe thats the wrong word - maybe its 'included' that point). Anyway, looking for annexations that intersected the place where the use clicked the map. Again, i know that the native multiple popups sorta solves the problem for me, but i'd like to present the data for any intersecting annexations in a single popup.

Thank you 

0 Kudos
ArmstKP
Frequent Contributor
0 Kudos
Trippetoe
Frequent Contributor

Thanks for your fast reply. Yes, i had seen that link. I was hopeful/wishing that with the updates to Arcade over the past year or so that the functionality had been added in, or some intrepid developer had stumbled on a workaround to get the info. 

As an aside, i didn't understand the suggestion made by DragoonHimself to use a point note feature layer. Do you know that was getting at?

0 Kudos
KevinMayall
Frequent Contributor

This probably doesn't get what you want, but this type of functionality is in the Near Me widget in Experience Builder.

https://doc.arcgis.com/en/experience-builder/latest/configure-widgets/near-me-widget.htm

Kevin
0 Kudos
MikeSweeney
Esri Contributor

I was just looking and a new variable has been added named $userinput.  It gives you the point where someone clicked for a popup.  Note, that is can also be a box or null, so you need to test for the geometry of $userinput.

 

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

 

MikeSweeney_0-1743447219145.png

 

MikeSweeney
Esri Contributor

Hey, I thought I would follow up with an example of how $userInput would be used.  I have 3 polygon layers I want to show in a single popup instead of paging through 3 popup layers.

MikeSweeney_0-1743520560930.png

I disable to popups for layer 1 & 2. 

On layer 3, I then add an Arcade expression to get the featureset for each of the 3 polygon layers and then use the $userInput location to do an intersect to find the polygons where my mouse click fell into.

MikeSweeney_1-1743520638382.png

MikeSweeney_2-1743520647307.png

 

 

I set some variables and then return an array with an attribute from each layer.  Check it out.

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)

 

var state = Intersects(states, $userInput)

var county = Intersects(counties, $userInput)

var zip = Intersects(zips, $userInput)

 

var stateName = first(state).STATE_NAME

var countyName = first(county).NAME

var zipName = first(zip).ZIP_CODE

 

Return [zipName, countyName, stateName]

 

In the popup setting for the ZIP Code layer, I just show the ZIP Code, County, State Arcade expression.

 

MikeSweeney_4-1743520909962.png

 

 

MikeSweeney_3-1743520769386.png

 

Trippetoe
Frequent Contributor

@MikeSweeney This is fabulous. Thank you for the example code!

0 Kudos