Select to view content in your preferred language

Pull multiple attributes from multiple overlapping layers in single popup

5451
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
34 Replies
KenBuja
MVP Esteemed Contributor

You can put in two line breaks

<b>Area:</b> ${f.AREAFT} <br><br>
KenBuja
MVP Esteemed Contributor

There is only one return of the text property, so the last one is used. What you should do is

// Create a variable that the FeatureSet of intersecting feature attributes  
var building = FeatureSetByName($map, "BuildingFootprints_Clip")
var intersectLayer = Intersects(building, $feature)  
var popup = '<h2>Building</h2>';
for (var f in intersectLayer){ 
  var popup += `<b>Area:</b> ${f.AREAFT} 

  
  <b>Length:</b> ${f.LENFT} 
  
  
  <b>ID:</b> ${f.ID}
`
}
popup += '<h2>Points</h2>'; 

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

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Happy Monday, Ken, thank you for providing further guidance. 

Have a wonderful week 🙂

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

Hi Ken so, I have multiple intersected layers like I think up to 5, meaning 5 headings (one of each layer) along with their respective intersect code. So would you recommend putting all these in one Arcade element or should I create like 5 separate ones?

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

It might be easier to have them in one element, with one code block to maintain.

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi Ken,

I have an update, so when I add += in line 11 of my code (line 6 of your code), I get an unexpected token error.

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

var intersectLayer = Intersects(building, $feature)  

var popup = '<h2>Building</h2>';

for (var f in intersectLayer){ 
  var popup += `<b>Area:</b> ${f.AREAFT} <br><br>

  
  <b>Length:</b> ${f.LENFT} <br><br>
  
  
  <b>ID:</b> ${f.ID} <br><br>
`
}  

popup += '<h2>Points</h2>';

return {

  type : 'text',
  text : popup

}

// Now bring in the attributes from the next intersected layer with Parcel

 

SaadullahBaloch_0-1693248852670.png

 

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

Sorry...remove "var" from line 9. Leave everything else in that line, though

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi Ken, I was able to work out the code a  bit further. It's interesting to note that I can keep on using the `popup` variable. Looking quite nice so far, thank you so much for all your help and especially your quick responses. I will let you know if I am stuck again. 

Have a wonderful week 🙂

Working code so far:

 

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

var intersectLayer = Intersects(building, $feature)  

// This variable will be repeated multiple times in the code
var popup = '<h2>Building</h2>';

for (var f in intersectLayer){ 
   popup += `<b>Area:</b> ${f.AREAFT} <br><br>

  
  <b>Length:</b> ${f.LENFT} <br><br>
  
  
  <b>ID:</b> ${f.ID} <br><br>
`
}  

// Now bring in the attributes from the second intersected layer with Parcel

popup += '<h2>Points</h2>';

var point = FeatureSetByName($map, "FloodFactor_Points_Clip")

var intersectLayerb = Intersects(point, $feature)  

for (var f in intersectLayerb){ 
   popup += `<b>Flood Factor:</b> ${f.floodfactor} <br><br>

  <b>FSID:</b> ${f.fsid} <br><br>
`
}  

popup += '<h2>Next Layer</h2>';

// Now bring in the attributes from the third intersected layer with Parcel

return {

  type : 'text',
  text : popup

}

 

 

SaadullahBaloch_0-1693263293764.png

 

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

Hi Ken, another question please, so now I want to add the attributes from the parcel layer that surrounds the other layers. When the user clicks on it the popup will appear. Hence this layer does not need the intersect function. 

But my code below is not working as shown in the screenshot.

I did try using a for loop but that returns each and every parcel's selected attributes  which is not what I want.

Code for parcel attributes:

 

 

// Now bring in the attributes from the layer the parcel layer, this layer surrounds other layers (whcih intersect Parcel) so the popup originates when the user clicks on a Parcel
var parcel = FeatureSetByName($map, "Parcels_with_FloodFacto_Clip")

   popup += `<b>Folio:</b> $Parcels_with_FloodFacto_Clip.FOLIO <br><br> 

  <b>FSID:</b> $parcel.fsid <br><br>
`

 

 

 

Entire code:

 

 

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

var intersectLayer = Intersects(building, $feature)  

// This variable will be repeated multiple times in the code
var popup = '<h2>Building</h2>';

for (var f in intersectLayer){ 
   popup += `<b>Area:</b> ${f.AREAFT} <br><br>

  
  <b>Length:</b> ${f.LENFT} <br><br>
  
  
  <b>ID:</b> ${f.ID} <br><br>
`
}  

// Now bring in the attributes from the second intersected layer with Parcel

popup += '<h2>Points</h2>';

var point = FeatureSetByName($map, "FloodFactor_Points_Clip")

var intersectLayerb = Intersects(point, $feature)  

for (var f in intersectLayerb){ 
   popup += `<b>Flood Factor:</b> ${f.floodfactor} <br><br>

  <b>FSID:</b> ${f.fsid} <br><br>
`
}  

popup += '<h2>Parcel</h2>';

// Now bring in the attributes from the layer the parcel layer, this layer surrounds other layers (whcih intersect Parcel) so the popup originates when the user clicks on a Parcel
var parcel = FeatureSetByName($map, "Parcels_with_FloodFacto_Clip")

   popup += `<b>Folio:</b> $feature.FOLIO <br><br> 

  <b>FSID:</b> $parcel.fsid <br><br>
`
 

return {

  type : 'text',
  text : popup

}

 


Current output:

SaadullahBaloch_0-1693363791670.png

 

 

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

When using template literals, you have to surround an expression with a dollar sign and curly braces, otherwise it's interpreted as just text.

popup += `<b>Folio:</b>${$feature.FOLIO}<br><br> 

I don't understand how you are using the parcel layer. You're returning a FeatureSet in line 38, but how are you getting the feature from that FeatureSet to show its fsid attribute?