Hello!
I have two polygon layers - buildings and neighborhood zones. I need in pop up to display whether a building is located in those zones or is not.
I use this Arcade expression and it works in ArcGIS Pro:
var zones = FeatureSetByName($map, 'NB_zones', ["*"]);
var intersects = Intersects($feature, zones);
var firstFeature = First(intersects);
if (firstFeature != null) {
return "Building is in the zone";
} else {
return "Building is not in the zone";
}
So, this expression perfectly works in ArcGIS Pero but not working in ArcGIS Online Mapviewer.
What's wrong with the expression in AGOL and must be used (written) instead?
So this issue with pro vs AGO is that accessing the feature is slightly different. In AGO, or any other portal, you will need to access the feature using Portal then FeatureSetByPortalItem.
var arcgisPortal = Portal('https://www.arcgis.com');
var features = FeatureSetByPortalItem(arcgisPortal, '7b1fb95ab77f40bf8aa09c8b59045449', 0, ['Name', 'Count'], false);
You can use the $map variable in AGOL if you're referring to a featureset in the current map. If featureset is not in your map, then you have to retrieve it using FeatureSetByPortalItem.
Need to adjust your return to be an object I believe:
if (firstFeature != null) {
return { type : 'text', text : 'Building is in the zone'}
} else {
return { type : 'text', text : 'Building is not in the zone'}
}
If this a simple text element, you don't need to return an object. For an Arcade element (or a chart), you will need to return an object.
As far as I know the spec changed in 1.16 according to the docs and you have to return a dictionary if you use Arcade: Popup Element | ArcGIS Arcade | Esri Developer
At least I have to in whatever version I'm running. If i one-liner return 'This is a test', my popup is blank.
Oh I see it now. I had no idea you could do it that way.