Arcade URL Scheme Collector to Survey123 IOS Problem

598
3
11-17-2020 07:31 PM
ScottStanton__GISP
New Contributor III

Hello Everyone,

With some help from many in the community (especially Xander Baker), we have put together a custom arcade expression to pass through values to Survey123 from Collector. The below example set works like a charm on Android/Windows devices, but on iOS devices the center function does not pass through and all of the points end up on null island.

function MetersToLatLon(x, y) {
    // Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
    // Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    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];
}

function CreateURLSurvey(lat, lon) {
    var url = "arcgis-survey123://?itemID=<surveyid>";
    url += "&field:name1=" + $feature["name1"] + "&field:name2=" + $feature["name2"];
    url += "&field:name_new=" + $feature["name_new"] + "&field:rel_globalID=";
    url += $feature["GlobalID"] + "&callback=https://collector.arcgis.app";
    url += "&center=" + lat + "," + lon;
    Console(url);
    return url;
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

Has anyone experienced this problem? We are running Collector 20.2.4 and Survey123 3.11.164 on the iPad and Collector 20.2.2 and Survey123 3.11.164 on the android/windows devices. 

The center function does work on iOS when it is not an arcade expression.

0 Kudos
3 Replies
ZacharySutherby
Esri Regular Contributor

Hello @ScottStanton__GISP

 

I have tested the arcade expression on my end and I was not able to reproduce the same behavior on my IOS 14 device.

 

If you temporarily change the link's text to the Arcade expression in the pop up, in Collector do you see the XY information or is it missing from the pop up in Collector? 

 

One option you can try is encoding the XY information, something along the lines of: 

function MetersToLatLon(x, y) {
    // Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
    // Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    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];
}

function CreateURLSurvey(lat, lon) {
    var url = "arcgis-survey123://?itemID=<surveyid>";
    url += "&field:name1=" + $feature["name1"] + "&field:name2=" + $feature["name2"];
    url += "&field:name_new=" + $feature["name_new"] + "&field:rel_globalID=";
    url += $feature["GlobalID"] + "&callback=https://collector.arcgis.app" + "&center=";
    var loc =  lat + "," + lon;
    Console(url);
    return url + UrlEncode(loc);
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

 

Thank you, 

 

Zach

 

Thank you,
Zach
0 Kudos
ScottStanton__GISP
New Contributor III

@ZacharySutherby , thanks for the reply and taking time to test the problem we are having.

 

I went and added the url scheme as an item in the popup and it did come through with the correct information. It also shows correctly in the arcade test and in the attribute table. I also went ahead and tried the encoded url, but no luck on the iPad and iPhone still, but once again works on android devices.  

 

I was testing on a iPad with 13.6, but while writing this upgraded to 14.2 with similar results. I may not have mentioned this in the initial question, but all the other data I am passing through with the URL scheme works including the call back to collector, but not the center function. 

0 Kudos
ScottStanton__GISP
New Contributor III

@ZacharySutherby , can you check one more thing for me?

We had some time to do a deep dive into this and started to build these maps in AGOL from scratch and tested the arcade function each time with an iOS device. 

The problem seems to occur when we have a copy of the hosted feature service in the same map. Example, our hosted feature service (HF1a) has a filter to only show certain locations on the map. We then create a copy of that hosted feature (HF1b) service in the map to show other locations with a transparency or similar. Once we add HF1b to the map, the centering function from collector to survey123 for iOS stops working on HF1a.

0 Kudos