summaryrefslogtreecommitdiff
path: root/demo5.html
blob: d4f5f05eb9cf9b2d06b4e14508c3ddfadd1853a6 (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
<html>
  <head>
    <link rel="stylesheet" href="leaflet/dist/leaflet.css" />
    <script src="leaflet/dist/leaflet-src.js"></script>

    <style>
        body {
          padding: 0;
          margin: 0;
        }

        html, body, #map {
          height: 100%;
        }
    </style>
  </head>
  <body>
    <div id="map">
    </div>

    <script>
      var artHouseCafe = [50.9087036, -1.4045204];

      var map = L.map('map', {
          center: artHouseCafe, // The Art House Cafe
          zoom: 18
      });

      var tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
         attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
      });

      tileLayer.addTo(map);

      // Load some GeoJSON exported from OpenStreetMap using the OverpassAPI
      // (http://overpass-turbo.eu/s/7yI)

      var url = "cafes.json";

      if (document.URL.indexOf("file") === 0) {
        url = "http://cbaines.net/maptime/cafes.json";
      }

      getJSON(url, function(cafes) {

        L.geoJson(cafes).addTo(map);
      });

      // function to get a JSON file
      function getJSON(url, callback) {
        var xhttp = new XMLHttpRequest();

        xhttp.open('GET', url, true);
        xhttp.setRequestHeader('Accept', 'application/json');

        xhttp.onreadystatechange = function() {
          if (xhttp.status == 200 &&
              xhttp.readyState == 4) {

            callback(JSON.parse(xhttp.responseText), xhttp.responseText);
          }
        };

        xhttp.send();
      }

    </script>
  </body>
</html>