Skip to content

Instantly share code, notes, and snippets.

@talllguy
Last active April 3, 2023 10:08
Show Gist options
  • Save talllguy/904e4a94574211b23d58c25f8b535b35 to your computer and use it in GitHub Desktop.
Save talllguy/904e4a94574211b23d58c25f8b535b35 to your computer and use it in GitHub Desktop.
Arcade Expression to generate an OpenStreetMap URL wherever a point is located in an ArcGIS
// =================================================================== //
// Arcade OpenStreetMap Point URL //
// by Elliott Plack ([email protected]) //
// Description: //
// ArcGIS Arcade expression that returns an OpenStreetMap URL //
// at a point's location. Add it to the point layer's attributes and //
// then reference the link as a URL in the popup. //
// =================================================================== //
function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
// Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
// Source: https://community.esri.com/thread/222695-latlong-unit-conversion-with-arcade#comment-806053
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 CreateOSMURL(lat, lon) {
return "https://www.openstreetmap.org/?mlat=" + lat + "&mlon=" + lon + "#map=17/" + lat + "/" + lon
}
var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateOSMURL(latlon[0], latlon[1]);
return url;
<a href="{expression/expr1}" rel="nofollow ugc noopener noreferrer" target="_blank">Open in OpenStreetMap</a>
@ohtonygren
Copy link

Hi, is there any way to make this work from EPSG: 3067 to Google Maps? Right now it directs me to The Netherlands instead of Helsinki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment