Custom URL and the ¢er function

1800
9
Jump to solution
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;

1 Solution

Accepted Solutions
JoshConrad1
New Contributor III

All:

I have been experiencing the same issues described in this thread: trying to create an attribute expression that calculates lat/long coordinates from a hosted feature layer, then integrate Field Maps with Survey123 to open a form and have the geopoint plot the submitted survey on top of the feature using the result of the attribute expression using a custom URL via the custom URL popup (&center=).

I have been using the "Expression/expr2 - Code to calculate geometry" formula called out in this post (and a multitude of others on the community page) and it was correctly calculating the coordinates in ArcGIS Online Web Viewer Classic, but then when we tested this functionality in the field, the point was not mapping.

I found that the original formula in the "Expression/expr2 - Code to calculate geometry" results in an Array data type, with associated brackets. These brackets do not show up in ArcGIS Online, but when you view the popup in Field Maps, you can see the brackets. So because of this, i tested further and in the original function, i removed the brackets in the result line, which worked but was not perfect. It was not perfect because the coordinate results ended up being truncated to 2 decimals, and even though the submitted form was executing, the point was being plotted hundred of feet away.

After 10 hours of testing and researching these threads (which by the way, all of the contributions are EXPONENTIALLY HELPFUL AND I AM SO GRATEFUL OF YOUR KNOWLEDGE) i was able to find the CORRECT SOLUTION:

1.) Create an attribute expression for latitude:

var lat;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lat = number(Geometry($feature).y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lat;

2.) Create an attribute expression for longitude:

var lon;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lon = number(Geometry($feature).x / originShift) * 180.0;
return lon;

3.) Because of the "number" identifier, In ArcGIS Online Web Map Viewer Classic go to Configure Popups, make sure your pop up display is custom, then the important step is to click Configure Attributes. Navigate to the newly created expressions and expand the decimal places to a minimum of 5.

4.) Lastly, in the custom URL make the "&center={expression/expr3},{expression/expr4} where expr 3 is Lat and expr 4 is Long.

I have been testing since i discovered this and it has been running smoothly. Happy Mapping!

View solution in original post

9 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
Occasional Contributor

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
Occasional Contributor

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
Occasional Contributor

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
by Anonymous User
Not applicable

Any update on this topic? I am pairing a field maps app with Survey123. I have configured custom pop-ups in Map Viewer classic so when a field worker opens the field maps app & clicks a location they can launch a survey for that feature. I am able to pass the location name but am struggling to pass the coordinates from the feature service to the survey. My survey test points keep appearing at my current location rather than the location of the feature. My custom Url looks like this:

arcgis-survey123://?itemID= 40852746f5bb43478bae2dbb6axxxxxx&field:location={expression/expr0}&center={Expression/Expr1},{Expression/Expr2}&callback=https://fieldmaps.arcgis.app

Here are my expressions:

Expression/expr0:

Proper($feature.POI_NAME)

Expression/expr1:

var lon = (Geometry($feature).x);
return lon

Expression/expr2:

var lat = (Geometry($feature).y);
return lat

0 Kudos
JoshConrad1
New Contributor III

All:

I have been experiencing the same issues described in this thread: trying to create an attribute expression that calculates lat/long coordinates from a hosted feature layer, then integrate Field Maps with Survey123 to open a form and have the geopoint plot the submitted survey on top of the feature using the result of the attribute expression using a custom URL via the custom URL popup (&center=).

I have been using the "Expression/expr2 - Code to calculate geometry" formula called out in this post (and a multitude of others on the community page) and it was correctly calculating the coordinates in ArcGIS Online Web Viewer Classic, but then when we tested this functionality in the field, the point was not mapping.

I found that the original formula in the "Expression/expr2 - Code to calculate geometry" results in an Array data type, with associated brackets. These brackets do not show up in ArcGIS Online, but when you view the popup in Field Maps, you can see the brackets. So because of this, i tested further and in the original function, i removed the brackets in the result line, which worked but was not perfect. It was not perfect because the coordinate results ended up being truncated to 2 decimals, and even though the submitted form was executing, the point was being plotted hundred of feet away.

After 10 hours of testing and researching these threads (which by the way, all of the contributions are EXPONENTIALLY HELPFUL AND I AM SO GRATEFUL OF YOUR KNOWLEDGE) i was able to find the CORRECT SOLUTION:

1.) Create an attribute expression for latitude:

var lat;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lat = number(Geometry($feature).y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lat;

2.) Create an attribute expression for longitude:

var lon;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lon = number(Geometry($feature).x / originShift) * 180.0;
return lon;

3.) Because of the "number" identifier, In ArcGIS Online Web Map Viewer Classic go to Configure Popups, make sure your pop up display is custom, then the important step is to click Configure Attributes. Navigate to the newly created expressions and expand the decimal places to a minimum of 5.

4.) Lastly, in the custom URL make the "&center={expression/expr3},{expression/expr4} where expr 3 is Lat and expr 4 is Long.

I have been testing since i discovered this and it has been running smoothly. Happy Mapping!

OscarGaleas
New Contributor II

hello were you able to get a solution to your question? I'm having the same trouble with a project of mine i was wondering if you or anyone here could help out. 

 

https://survey123.arcgis.com/share/a7ed8daa7bd64a3399504972d6a545cb?field:cb_id={GIS_ID}&field:cb_ad... 

 

here is my current link... i am retrieving the lat and long data from a online map of catch basins and populating the respective fields in survey123 "cb_lat" and "cb_long" and pulling that data into the geopoint question in s123 using formula below:

pulldata("@geopoint", ${cb_lat}, ${cb_long})

 

 

So far its auto-populating the fields correctly but i cant get the map to pull up in the right spot even with the coordinates being pushed through. Any advice or help is much appreciated.

0 Kudos