Display multiple pdf attachments from another layer in popup using Arcade

279
1
01-31-2024 12:01 PM
Labels (1)
DylanBroderick
New Contributor

I'm somewhat new to Arcade and have been experimenting with FeatureSets. I've had success displaying attributes in one layer that intersect with features in another (clicked) layer, but am stuck on getting linked attachments to display in the popup.

Specifically, I have a 'Parcels' polygon layer and a 'Surveys' polygon layer. I'd like to display various elements from 'Surveys' if the polygon centroid intersects a clicked 'Parcels' polygon. Both are feature services, but cannot be joined by any common attribute between the two layers (only their spatial relationship). All 'Surveys' should have an attachment, which is a public hyperlink to a pdf.

Here is an example of what I'm working with so far: 

 

 

 

var parcelFeature = $feature;
var surveysLayer = FeatureSetByName($map, "Survey Library");

// Intersect the parcel with the polygons of the surveys layer
var surveysIntersect = Intersects(parcelFeature, surveysLayer);

if (Count(surveysIntersect) > 0) {
  var surveyInfo = "";
  for (var survey in surveysIntersect) {
    var surveyCentroid = Centroid(Geometry(survey)); // Check if the centroid of the survey polygon falls within the clicked parcel
    if (Contains(parcelFeature, surveyCentroid)) {
      surveyInfo += "Survey Type: " + survey.survey_type + "\n";
      surveyInfo += "Survey Date: " + Text(survey.survey_date, 'YYYY-MM-DD') + "\n";
      surveyInfo += "Surveyor: " + Text(survey.surveyor_name) + "\n\n";
    }
  }

  if (surveyInfo != "") {
    return surveyInfo;
  } else {
    return "There is no attachment available for this survey.";
  }
} else {
  return "There are no surveys associated with this parcel";
}

 

 

 

 
How can I add an additional "surveyInfo" line for the popup with a link to the attachment? Since the field name for attachments is a bit different, I'm not sure how to reference it. I've found some examples (e.g., here) using a concatenation of layer's link with the [OBJECTID], "/attachments/", and the attachment [id], but haven't been able to get the syntax quite right for it to work.
 
Thanks in advance! 
Dylan
 
Edit: I was able to display the link in a separate expression using the following: 

 

 

var parcelFeature = $feature;

var attachmentLayer = FeatureSetByName($map, "Survey Library");

var intersectingAtts = Intersects(attachmentLayer, parcelFeature);

var surveyAtt = "";
for (var survey in intersectingAtts) {
  var ObjectID = survey.OBJECTID
  var AttachID = First(Attachments(survey)).ID
  var Part1 = "https://services1.arcgis.com/abc/arcgis/rest/services/def/FeatureServer/0/" //dummy link to service
  var Part2 = "/attachments/"
  var link = Part1 + ObjectID + Part2 + AttachID
}

return link

if (surveyAtt != "") {
  return link;
} else {
  return "No survey available.";
}

 

 

 

The remaining challenge is that some surveys have more than one attachment. I know this is related to the First() function but am not sure how to rewrite/loop through the AttachID variable to call all attachments instead of just the first.

 

0 Kudos
1 Reply
Rémi
by
New Contributor II

I have a similar problem. Did you find a solution?

0 Kudos