From ecf142a7f105471eaf1da421ff1bf55881e6b493 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 23 Oct 2022 11:50:54 +0200 Subject: initial commit --- script.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 script.js (limited to 'script.js') diff --git a/script.js b/script.js new file mode 100644 index 0000000..5f07efb --- /dev/null +++ b/script.js @@ -0,0 +1,61 @@ +const fragment = location.hash.substring(1); + +const i = fragment.indexOf('&'); +let latlon; +let params; +if (i != -1) { + latlon = fragment.slice(0, i); + params = Object.fromEntries(new URLSearchParams(fragment.slice(i+1)).entries()); +} else { + latlon = fragment; + params = {}; +} + +const [lat, lon] = latlon.split(','); + +function getLinks(lat, lon, zoom) { + return [ + { + label: 'Google Maps', + url: `https://www.google.com/maps/search/?api=1&query=${lat},${lon}`, + }, + { + label: 'Apple Maps', + url: `https://maps.apple.com/?q=${lat},${lon}&t=m` + }, + { + label: 'Default app', + url: `geo:${lat},${lon}` + }, + { + label: 'OpenStreetMap', + url: `https://www.openstreetmap.org/?mlat=${lat}&mlon=${lon}&zoom=${zoom}&layers=M` + }, + ] +} + +const heading = document.getElementById('heading'); + +// TODO: listen on hashChange + +if (isNaN(lat) || isNaN(lon)) { + heading.textContent = 'not yet implemented'; +} else { + const zoom = params.z || 15; + const linkList = document.getElementById('links'); + document.getElementById('instructions').hidden = false; + + if (params.name) { + document.title = params.name; + heading.textContent = params.name; + } + + for (const link of getLinks(lat, lon, zoom)) { + const li = document.createElement('li'); + const a = document.createElement('a'); + a.href = link.url; + a.textContent = link.label; + li.appendChild(a); + linkList.appendChild(li); + } +} -- cgit v1.2.3