Arcade and ArcCollector - Getting X and Y through Popups

1799
6
Jump to solution
02-19-2019 02:56 AM
TomRuff
New Contributor III

Hi,

 

I'm trying to pass the X and Y co-ordinates of a point location to Survey123 through collector. 

When I test it via the online webmap it works perfectly however when using Collector (the beta aurora version) it passes 0 to the field in Survey123.

 

Is arcade currently not supported in the Beta version of Aurora? or is there some other problem?

 

Thanks,

Tom.

0 Kudos
1 Solution

Accepted Solutions
MarkBockenhauer
Esri Regular Contributor

Tom,

Using a URL Scheme I was able to see it working.

I used the following Arcade Expression below, I made use of Xander Bakker‌ 's good examples for working with coordinates Crear un enlace con Arcade para Navegar con Waze desde la Ventana Emergente 

In my Collector webmap I configured the popup

Added an Expression

This is the expression

var x = text(geometry($feature).x)
var y = text(geometry($feature).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 text(lon + "," + lat)

Then in the custom attribute display popup configuration I made use of the Survey123 Url Scheme in the Link.

This is the link I used..

arcgis-survey123://?itemID=4560a3c533eb41fcb79fa3ec473babc8&field:TRAILNAME={expression/expr0}

In this instance I am passing the string to a text field, the trail name as pictured below.

Mark

View solution in original post

6 Replies
MarkBockenhauer
Esri Regular Contributor

Tom,

Using a URL Scheme I was able to see it working.

I used the following Arcade Expression below, I made use of Xander Bakker‌ 's good examples for working with coordinates Crear un enlace con Arcade para Navegar con Waze desde la Ventana Emergente 

In my Collector webmap I configured the popup

Added an Expression

This is the expression

var x = text(geometry($feature).x)
var y = text(geometry($feature).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 text(lon + "," + lat)

Then in the custom attribute display popup configuration I made use of the Survey123 Url Scheme in the Link.

This is the link I used..

arcgis-survey123://?itemID=4560a3c533eb41fcb79fa3ec473babc8&field:TRAILNAME={expression/expr0}

In this instance I am passing the string to a text field, the trail name as pictured below.

Mark

TomRuff
New Contributor III

Thanks very much Mark, I've managed to get to the point of having XY returned but I can't get it to pass to Survey123. The connect works when I'm using the desktop version of S123 a web map but doesn't work via collector. I'm using the most recent version of Collector but it just passes 0. Any ideas?

Tom.

0 Kudos
MarkBockenhauer
Esri Regular Contributor

Tom,

What does the URL for your Hyperlink look like?

In Collector press and hold the link.

A action panel will display, showing the link.

Mark

TomRuff
New Contributor III

Hi Mark, Thanks for getting back to me, Im on the latest version of the beta Collector for ArcGIS for android and I'm not getting the option to copy the link address by pressing and holding the link in Collector. I've tried it on a couple of different tables and getting the same issue.

Any ideas?

Tom.

0 Kudos
TomRuff
New Contributor III

I've also tried it on iOS where I can copy the url and its giving arcgis-survey123:///?itemID=(MYSURVEY)&field:incoming=(MYID)&field:TreeNumber=1&field:Tree_Loc_X=0&field:LandParcel=(MYLANDPARCEL)&field:Tree_Loc_Y=0

0 Kudos
TomRuff
New Contributor III

I've located the issue, The issue was with my original formula for some reason. The formula worked in AGOL but wouldn't in collector. When I used your adapted version of Xanders formula it worked fine. Incase its something relevant here is the formula i was using that wouldnt work on the android version:

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

function AuxSphereToLatLon(x, y) {
Console("Converting...");
//Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
var rMajor = 6378137;
var shift = PI * rMajor;
Longitude = x / shift * 180.0;
Latitude = y / shift * 180.0;
Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
Console("4326 Spatial Reference - No Conversion Necessary");
Latitude = ArcadeY;
Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
Console("102100 Spatial Reference - Conversion Necessary");
AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

function ReturnLatLong(Long, Decimals) {
return Text(Round(Long, Decimals));
}

ReturnLatLong(Longitude, 7);

(used a similar one for Lat) so i have two seperate vars.