-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.html
101 lines (101 loc) · 3 KB
/
demo.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>TMS Demo</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
font-size: 15px;
line-height: 1.25em;
}
a {
color: #425e5e;
padding: .25em;
}
a:visited {
color: #233;
}
a:hover, a:focus {
color: #4e7a7a;
}
section {
background-color: white;
word-wrap: break-word;
box-sizing: border-box;
transition: all .1s;
}
p {
margin: .5em 0;
}
#container {
height: 100%;
width: auto;
}
#agent {
width: 250px;
height: 100%;
float: left;
padding: 15px 20px;
overflow-y: auto;
}
#mapwrap, #map {
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.3/leaflet.css" integrity="sha512-mD70nAW2ThLsWH0zif8JPbfraZ8hbCtjQ+5RU1m4+ztZq6/MymyZeB55pWsi4YAX+73yvcaJyk61mzfYMvtm9w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.3/leaflet.js" integrity="sha512-Dqm3h1Y4qiHUjbhxTuBGQsza0Tfppn53SHlu/uj1f+RT+xfShfe7r6czRf5r2NmllO2aKx+tYJgoxboOkn1Scg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
'use strict';
document.addEventListener('DOMContentLoaded', function() {
var layers_attr = {{layers}};
document.getElementById('map').innerHTML = "";
var zoom = 3, lat = 39.9276, lng = 116.3789;
if (window.location.hash) {
var h = window.location.hash.substring(1).split('/');
var z = parseInt(h[0], 10), l1 = parseFloat(h[1]), l2 = parseFloat(h[2]);
if (!(isNaN(z) || isNaN(l1) || isNaN(l2))) {
zoom = z; lat = l1; lng = l2;
}
}
var map = L.map('map', {center: [lat, lng], zoom: zoom});
var layers_base = {}, layers_overlay = {};
var i = 0;
for (i = 0; i < layers_attr[0].length; i++) {
var obj = layers_attr[0][i];
layers_base[obj['name']] = L.tileLayer(obj['url'],
{id: obj['id'], attribution: obj['attribution'], maxZoom: 18, minZoom: 3});
if (i == 0) layers_base[obj['name']].addTo(map);
}
for (i = 0; i < layers_attr[1].length; i++) {
var obj = layers_attr[1][i];
layers_overlay[obj['name']] = L.tileLayer(obj['url'],
{id: obj['id'], attribution: obj['attribution'], maxZoom: 18, minZoom: 3});
}
L.control.layers(layers_base, layers_overlay).addTo(map);
function setHash() {
var a = map.getCenter(), z = map.getZoom();
var i = Math.max(0, Math.ceil(Math.log(z) / Math.LN2));
history.replaceState(undefined, undefined,
"#" + z + "/" + a.lat.toFixed(i) + "/" + a.lng.toFixed(i));
}
map.on('zoomend', setHash);
map.on('moveend', setHash);
});
</script>
</head>