-
Notifications
You must be signed in to change notification settings - Fork 46
/
bbox.html
81 lines (80 loc) · 2.92 KB
/
bbox.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
<!DOCTYPE html>
<html>
<head>
<title>Show Me The Way</title>
<meta charset='utf-8' />
<link rel='stylesheet' href='//unpkg.com/leaflet@1.8.0/dist/leaflet.css' />
<link rel='stylesheet' href='css/style.css' />
<link rel='stylesheet' href='css/site.css' />
<link rel='stylesheet' href='js/locationfilter/src/locationfilter.css' />
<style>
#bbox {
position:absolute;
bottom:0;
left:0;
font-size:40px;
font-family:monospace;
right:0;
background:#fff;
color:#000;
border:0;
margin:0;
z-index: 500;
}
</style>
</head>
<body>
<div class='container'>
<div id='map' class='col12 full-height'></div>
<a id='bbox'></a>
</div>
<script src='//unpkg.com/leaflet@1.8.0/dist/leaflet.js'></script>
<script src='js/locationfilter/src/locationfilter.js'></script>
<script>
//<![CDATA[
function updateLink(bounds, hashParams) {
const bs =
bounds.getSouthWest().lat.toFixed(5) + ',' +
bounds.getSouthWest().lng.toFixed(5) + ',' +
bounds.getNorthEast().lat.toFixed(5) + ',' +
bounds.getNorthEast().lng.toFixed(5);
hashParams.set('bounds', bs);
var loc = new URL(location.href.replace('bbox.html', '').replace('bbox', ''));
loc.hash = hashParams;
document.getElementById('bbox').textContent = loc;
document.getElementById('bbox').setAttribute('href', loc);
}
const hashParams = new URLSearchParams(location.hash.replace('#', ''));
var map = L.map('map');
const mapboxKey = 'pk.eyJ1Ijoib3BlbnN0cmVldG1hcHVzIiwiYSI6ImNqdTM1ZWxqeTBqa2MzeXBhODIxdnE2eG8ifQ.zyhAo181muDzPRdyYsqLGw';
var osm = new L.TileLayer(
'https://api.mapbox.com/styles/v1/openstreetmapus/{style_id}/tiles/256/{z}/{x}/{y}?access_token={key}', {
style_id: 'cju35gljt1bpm1fp2z93dlyca',
key: mapboxKey,
attribution: '<a href="https://mapbox.com/about/maps/">Terms & Conditions</a>'}).addTo(map);
map.setView([0, 0], 3);
var locationFilter = new L.LocationFilter().addTo(map);
const hashBounds = hashParams.get('bounds');
if (hashBounds) {
const boundsParts = hashBounds.split(',');
if (boundsParts.length === 4) {
const providedBounds = L.latLngBounds(
[ boundsParts[0], boundsParts[1] ],
[ boundsParts[2], boundsParts[3] ],
);
locationFilter.setBounds(providedBounds);
map.fitBounds(providedBounds);
updateLink(providedBounds, hashParams);
}
}
locationFilter.on("change", function (e) {
console.log(e.bounds);
// Do something when the bounds change.
// Bounds are available in `e.bounds`.
updateLink(e.bounds, hashParams);
});
locationFilter.enable();
//]]>
</script>
</body>
</html>