In ArcGIS Pro, I made 2 simple Arcade expressions to display lat and long in PopUps for polygons centroids.
Centroid($feature).x and Centroid($feature).y
As the layer is in WGS84, I get nice decimal degrees coordinates for centroids in pop-ups
Once published as a Hosted layer, the same pop-ups using same Arcade expressions display funny coordinates, like some sort of projected coordinates in meters/feets
Is it normal behavior? Is there any way to force Arcade in Portal to display decimal degrees in WGS84?
Solved! Go to Solution.
There isn't a built-in one (though that would be really handy!) But you can find a really nice function that @XanderBakker posted over here, which I am pasting with modifications below:
function MetersToLatLon(x, y) {
var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lon = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}
var c = Centroid($feature)
var coords = MetersToLatLon(c.x, c.y)
return Concatenate(coords, '\n')
The post-publishing coordinates are showing Web Mercator units. When you ask for coordinates in a web map, it will use the coordinates of the web map's projection, not the layer.
It is possible to get AGOL to open a WGS84 basemap, thus altering the map's projection, and your same expression would return decimal degrees.
I thought about the web-Mercator projection, it makes sense although not handy! In Arcade, I wonder if there is any function to translate the web-Mercator coordinates back to WGS84 decimal degrees...? Something like GeodeticX and GeodeticY, just like AreaGeodetic functions...
There isn't a built-in one (though that would be really handy!) But you can find a really nice function that @XanderBakker posted over here, which I am pasting with modifications below:
function MetersToLatLon(x, y) {
var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lon = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}
var c = Centroid($feature)
var coords = MetersToLatLon(c.x, c.y)
return Concatenate(coords, '\n')
Thanks (@XanderBakker too). It really helped.In addition, I used a simple if statment in order to display WGS84 lat/lon in decimal degrees in ArcGIS Pro, and once published to Portal using the MetersToLatLon function.
IIf(centroid($feature).x <= 180 && centroid($feature).x >= -180, centroid($feature).y + ',' + centroid($feature).x,
MetersToLatLon(centroid($feature).x, centroid($feature).y)[0] + ',' + MetersToLatLon(centroid($feature).x, centroid($feature).y)[1]);