Custom URL and the ¢er function

285
6
05-04-2020 01:54 PM
AprilChipman
Occasional Contributor III

I have several surveys that receive pass-through attribute information from existing features on other layers. All of the attribute information is populating in Survey123 perfectly well, but I can't get the &center function to work. I either get a point off the west coast of Africa or one right where the survey was submitted. Never on top of the existing feature.

I'm using Survey123 Connect version 3.7.62 and ArcGIS Enterprise/Portal 10.6.1. Before migrating to Enterprise, this process worked very well in ArcGIS Online.

Here's an example of my custom URL: 

arcgis-survey123://?itemID=xxxxxxxxxxxx&field:Comments={maplocation}&field:Date={installdate}&center={expression/expr0},{expression/expr1}

expr0:

var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (Geometry($feature).x / originShift) * 180.0;
var lat = (Geometry($feature).y / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lon;

expr1:

var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (Geometry($feature).x / originShift) * 180.0;
var lat = (Geometry($feature).y / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lat;

6 Replies
JamesTedrick
Esri Esteemed Contributor

Hi April,

Just to check, which locale/language are your devices in?  We will be releasing an update to the field application to address issues that have been raised in decimal comma locales (i.e., French, Nederlands).

What client are you viewing the link in (Collector, Explorer, Web Map Viewer)?  It sounds like we would need to raise an issue with that application.

0 Kudos
AprilChipman
Occasional Contributor III

Thanks for the reply, James!

I am in the US and using the English language.

The link is commonly used in Collector, but I'm starting to get reasons to use them in webapps and dashboards.

Also, I found this other thread: Can't pass attributes of a line from Collector to S123   and was able to use a different version of the Arcade expression to get the center function to work, but only in individual layers. If I have a service with several layers, the expression throws an error.

Here is the expression that works to get the x,y location of existing points for Survey123:

function LatLon(x, y) {

var lon = (Geometry($feature).x);
var lat = (Geometry($feature).y);

return [lat, lon];
}
function CreateURLSurvey(lat, lon) {
var url = lat + "," + lon;// This is the line that defines the location
Console(url);
return url;
}

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

0 Kudos
BenBaker1
New Contributor III

I'm having a similar issue. I have a link in a web map popup that was working a few weeks ago. When I revisited that project this week, the link is no longer pulling the custom URL scheme correctly. The map and dashboard the link is included in are published to ArcGIS Online.

The URL Scheme matches the recommended formatting, although it's not pulling into the survey form. The map is centering on current location instead of the parameters passed in the URL scheme. This is the case on Android and Apple devices, although if I launch S123 from a Chrome browser on my desktop, the parameters are passed correctly.

Here's my HTML as well as the URL that launches S123 from the Dashboard:

<a href="arcgis-survey123://?itemID=14fcceaf30084ace8c3345efc006469b&amp;field:Address={Address}&amp;field:OccType={OccType}&amp;field:BusName={BusName}&amp;field:BusType={BusType}&amp;field:InspType=102&amp;center={LAT},{LON}" rel="nofollow ugc" target="_blank">Complete Reinspection</a>

arcgis-survey123://?itemID=14fcceaf30084ace8c3345efc006469b&field:Address={Address}&field:OccType={OccType}&field:BusName={BusName}&field:BusType={BusType}&field:InspType=102&center={LAT},{LON}

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Ben,

Rather than manually typing your URL, you should use the Arcade UrlEncode() function to construct the URL - this will ensure the proper number format is used.

0 Kudos
BenBaker1
New Contributor III

Thank you, James Tedrick. I've been testing this function but am not familiar with how to pass field parameters (from the attributes or other Arcade expressions). I finally settled on the following, although if there's a way to set up each field parameter with the params variable, I'd be interested to try it out.

Var urlsource = 'arcgis-survey123://?'

var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lon = (Geometry($feature).x / originShift) * 180.0;
var lat = (Geometry($feature).y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
var centerpoint= Round(lat,6)+','+Round(lon,6);

Var params = {
itemID: '14fcceaf30084ace8c3345efc006469b',
center: centerpoint
};
Return urlsource + UrlEncode (params) + '&field:Address={Address}&field:OccType={OccType}&field:BusName={BusName}&field:BusType={BusType}&field:InspType=102'
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
BenBaker1
New Contributor III

I spoke too soon. The code above is passing the field parameters dynamically, but the centerpoint variable is pulling the same lat/lon for every point in the popup instead of from each feature. When I changed the expression to what is shown below, the Lat/Lon is changing for the respective point I select, but now the field parameters are 'hard coded' into the URL and are not pulling the attributes. I think I'm missing something?

Var urlsource = 'arcgis-survey123://?'

function MetersToLatLon(mx, my) {
// Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
// Fuente: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
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 poly = Geometry($feature);

var result1 = "";
if (!IsEmpty(poly)) {
var pnt_centr = Centroid(poly);

var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);

result1 = Round(latlon[0], 6);
} else {
result1 = "";
}

function MetersToLatLon(mx, my) {
// Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
// Fuente: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
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 poly = Geometry($feature);

var result2 = "";
if (!IsEmpty(poly)) {
var pnt_centr = Centroid(poly);

var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);

result2 = Round(latlon[1], 6);
} else {
result2 = "";
}


//return result1;
//return result2;

var centerpoint = result1 + ',' + result2

Var params = {
itemID: '14fcceaf30084ace8c3345efc006469b',
center: centerpoint
};
Return urlsource + UrlEncode (params) + '&field:Address={Address}&field:OccType={OccType}&field:BusName={BusName}&field:BusType={BusType}&field:InspType=102'

0 Kudos