want to launch Trek2There from popup, but getting "Unexpected token ILLEGAL" error

994
6
07-03-2019 02:59 PM
LynnBerni
Occasional Contributor II

Following the instructions in Get To The Point on Your Map (ArcGIS Blog, 2017), I would like to configure a popup with a custom expression that launches Trek2There from my map (on an ipad):

[from the blog]
5. Within the expression, delete any existing sample text, and paste in the below expression.

    • For Trek2There:  “arcgis-trek2there://?stop=”+ Geometry($feature).y + “,” + Geometry($feature).x


When I paste the above expression, I get this error in the arcade window:

   Parse Error:Line 1: Unexpected token ILLEGAL

Is it still possible to launch Trek2There with a custom expression?

Thanks,

Lynn 

6 Replies
XanderBakker
Esri Esteemed Contributor

Hi LBerni@slco.org_slco ,

When you define the Arcade expression and test it, what URL is returned? Can you provide an example? In case your map does not have WGS 1984 geographic coordinates, you will have to convert the coordinates in the expression first.  This can be done, but I will recognize if it is necessary when I see an example URL.

LynnBerni
Occasional Contributor II

No URL is returned when I click the "Test" button, just the error (see screenshot).

Not sure if my basemap is WGS 1984.

XanderBakker
Esri Esteemed Contributor

Hi Lynn Berni ;

It was a bit difficult to see, but this seems to be a classical case of using the wrong character for quotes (as if the code was written in Word which converts it). Could you copy the line below and try again?

"arcgis-trek2there://?stop=" + Geometry($feature).x + "," + Geometry($feature).x
0 Kudos
LynnBerni
Occasional Contributor II

Woohoo, it worked!  That'll teach me to copy/paste from a blog post.

When I test the expression i get: 

arcgis-trek2there://?stop=-12456784.157737207,-12456784.157737207

But I'm not really sure what to do next. I've added the above link to the custom attributes in my popup, and it launches the Trek2There app, but T2T says "no destination set".  Is this related to the WGS 1984 issue?   

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Lynn Berni ,

That is correct (apart from the fact that I also made a mistake in my expression by specifying the x-coordinate twice).

You will have to provide your coordinates in WGS 1984 geographic coordinate as decimal degrees.

Have a look at the explanation here:

https://www.esri.com/arcgis-blog/products/apps/announcements/introducing-trek2there-by-esri-labs/

As I mentioned before this is possible, but the expression becomes a little more complex. Copy the following code and have a try:

function MetersToLatLon(x, y) {
    // 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 = (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 CreateTrack2ThereURL(lat, lon) {
    return "arcgis-trek2there://?stop=" + lat + "," + lon;
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateTrack2ThereURL(latlon[0], latlon[1]);
return url;
ZacharyHart
Occasional Contributor III

Xander Bakker‌,

This is pretty clever! When I test the expression i get the desired URL. However, in Collector Beta, the custom expression simply appears as a string...not a URL you can click on to launch the app. What am I missing here? [Latest version of Collector Beta for Android].

I am able to get a basic test pop-up 'working' for old Collector using a 'custom attribute display' (like the earlier blog posts show), but this obviously doesn't have the Arcade functionality and you need to have a pre-attributed X&Y field. I don't believe that old Collector/Collector classic supports the Arcade expressions.

Trek 2 There Popup

0 Kudos