Using Arcade in Popup to display fields from 2 different layers

2078
8
Jump to solution
02-08-2022 07:52 AM
Labels (1)
RandyMcGraw1
New Contributor II

I'm trying to use Arcade to display table information in a Popup from 2 different layers in the same map.

Both layers are point features, same geospatial locations but different attribute data.

The main layer (which generates the Popup) uses a standard field list to display attributes and it works. I created an Arcade expression (using the fields template) to bring in the attributes from the secondary layer (using the Intersect arcade expression to select features from the secondary layer).

However, even though I get a second fields list the attributes are populated with:

RandyMcGraw1_1-1644335139766.png

Arcade Expression:

// Facilities - Construction Year
var fac = FeatureSetByName($map,"Facilities",['Construction_Year'])

//Get Intersecting features
var intfac = Intersects($feature, fac)

// Facilities - Structure_Number
var str = FeatureSetByName($map,"Facilities",['Structure_Number'])

//Get Intersecting features
var intstr = Intersects($feature, str)

// Facilities - Floar area
var flo = FeatureSetByName($map,"Facilities",['Floor_Area'])

//Get Intersecting features
var intflo = Intersects($feature, flo)

return {
type: 'fields',
//title: '',
//description : '',
fieldInfos: [{
fieldName: "Construction"
},
{
fieldName: "Structure"
},
{
fieldName: "Floor"
}],
attributes : {Construction : intfac, Structure : intstr, Floor : intflo}
}

Thank you for any help you can provide

Randy

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Have you tested the popup on multiple features? If there are no intersecting features, it's going to run into null values and not return anything.

We can try adding some null handling to the expression itself, too.

 

var fac_fields = [
    'Construction_Year',
    'Structure_Number',
    'Floor_Area'
]

var fac = FeatureSetByName($map, "Facilities", fac_fields, true)

var intfac = First(Intersects($feature, fac))

If(IsEmpty(intfac)){
    return 'No intersecting feature'
} Else {
    return `Construction: ${intfac['Construction_Year']}
    Structure: ${intfac['Structure_Number']}
    Floor: ${intfac['Floor_Area']}`
}

 

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
8 Replies
jcarlson
MVP Esteemed Contributor

When you use Intersect, the returned object is still a FeatureSet. You need to access a single Feature object in order to pull out its attributes. The simplest method is to use First, and as long as your points will not intersect with multiple features, you can use this expression:

 

var fac_fields = [
    'Construction_Year',
    'Structure_Number',
    'Floor_Area'
]

var fac = FeatureSetByName($map, "Facilities", fac_fields, true)

var intfac = First(Intersects($feature, fac))

return `Construction: ${intfac['Construction_Year']}
Structure: ${intfac['Structure_Number']}
Floor: ${intfac['Floor_Area']}`

 

 

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

Hello Josh,

Your expressions works for me in the expression builder:

RandyMcGraw1_0-1644352731616.png

But it is not showing up in the actual Popup. Any ideas of how to fix this?

Your help is greatly appreciated.

Randy

0 Kudos
jcarlson
MVP Esteemed Contributor

Have you tested the popup on multiple features? If there are no intersecting features, it's going to run into null values and not return anything.

We can try adding some null handling to the expression itself, too.

 

var fac_fields = [
    'Construction_Year',
    'Structure_Number',
    'Floor_Area'
]

var fac = FeatureSetByName($map, "Facilities", fac_fields, true)

var intfac = First(Intersects($feature, fac))

If(IsEmpty(intfac)){
    return 'No intersecting feature'
} Else {
    return `Construction: ${intfac['Construction_Year']}
    Structure: ${intfac['Structure_Number']}
    Floor: ${intfac['Floor_Area']}`
}

 

 

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

Hello Josh,

First of all, thanks for taking the time to help.

Unfortunately the "If" statements has not fixed the situation. 

Is it normal that your when I use your expression I get a " Execution Error:Cannot assign undeclared variable"?

RandyMcGraw1_0-1644417733514.png

When I add a variable statement in front of the "fac_fields" the test runs smoothly:

RandyMcGraw1_1-1644417845834.png

Could that be the issue?

0 Kudos
jcarlson
MVP Esteemed Contributor

Oh gosh, foolish mistake on my part. Yes, the fac_fields needs a "var" in front of it. I'll fix the original post. Also, I didn't realize the output string would insert the line indentations like that, so I've adjusted that as well.

I'm still not certain why the expression doesn't return anything in the map. Other expressions seem to share this behavior, but I've not found a common cause for why it happens.

- Josh Carlson
Kendall County GIS
RandyMcGraw1
New Contributor II

I agree with you that all seems to be order with the expression and it seems to be a behavioral issue between the expression and the popup. I'm going to contact my Admin and see if we can't find a fix.

Thanks

0 Kudos
jcarlson
MVP Esteemed Contributor

Spatial operations in Arcade are dependent on the view scale, so it's possible that the features don't end up intersecting because of the map generalizing your features.

What if you tried something like buffering the feature?

First(Intersects(Buffer($feature, 10), fac))

 

That might catch more points than intended, but could indicate whether or not it's the intersection doing something different in the map view.

- Josh Carlson
Kendall County GIS
RandyMcGraw1
New Contributor II

I tried the buffer and still nothing. When I activate a Popup on both layers, they both show up in the Popup window.

0 Kudos