-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (50 loc) · 1.77 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Mapbox Raster Tileset Viewer</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link href='https://unpkg.com/[email protected]/dist/leaflet.css' rel='stylesheet' />
<script src='https://unpkg.com/[email protected]/dist/leaflet.js'></script>
<script src='https://d3js.org/d3.v4.min.js'></script>
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
var map = L.map('map', {
maxZoom: 22
});
L.tileLayer('https://{s}.tiles.mapbox.com/v4/{tileset}/{z}/{x}/{y}.png?access_token={access_token}', {
tileset: getParam('tileset'),
access_token: getParam('access_token'),
maxZoom: 22
}).addTo(map);
var loc = getParam('location');
if (loc) {
var locHash = loc.split("/");
if (locHash.length == 3) {
var zoom = parseInt(locHash[0], 10),
lat = parseFloat(locHash[1]),
lon = parseFloat(locHash[2]);
if (!(isNaN(zoom) || isNaN(lat) || isNaN(lon))) {
map.setView(new L.LatLng(lat, lon), zoom);
}
}
} else {
d3.json('https://api.mapbox.com/v4/' + getParam('tileset') + '.json?access_token=' + getParam('access_token'), function (tilejson) {
map.fitBounds([[tilejson.bounds[1], tilejson.bounds[0]], [tilejson.bounds[3], tilejson.bounds[2]]], {
maxZoom: tilejson.maxzoom
});
});
}
function getParam(name) {
var match = RegExp('[#&]' + name + '=([^&]*)').exec(window.location.hash);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
</script>
</body>
</html>