Select to view content in your preferred language

Pop up Arcade expression script working in ArcGIS Pro but not working in ArcGIS Online

194
7
2 weeks ago
LIEPAJABUILDINGBOARD
Occasional Contributor

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?

0 Kudos
7 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @LIEPAJABUILDINGBOARD,

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);
0 Kudos
KenBuja
MVP Esteemed Contributor

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.

0 Kudos
JohnEvans6
Frequent Contributor

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'}
}

 

0 Kudos
KenBuja
MVP Esteemed Contributor

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.

0 Kudos
JohnEvans6
Frequent Contributor

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

I'm referring to a text element like this:

Snag_74057a.png

The expression used in that element just has a text return, not an object return

Snag_721ec8.png

var label = "This is a test"
return label

Snag_74974a.png

JohnEvans6
Frequent Contributor

Oh I see it now. I had no idea you could do it that way.

0 Kudos