I have a web map that includes the Watershed Boundary Dataset HUC 10s Living Atlas dataset. In Experience Builder, I need to use arcade to calculate the total area of each watershed that intersects with the USA Census States Living Atlas layer polygons (currently in the web map, but visibility is turned off). The purpose is to account for open water areas present within coastal watershed. I want the total land area of the watershed, minus the coastal open water outside of the states boundaries.
I am able to successfully do this in the popup arcade expressions within Map Viewer:
var states = Intersects(FeatureSetByName($map, "USA Census States"), $feature);
var cnt = Count(states);
var intersectArea = 0;
if (cnt > 0) {
for (var st in states) {
intersectArea += AreaGeodetic(Intersection($feature, st), "acres");
}
}
var acres = intersectArea
return Text(Round(acres, 2), "#,###.00");
However, in Experience Builder, the text widget arcade expressions do not support the "Intersection()" function. The Add Data via arcade option seems to support all these functions, but I am not able to get the arcade code to work and it does not show me where the errors are. This is the code I have in Add Data that is not working:
// returns the number of sensitive areas that intersect the selected feature
var p = Portal("https://arcgis.com");
var states = FeatureSetByPortalItem(p, "774019f31f8549c39b5c72f149bbe74e", 0);
var watershed = FeatureSetByPortalItem(p, "42f868d269784624b0a2df9757c34abb", 0);
var x = Intersects(states, watershed);
var cnt = Count(x);
var intersectArea = 0;
if (cnt > 0) {
for (var st in states) {
intersectArea += AreaGeodetic(Intersection(states, watershed), "acres");
}
}
var acres = Round(intersectArea,2);
return Text(Round(acres, 2), "#,###.00");It just says "Test execution error: Execution error - Invalid parameter. Verify test data"
Ideally the goal is to not have to publish our own copies of these datasets (which would otherwise allow me to do all these calculations as a new field), and instead do the on the fly calculations off of the Living Atals datasets via arcade.
Please let me know if you have any ideas.