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";
}
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.
I have a similar problem. Did you find a solution?