HOW TO
As described in What’s New in Collector for ArcGIS 18.1.0, Arcade expressions are supported. An integrated Collector for ArcGIS and Survey123 for ArcGIS system connection has now the ability to build Survey123’s custom URL scheme using an Arcade expression. If a Collector for ArcGIS web map is based on an existing service, and it is necessary to populate a Survey123 survey using a different feature service, use the custom URL scheme and custom attribute pop-up to do this. For example:
arcgis-survey123://?itemID=<itemid>&field:AssetID={otherfeatid}
This populates the survey with the field 'AssetID' with 'otherfeatid' from the existing service. However, Survey123 for ArcGIS defaults to the current location, and not the point used in the Collector for ArcGIS map when Survey123 for ArcGIS is launched.
In previous versions, the only way to fix this was to hard code the Lat/Long into attributes for the existing service to be read for the custom URL scheme. However, with Arcade expressions, the geometry of a feature and the custom URL scheme for Survey123 for ArcGIS can be used to define the location of the geopoint in the survey.
To configure the web map pop-up to use an attribute expression, refer to Configure pop-ups. The following steps describe how to use Arcade expressions to define the location of the geopoint:
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]; }
function CreateURLSurvey(lat, lon) { var url_scheme = "arcgis-survey123://?itemID=<itemid>"; var url = url_scheme + "&field:AssetID={otherfeatid}";// Repeat this line as many times as required based on how many fields you want populated. For this example AssetID will be populated from otherfeatid var url = url + "¢er=" + lat + "," + lon;// This is the line that defines the location Console(url); return url; }
var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y); var url = CreateURLSurvey(latlon[0], latlon[1]); return url;
The following shows the full code:
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_scheme = "arcgis-survey123://?itemID=<itemid>"; var url = url_scheme + "&field:AssetID={otherfeatid}";// Repeat this line as many times as required based on how many fields you want populated. For this example AssetID will be populated from otherfeatid var url = url + "¢er=" + lat + "," + lon;// This is the line that defines the location Console(url); return url; } var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y); var url = CreateURLSurvey(latlon[0], latlon[1]); return url;
Article ID: 000020624
Get help from ArcGIS experts
Download the Esri Support App