Skip to content

Instantly share code, notes, and snippets.

@Tofull
Created July 23, 2021 15:19
Show Gist options
  • Save Tofull/0ae964f7c9ac0161a5aed6c456db8de0 to your computer and use it in GitHub Desktop.
Save Tofull/0ae964f7c9ac0161a5aed6c456db8de0 to your computer and use it in GitHub Desktop.
Tutoriel Pin to Jakartowns
// Inspired from : https://github.com/Esri/arcade-expressions/blob/master/popup/url-withlocation.md
// Options are "Jakarto", "Google Directions", "Google Panoramic", and "Google Pin"
var EndGoal = "Jakarto"
var BaseUrl = Decode( EndGoal,
"Jakarto", "https://maps.jakarto.com/?lat=${LATITUDE}&lng=${LONGITUDE}",
"Google Directions", "https://www.google.com/maps/dir/?api=1&origin=Current+Location&destination=${LATITUDE},${LONGITUDE}",
"Google Panoramic", "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${LATITUDE},${LONGITUDE}",
"Google Pin", "https://maps.google.com/maps?t=k&q=loc:${LATITUDE},${LONGITUDE}",
"Invalid"
);
if (BaseUrl == "Invalid"){
Console(EndGoal + " is an invalid value for EndGoal.");
}
// Convert Lines/Polygons to Points
var PointGeometry = Centroid(Geometry($feature));
var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;
function AuxSphereToLatLon(x, y) {
Console("Converting...");
// Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
var rMajor = 6378137;
var shift = PI * rMajor;
Longitude = x / shift * 180.0;
Latitude = y / shift * 180.0;
Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}
if (ArcadeSr == 4326) {
Console("4326 Spatial Reference - No Conversion Necessary");
Latitude = ArcadeY;
Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
Console("102100 Spatial Reference - Conversion Necessary");
AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}
//Build Url Link
function BuildLink(Url, Lat, Long) {
Url = Replace(Url, '${LATITUDE}', Lat);
Url = Replace(Url, '${LONGITUDE}', Long);
return Url;
}
BuildLink(BaseUrl, Latitude, Longitude);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment