summaryrefslogtreecommitdiff
path: root/assets/ilztal.live/geolocation/view.html
blob: 58b4c765bb39dc8a297da65e7a58b466909a186e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!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:60vh; 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/current")
                 .then((data) => {
                     let text = data.text().then(text => {
                         let pos = JSON.parse(text);
                         console.log(pos)
                         updateMap(pos.pos);
                     });

                     setTimeout(fetchUpdate, 3000);
                 })
                 .catch((e) => {
                     console.log("some error!", e);
                     setTimeout(fetchUpdate, 3000);
                 })
         }

         fetchUpdate()
        </script>

    </body>
</html>