I am trying to create an Arcade script that, within the pop-up, will return the next closest feature within the same layer. In my case, if I click on a wildfire point, it will tell me what the next closest wildfire point is. I have has some success changing up the script found in lines 30-44 here, but what I have found is that my current script returns the point that is furthest from the selected point within the search distance. Any guidance on what I can do?
var searchDistance =50;
var points = $layer
var closestPoint = Intersects(points, BufferGeodetic($feature, searchDistance, "Miles"));
var minDistance = Infinity
for(var listing in closestPoint){
var facilityDistance = Distance(listing, $feature, "miles");
if (facilityDistance < minDistance){
closestPoint = listing;
return closestPoint.iaName
}
};
Solved! Go to Solution.
Hi @AFackler_NAPSG ,
You have to update the minimum distance and as @KenBuja pointed out you have to put the return outside the for loop.
var searchDistance = 50;
var points = $layer;
var CurrentiaName = $feature.iaName;
var closestPoints = Intersects(points, BufferGeodetic($feature, searchDistance, "Miles"));
var minDistance = Infinity;
for(var pnt in closestPoints){
var facilityDistance = DistanceGeodetic(pnt, $feature, "miles");
if (facilityDistance < minDistance){
if (CurrentiaName != pnt.iaName) {
closestPoint = pnt;
minDistance = facilityDistance;
}
}
};
return closestPoint.iaName;
Furthermore, you have to avoid returning the same input feature. You could do this by checking for an ID (I used the iaName in this case.
Give this a try
var searchDistance =50;
var points = $layer
var closestPoints = Intersects(points, BufferGeodetic($feature, searchDistance, "Miles"));
var closestPoint;
var minDistance = Infinity;
for(var listing in closestPoints){
var facilityDistance = Distance(listing, $feature, "miles");
if (facilityDistance < minDistance){
closestPoint = listing;
}
};
return closestPoint;
Hi @AFackler_NAPSG ,
You have to update the minimum distance and as @KenBuja pointed out you have to put the return outside the for loop.
var searchDistance = 50;
var points = $layer;
var CurrentiaName = $feature.iaName;
var closestPoints = Intersects(points, BufferGeodetic($feature, searchDistance, "Miles"));
var minDistance = Infinity;
for(var pnt in closestPoints){
var facilityDistance = DistanceGeodetic(pnt, $feature, "miles");
if (facilityDistance < minDistance){
if (CurrentiaName != pnt.iaName) {
closestPoint = pnt;
minDistance = facilityDistance;
}
}
};
return closestPoint.iaName;
Furthermore, you have to avoid returning the same input feature. You could do this by checking for an ID (I used the iaName in this case.
Thank you @KenBuja and @XanderBakker !