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=*****"+"¢er="+result;
return surveyUrl;
Solved! Go to Solution.
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.
Does the expression evaluate correctly when you test it in the Expression Builder?
The quotes aren't correct when you set the URL
var surveyUrl="https://survey123.arcgis.app/?itemID=*****+¢er="+result;
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=*****"+"¢er="+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.
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.
Maybe it doesn't have an official name or anything, I just mean the screen where you're writing the expression.
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:
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:
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.
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.
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?
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.