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
Solved! Go to Solution.
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.
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.
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.
@Trippetoe Are you trying to actually write those values to a table or just manually copy the coordinates?
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
@Trippetoe Maybe you have seen this discussion? https://www.reddit.com/r/gis/comments/ut5nqg/using_arcgis_arcade_to_get_xy_coords_of_point/?rdt=5378...
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?
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
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/
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.
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.
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 This is fabulous. Thank you for the example code!