Hello,
I am attempting to auto calculate a field in the Field maps smart form for a hosted feature layer using the new arcade calculation capability. Using the solution provided here Solved: Using Arcade to Find the Nearest Address Point - Esri Community I kept getting wrong and inconsistent results for the nearest address. So I have now switched to making a dictionary and converting it into a feature so I can sort the buffer intersecting addresses by distance to get accurate results. Now I am just receiving null values
Our feature services are in nad 1983.
var search_distance = 150;
var addresses = FeatureSetById($map, /* AddressPoints_Export */ "AddressPoints_Export_5543")
var buf = Buffer($feature, search_distance, "feet")
var intersecting = Intersects(addresses, buf)
var cnt = Count(intersecting)
Console("Total Number of addresses within buffer: " + cnt)
var emptyDict = {
'fields': [{ 'name': 'address', 'type': 'esriFieldTypeString'},{ 'name': 'distance_a', 'type': 'esriFieldTypeInteger'}],
'geometryType': '',
'features': []
};
var index = 0;
if (cnt >0){
for (var f in intersecting){
var addressDist = number(Distance(f,$feature, "feet"));
var address_n = f.FULL_ADDRESS
for(var i = 0; i <1; i++){
emptyDict.features[index]= {
'attributes':{
'address': address_n,
'distance_a': addressDist
}
}
index++;
}
}
}
var fs_dict = FeatureSet(Text(emptyDict));
var nearest_address = First(Orderby(fs_dict, 'distance_a DESC'));
return nearest_address;
Any advice would be greatly appreciated!!
EDIT: I am able to view the dictionary successfully, but cant figure out how to sort and return it as a featureSet
