Select to view content in your preferred language

Pull multiple attributes from multiple overlapping layers in single popup

2848
34
Jump to solution
08-23-2023 08:19 AM
Ed_
by MVP Regular Contributor
MVP Regular Contributor

I have three layers, two of them are polygons (parcels and buildings) and one of them is a point. I would like the parcel's popup to return multiple attributes/columns from the building layer as well as the point layer.

 

Based on the code below, I am able to show a single corresponding attribute from the building layer when a parcel is clicked.

But now I want to return more attributes from the building layer as well. 

How can I do this?

Like let's say I also want return values from the columns `LenFt` and `ID` then how can I do that?

Side question: Also is there a way to add contextual text before the attribute value in the Arcade code?

Like let's say I want to add bold `Area:`, `Length:` and `ID:` before each of the returned attribute value.

Attributes of interest from the building layer:

SaadullahBaloch_0-1692803933589.png

 

Code:

 

// Create a variable that the FeatureSet of intersecting feature attributes  
var building = FeatureSetByName($map, "BuildingFootprints_Clip")

var intersectLayer = Intersects(building, $feature)  

for (var f in intersectLayer){ 
	
	var popup = f.AREAFT
	
	}  
 
 return popup

 

 

Question | Analyze | Visualize
3 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Here's one way to do that. This uses template literals, including a carriage return at the end for multiple buildings getting returned.

var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup;
for (var f in intersectLayer){ 
  var popup += `Area: ${f.AREAFT}, Length: ${f.LenFt}, ID: ${f.ID}
`
}  
return popup;

 

 

View solution in original post

KenBuja
MVP Esteemed Contributor

This will put everything on its own line. The error you were getting was due to "var" on line 5. I forgot to edit that out when updating it for multiple buildings on a parcel.

var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup;
for (var f in intersectLayer){ 
  popup += `Area: ${f.AREAFT}
Length: ${f.LenFt}
ID: ${f.ID}
`
}  
return popup;

 If you want an extra line between each, you can easily do that

for (var f in intersectLayer){ 
  popup += `Area: ${f.AREAFT}

Length: ${f.LenFt}

ID: ${f.ID}
`
}  

 

View solution in original post

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Happy Friday Ken, so, I should put the entire code in Arcade element and not in expressions? 

Question | Analyze | Visualize

View solution in original post

0 Kudos
34 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

@KellyGerrow @HeatherSmith can you please help with this?

Thank you

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

Here's one way to do that. This uses template literals, including a carriage return at the end for multiple buildings getting returned.

var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup;
for (var f in intersectLayer){ 
  var popup += `Area: ${f.AREAFT}, Length: ${f.LenFt}, ID: ${f.ID}
`
}  
return popup;

 

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

@KenBuja thank you so much for the quick response. Arcade is giving me an error with `+=`

Test execution error: Unexpected token '+='.. Verify test data.

 

Question | Analyze | Visualize
0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

The code works fine if I replace `+=` with `=`. 

Output:

Area: 3376, Length: 3376, ID: 0 

 

Can you please tell me how I get the output such that each subsequent attribute value is in a new line like shown below?


Area: 3376

Length: 3376

ID: 0

 

Question | Analyze | Visualize
0 Kudos
Ed_
by MVP Regular Contributor
MVP Regular Contributor

No worries, I was able to get the attribute value in a separate line using the following code:

 

var popup = `Area: ${f.AREAFT} \n Length: ${f.LENFT} \n ID: ${f.ID}`

 

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

This will put everything on its own line. The error you were getting was due to "var" on line 5. I forgot to edit that out when updating it for multiple buildings on a parcel.

var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup;
for (var f in intersectLayer){ 
  popup += `Area: ${f.AREAFT}
Length: ${f.LenFt}
ID: ${f.ID}
`
}  
return popup;

 If you want an extra line between each, you can easily do that

for (var f in intersectLayer){ 
  popup += `Area: ${f.AREAFT}

Length: ${f.LenFt}

ID: ${f.ID}
`
}  

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Oh thank you so much, that's so cool and much easier than what I did. One last question please, is there a way to make a the text including the colon bold before the attribute value bold?

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

Yes, but you have to use an Arcade element in your popup. Your code would look something like this

var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup;
for (var f in intersectLayer){ 
  popup += `<b>Area:</b> ${f.AREAFT}
<b>Length:</b> ${f.LenFt}
<b>ID:</b> ${f.ID}
`
} 

return { 
  type : 'text', 
  text : popup
} 

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Bro you are awesome 😎👍

Question | Analyze | Visualize
0 Kudos