Return list of values in pop-up with arcade

6003
10
Jump to solution
06-30-2020 01:48 AM
LauraGuthschmidt
New Contributor III

I have a point layer of farms with several features, including a TRUE/FALSE field which tells me if the farm has submitted data that we require. We would like to be able to overlay this with a polygon layer of provinces to see per province how many farms have submitted the data, and then list their names in the polygon pop-up.

Please note that I am very new to arcade.

I have succeeded in the first expression of counting the farms, and am well on my way with the second expression, but I keep running into the following problem: According to multiple blogs/questions https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2018/12/10/overlapping-features-i..., Using FeatureSetBy functions in Arcade to drill-down to other layers and tables, my script looks as it should as far as I can see:

var farms = FeatureSetByName($map,"CoordinatesMasterZonal");
var gis = Intersects(Filter(farms,"GIS_Submitted LIKE 'TRUE'"),$feature);
var gistrue = "";
if (gis > 0) {
    for (var f in gis) {
        gistrue = f.Site_Name + ".  "+ TextFormatting.NewLine + "View their BEIA report here";
    }
} else {
    gistrue = "No farms in this province have submitted GIS data yet"
}  
return gistrue

However, this gives me an output like non of the farms have submitted the data for all provinces, even when I know that there are farms intersecting that have submitted the data.

The following does give me a better output:

var farms = FeatureSetByName($map,"CoordinatesMasterZonal");
var gis = Intersects(Filter(farms,"GIS_Submitted LIKE 'TRUE'"),$feature);
    for (var f in gis) {
        gis = f.Site_Name + ".  "+ TextFormatting.NewLine + "View their BEIA report here";
    }
return gis

But it doesn't loop through the "gis" list and only gives me one value for each province.

What am I missing here to achieve a full list per province?

Thanks!

10 Replies
anonymous55
Occasional Contributor II

Hello

I have this code which sort values base on buffer 1000 feet and return First values. I want to return all values inside the buffer not just one. is it any way I can do this? 

Thanks

 

// If the feature doesn't have a geometry, return null
if (IsEmpty(Geometry($feature))) { return null }
// Get the bus stops layer
// To customize, replace the layer name below
var busStops = FeatureSetByName($map,"RTD Active Bus Stops")
// Buffer the current location and intersect with the bus stops
var bufferedLocation = Buffer($feature, 1000, 'feet')
var candidateStops = Intersects(busStops, bufferedLocation)
// Calculate the distance between the bus stops and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateStops) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}
// Sort the candidate bus stops by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest bus stop
var closestFeatureWithDistance = First(sorted)
// If there was no bus stop, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the bus stop name attribute value
// To customize, replace the field name "STOPNAME" below
return `${closestFeatureWithDistance['feature']['STOPNAME']}`

 

 

0 Kudos