Arcade Centroid function doesn't work with Web AppBuilder application

1757
8
Jump to solution
03-19-2021 10:29 AM
Ming
by
Occasional Contributor

With ArcGIS Enterprise 10.7.1, have a web map with a polygon layer, and an App created using the Web AppBuilder with that web map. The polygon layer has a custom attribute defined with following Arcade code. When open attributes table in the App, that polygon layer can't show attributes but got stuck.

//
function MetersToLatLon(mx, my) {
var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (mx / originShift) * 180.0;
var lat = (my / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}

var pnt_centr = Centroid($feature);
var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);
var result = Round(latlon[0], 6) + "," + Round(latlon[1], 6);


var surveyUrl="https://survey123.arcgis.app/?itemID=*****"+"&center="+result;
return surveyUrl;

0 Kudos
1 Solution

Accepted Solutions
Ming
by
Occasional Contributor

That link attribute with centroid function is used for popup, not necessary to display in attribute table, so the workaround is:

1. Configure Attributes Table widget.

2. Select the layer, configure Fields, and uncheck that field.

View solution in original post

8 Replies
jcarlson
MVP Esteemed Contributor

Does the expression evaluate correctly when you test it in the Expression Builder?

- Josh Carlson
Kendall County GIS
0 Kudos
KenBuja
MVP Esteemed Contributor

The quotes aren't correct when you set the URL

var surveyUrl="https://survey123.arcgis.app/?itemID=*****+&center="+result;
0 Kudos
Ming
by
Occasional Contributor

Thanks for the reply. ArcGIS Enterprise 10.7.1 doesn't have built-in Expression Builder, so we didn't test that. But with Field Maps app and map viewer, that link works.

When use web map expression editor to test that link, it also works well.

The surveyUrl is "https://survey123.arcgis.app/?itemID=*****"+"&center="+result.

I used ** to replace the real item id.

For Web AppBuilder App, it just doesn't show any record for that layer in the attributes table.

0 Kudos
KenBuja
MVP Esteemed Contributor

I used the Arcade playground to test your code and that original line was flagged as error, but somehow my copy and paste dropped a quote. It does return a value for the centroid.

arcade.png

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Maybe it doesn't have an official name or anything, I just mean the screen where you're writing the expression.

jcarlson_0-1616176171822.png

But if it's working in Field Maps, then it may be an issue specific to WAB. Using your same expression, I get this in a web map:

jcarlson_1-1616176889377.png

But when I go to open the Attribute Table widget in WAB, it hangs, just as you're experiencing. Interestingly, I see the same issue even in the Map Viewer's attribute table:

jcarlson_2-1616177036879.png

I don't think there's anything wrong with your code, but something about the expression and how the table is trying to interpret it. It may be a bug, or perhaps a limitation of some sort. I've tested a few alternate methods, but cannot get the lat/lon values to populate the table.

- Josh Carlson
Kendall County GIS
0 Kudos
Ming
by
Occasional Contributor

Thanks for all the help.

Actually the popup works, so means the code is correct. 

Just the attributes table hangs and can't show any records. 

We once used geoprocessing tool and generated lat/long into two columns. In that case the attributes table can show records, but now it can't with the Arcade to generate lat/long.

So I think it is a bug that the Arcade Centroid function doesn't work well with WAB application's attributes table widget.

Ming_0-1616178084184.png

 

0 Kudos
jcarlson
MVP Esteemed Contributor

It seems that way, unfortunately. I can't even get it to return Centroid($feature).x in the attribute table, so that's pretty clear it's the centroid function in particular.

Where does the data originate? Any chance you could use an attribute rule to populate a new field?

- Josh Carlson
Kendall County GIS
0 Kudos
Ming
by
Occasional Contributor

That link attribute with centroid function is used for popup, not necessary to display in attribute table, so the workaround is:

1. Configure Attributes Table widget.

2. Select the layer, configure Fields, and uncheck that field.