summaryrefslogtreecommitdiff
path: root/assets/ilztal.live/geolocation/mapview.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assets/ilztal.live/geolocation/mapview.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/assets/ilztal.live/geolocation/mapview.html b/assets/ilztal.live/geolocation/mapview.html
new file mode 100644
index 0000000..bb62f62
--- /dev/null
+++ b/assets/ilztal.live/geolocation/mapview.html
@@ -0,0 +1,94 @@
+<!doctype html>
+<html class="no-js" lang="">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="x-ua-compatible" content="ie=edge">
+ <title>Position view</title>
+ <meta name="description" content="">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png">
+ <!-- Place favicon.ico in the root directory -->
+
+ <link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
+ integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
+ crossorigin=""/>
+ <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
+ integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
+ crossorigin=""></script>
+
+ </head>
+ <body>
+ <!--[if lt IE 8]>
+ <p class="browserupgrade">
+ You are using an <strong>outdated</strong> browser. Please
+ <a href="http://browsehappy.com/">upgrade your browser</a> to improve
+ your experience.
+ </p>
+ <![endif]-->
+
+ <div align="justify">
+ <div id="MapID2" style="height:100vh; margin-left: auto; margin-right:auto; width:80%"></div>
+ </div>
+ <script>
+ var mymap = L.map('MapID2');
+ L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoiZmVsaXg4MTgyOTMiLCJhIjoiY2p6a2h6cjdyMGpicjNvbzlzZ3UwNmloMCJ9.a4t1KM9Gid-q29ultM7HgA', {
+ attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
+ maxZoom: 18,
+ id: 'mapbox/streets-v11',
+ accessToken: 'pk.eyJ1IjoiZmVsaXg4MTgyOTMiLCJhIjoiY2p6a2h6cjdyMGpicjNvbzlzZ3UwNmloMCJ9.a4t1KM9Gid-q29ultM7HgA'
+ }).addTo(mymap);
+ var marker = L.marker([0,0]).addTo(mymap);
+ marker.bindPopup("Hello Train!");
+
+ mymap.setView([0,0], 16);
+ function updateMap(pos) {
+ if (pos === null) {
+ console.log("no data yet?");
+ return;
+ }
+ mymap.setView(pos);
+ mymap.scrollWheelZoom.disable();
+ marker.setLatLng(pos);
+ }
+ updateMap([48.13716,11.57540]);
+
+ function fetchUpdate () {
+ fetch("https://ilztal.live/geoloc/history")
+ .then((data) => {
+ let text = data.text().then(text => {
+ let hist = JSON.parse(text);
+ console.log(hist)
+
+ let latlngs = hist.filter(e => e.data.latitude !== undefined).map((e) => [e.data.latitude, e.data.longitude]);
+
+ console.log(latlngs);
+ let polyline = L.polyline(latlngs, {color: "red"}).addTo(mymap);
+
+ mymap.fitBounds(polyline.getBounds())
+
+ for (idx in hist) {
+ if (hist[idx].data.latitude === undefined) {
+ console.log(hist[idx].data, idx, 1+parseInt(idx))
+ let nidx = 1+parseInt(idx);
+ if (hist[nidx] !== undefined && hist[nidx].data.latitude !== undefined) {
+ let marker = L.marker([hist[nidx].data.latitude, hist[nidx].data.longitude])
+ .addTo(mymap);
+ marker.bindPopup(hist[idx].data);
+ }
+ }
+ }
+ });
+
+ })
+ .catch((e) => {
+ console.log("some error!", e);
+ setTimeout(fetchUpdate, 3000);
+ })
+ }
+
+ fetchUpdate()
+ </script>
+
+ </body>
+</html>