diff --git a/index.html b/index.html index 3c0d6cc..04fad7f 100644 --- a/index.html +++ b/index.html @@ -221,6 +221,12 @@ } }); + // Check for coordinates in hash + parseWindowHash(); + window.addEventListener('hashchange', function () { + parseWindowHash(); + }, false); + $("body").on("click", ".copyonclick", function () { var copyitem = $(this); var copytext = copyitem.text(); @@ -276,6 +282,20 @@ alert(e); } } + + function parseWindowHash() { + var hash = window.location.hash.substr(1); + if (/^-?[0-9]{1,2}\.?[0-9]*,-?[0-9]{1,3}\.?[0-9]*$/.test(hash)) { + var lat = hash.split(",")[0]; + var lon = hash.split(",")[1]; + lat = (Math.round(lat * 10000) / 10000); + lon = (Math.round(lon * 10000) / 10000); + lookupAndShowCoords(lat, lon); + setTimeout(function () { + window.location.hash = hash; + }, 1000); + } + } diff --git a/js/map.js b/js/map.js index 18331a4..6349f1f 100644 --- a/js/map.js +++ b/js/map.js @@ -100,6 +100,7 @@ function showLocationPopup(latitude, longitude, words, accuracy) { latitude + (accuracy / 2), longitude + (accuracy / 2) ); + window.location.hash = latitude + "," + longitude; } function drawRectangle(fromlat, fromlng, tolat, tolng) { @@ -143,4 +144,18 @@ function clearRectangle() { if (typeof map.getLayer("rectangle") != "undefined") { map.removeLayer('rectangle'); } +} + +function lookupAndShowCoords(latitude, longitude) { + var words = FixPhrase.encode(latitude, longitude); + + map.flyTo({ + center: { + lat: latitude, + lng: longitude + }, + zoom: Math.max(map.getZoom(), 14) + }); + + showLocationPopup(latitude, longitude, words, 0.0001); } \ No newline at end of file diff --git a/js/map_maplibre.js b/js/map_maplibre.js index a943317..6083b87 100644 --- a/js/map_maplibre.js +++ b/js/map_maplibre.js @@ -28,17 +28,7 @@ function maplibreMap() { try { var latitude = (Math.round(coordinates.lat * 10000) / 10000); var longitude = (Math.round(coordinates.lng * 10000) / 10000); - var words = FixPhrase.encode(latitude, longitude); - - map.flyTo({ - center: { - lat: latitude, - lng: longitude - }, - zoom: Math.max(map.getZoom(), 14) - }); - - showLocationPopup(latitude, longitude, words, 0.0001); + lookupAndShowCoords(latitude, longitude); } catch (e) { alert(e); }