Select to view content in your preferred language

Arcade popup gives varying results

170
2
Jump to solution
04-11-2025 06:59 AM
Labels (1)
Ehei_Dogen
Frequent Contributor

I'm making a web map with ~ 19 layers for use in the Zone Lookup app. I'm using Arcade attribute expressions within one layer ('Counties') for all layers. For example, the Counties layer popup includes expressions for County, City, Census tract, and so on. The reason for this is that using separate popups for each layer uses a large amount of blank space in between the individual popups.

I have two census layers for Native American land - reservation land and trust land. I thought I could combine them in one expression, to save space, since the two classifications should never overlap. the expression should either return the name of one of the land types or NA.

The problem is that sometimes it works, and sometimes it doesn't. It may or may not show the type name, and may or may not show NA. Running the expression in the Arcade editor sometimes works, and sometimes raises a "Test execution error: Unknown Error. Verify test data." error. I can't figure out why. Layer and field names are correct. Any ideas? Running on ArcGIS Enterprise 11.3, with the census layers from the Tigerweb shapefile REST endpoint, filtered in the map to Michigan..

 

var click = $userInput;
if (TypeOf(click) == 'Point') {
    var center = Point({x: click.x, y: click.y, spatialReference: {wkid: 3857}})
};

if(Count(Intersects(center, FeatureSetByName($map, "Trust Lands", ['Name'], false))) > 0) {
  return First(Intersects(center, FeatureSetByName($map, "Trust Lands", ['Name'], false)))['Name']
}
else if(Count(Intersects(center, FeatureSetByName($map, "Indian Reservations", ['Name'], false))) > 0) {
  return First(Intersects(center, FeatureSetByName($map, "Indian Reservations", ['Name'], false)))['Name']
}
else {
  return 'NA'
};

 

0 Kudos
1 Solution

Accepted Solutions
NicoleJohnson
Frequent Contributor

I have no idea why your code isn't working consistently, but I seem to be getting consistent results with this, approached a little differently:

var click = $userInput;
if (TypeOf(click) == 'Point') {
    var center = Point({x: click.x, y: click.y})
};

var trust = FeatureSetByName($map, "Trust Lands", ['NAME'], false)
var res = FeatureSetByName($map, "Indian Reservations", ['NAME'], false)

var trustTest = Intersects(center, trust)
var resTest = Intersects(center, res)

var popupString

if (IsEmpty(trustTest) == false){
  for (var i in trustTest){
    popupString = i.NAME
  }
}

if (IsEmpty(resTest) == false){
  for (var k in resTest){
    popupString = k.NAME
  }
}

DefaultValue(popupString, "NA")

I would think testing if a featureset has more than 0 records in it would be the same as checking if it's not empty. I also changed to just a loop rather than getting the first item in the featureset (even though in theory, shouldn't those be the same since there's only one item? My head's spinning...).

View solution in original post

2 Replies
NicoleJohnson
Frequent Contributor

I have no idea why your code isn't working consistently, but I seem to be getting consistent results with this, approached a little differently:

var click = $userInput;
if (TypeOf(click) == 'Point') {
    var center = Point({x: click.x, y: click.y})
};

var trust = FeatureSetByName($map, "Trust Lands", ['NAME'], false)
var res = FeatureSetByName($map, "Indian Reservations", ['NAME'], false)

var trustTest = Intersects(center, trust)
var resTest = Intersects(center, res)

var popupString

if (IsEmpty(trustTest) == false){
  for (var i in trustTest){
    popupString = i.NAME
  }
}

if (IsEmpty(resTest) == false){
  for (var k in resTest){
    popupString = k.NAME
  }
}

DefaultValue(popupString, "NA")

I would think testing if a featureset has more than 0 records in it would be the same as checking if it's not empty. I also changed to just a loop rather than getting the first item in the featureset (even though in theory, shouldn't those be the same since there's only one item? My head's spinning...).

Ehei_Dogen
Frequent Contributor

Thanks Nicole, I'll give that a try.

0 Kudos