-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.html
70 lines (59 loc) · 1.55 KB
/
example.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
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-2fA79E27MOeBgLjmBrtAgM/20clVSV8vJERaW/EcnnWCVGwQRazzKtQS1kIusCZv1PtaQxosDZZ0F1Oastl55w=="
crossorigin=""></script>
<style>
.leaflet-container {
background-color: #000; }
#mapid {
height: 100%;
width: 100%;
border: 1px solid black }
</style>
</head>
<body>
<div id="mapid"></div>
<script>
var loadBoundary = function ()
{
var qs = window.location.search;
if (qs.length > 1) {
qs = qs.substring(1);
qs = qs.split(',');
}
if (qs.length === 3) {
qs[0] = Number.parseFloat(qs[0]);
qs[1] = Number.parseFloat(qs[1]);
qs[2] = Number.parseInt(qs[2]);
} else {
qs = [0, 0, 10] // Set default center and zoom here
}
return qs;
}
var saveBoundary = function ()
{
var center = mymap.getCenter();
var zoom = Number.parseFloat(mymap.getZoom()).toPrecision(1);
var url = '?' + center.lat.toPrecision(5) + ',' + center.lng.toPrecision(5) + ',' + zoom;
window.history.replaceState({}, '', url);
}
var b = loadBoundary();
console.log(b);
var mymap = L.map(
'mapid', {
crs: L.CRS.Simple,
maxZoom: 10,
minZoom: 1,
wheelPxPerZoomLevel: 500
}).setView([b[0], b[1]], b[2]);
mymap.on('moveend', function (e) {
saveBoundary();
});
L.tileLayer("{z}/{y}/{x}.jpg").addTo(mymap); // set relative path to your tiles here
</script>
</body>
</html>