This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
/
leaflet-basic.html
64 lines (59 loc) · 1.54 KB
/
leaflet-basic.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
<!DOCTYPE html>
<html>
<head>
<title>hashable</title>
<meta charset="utf-8">
<script src="../hashable.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="http://maps.stamen.com/js/tile.stamen.js"></script>
<style>
#state {
width: 20em;
height: 10em;
}
#map {
height: 500px;
}
</style>
</head>
<body>
<div id="map"></div>
<ul>
<li><a href="#11/37.7691/-122.4399">San Francisco</a></li>
<li><a href="#13/37.8068/-122.2653">Oakland</a></li>
<li><a href="#13/51.505/-0.09">London</a></li>
</ul>
</body>
<script>
var map = L.map("map")
.setView([37.7691, -122.4399], 11)
.addLayer(new L.StamenTileLayer("toner"));
var hash = hashable.hash()
.format(hashable.format.map())
.change(function(e) {
var data = e.data;
console.log("moving to:", data);
map.setView([data.y, data.x], data.z);
})
.default(function() {
return {
z: map.getZoom(),
x: map.getCenter().lng,
y: map.getCenter().lat
};
})
.enable()
.check();
map
.on("moveend", function() {
var center = map.getCenter();
hash.update({x: center.lng, y: center.lat})
.write();
})
.on("zoomend", function() {
hash.update({z: map.getZoom()})
.write();
});
</script>
</html>