summaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-10-23 11:50:54 +0200
committerMartin Fischer <martin@push-f.com>2022-10-23 11:58:44 +0200
commitecf142a7f105471eaf1da421ff1bf55881e6b493 (patch)
treea3b508031b1546181e27b7c7df1a256ba472e9ad /script.js
initial commit
Diffstat (limited to 'script.js')
-rw-r--r--script.js61
1 files changed, 61 insertions, 0 deletions
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);
+ }
+}