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:
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
Solved! Go to Solution.
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;
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}
`
}
Happy Friday Ken, so, I should put the entire code in Arcade element and not in expressions?
@KellyGerrow @HeatherSmith can you please help with this?
Thank you
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;
@KenBuja thank you so much for the quick response. Arcade is giving me an error with `+=`
Test execution error: Unexpected token '+='.. Verify test data.
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
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}`
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}
`
}
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?
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
}
Bro you are awesome 😎👍