Select to view content in your preferred language

arcade script for popup

541
3
Jump to solution
04-04-2023 02:47 AM
Labels (1)
IngridAnneessens
New Contributor II

Hi! I would like a Arcade script for a popup that  shows me all the features within a buffer from one layer with their distances to the selected feature in an other layer.

for example: I selected an adress. The popup has to show all the schools by name within a distance of 10km, followed by their distance to the selected adress.

Can anyone help me?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

This is certainly possible. Including spatial operations in a popup expression can cause your expression to take a bit longer to evaluate, but it's not too hard to put together.

 

// create the 10km buffer
var buff = Buffer($feature, 10, 'kilometers')

// get intersecting schools
var xs_schools = Intersects(buff, FeatureSetByName($map, 'school_layer_name'))

// loop through the returned schools and populate an array
var school_list = []

for (var s in xs_schools) {
    // get distance
    var dist = Distance(s, $feature, 'kilometers')

    // push a formatted string to the school_list array
    Push(school_list, `${s['school_name_field']}: ${Text(dist, '#,###.0')} km away`)

// return a newline-delimited string from your array
return Concatenate(school_list, '\n')

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

This is certainly possible. Including spatial operations in a popup expression can cause your expression to take a bit longer to evaluate, but it's not too hard to put together.

 

// create the 10km buffer
var buff = Buffer($feature, 10, 'kilometers')

// get intersecting schools
var xs_schools = Intersects(buff, FeatureSetByName($map, 'school_layer_name'))

// loop through the returned schools and populate an array
var school_list = []

for (var s in xs_schools) {
    // get distance
    var dist = Distance(s, $feature, 'kilometers')

    // push a formatted string to the school_list array
    Push(school_list, `${s['school_name_field']}: ${Text(dist, '#,###.0')} km away`)

// return a newline-delimited string from your array
return Concatenate(school_list, '\n')

 

- Josh Carlson
Kendall County GIS
0 Kudos
IngridAnneessens
New Contributor II

It Works! Thx

0 Kudos
IngridAnneessens
New Contributor II

Hi! I would like a Arcade script for a popup that  shows me all the features within a buffer from one layer with their distances to the selected feature in an other layer.

for example: I selected an adress. The popup has to show all the schools by name within a distance of 10km, followed by their distance to the selected adress.

Can anyone help me?

0 Kudos