-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
74 lines (69 loc) · 2.92 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<html>
<head>
<title>PMTiles MapLibre Example</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" crossorigin="anonymous">
<script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/pmtiles@3.1.0/dist/pmtiles.js"></script>
<style>
body {
margin: 0;
}
#map {
height:100%; width:100%;
}
#overlay {
position: absolute;
top: 1rem;
left: 1rem;
font: 600 16px sans-serif;
background-color: white;
border-radius: 4px;
padding: 0.5rem;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="overlay">
<script type="text/javascript">
// add the PMTiles plugin to the maplibregl global.
let protocol = new pmtiles.Protocol();
maplibregl.addProtocol("pmtiles",protocol.tile);
let URL = "https://tile.openstreetmap.jp/static/planet.pmtiles"
const styleUrl = "https://tile.openstreetmap.jp/styles/osm-bright/style.json"
function formatBytes(a,b=2){if(!+a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return`${parseFloat((a/Math.pow(1024,d)).toFixed(c))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}`}
fetch(URL, {method:"HEAD"}).then(resp => {
let length = resp.headers.get("Content-Length");
document.getElementById("overlay").innerHTML = `<a href="${URL}">${URL}</a> (${formatBytes(length)})`;
})
let style;
fetch(styleUrl).then(resp => resp.json()).then(data => {
style = data
console.log(data)
style['sources']['openmaptiles'] = {
type: "vector",
url: "pmtiles://" + URL,
attribution: 'Protomaps © <a href="https://openstreetmap.org">OpenStreetMap</a>',
}
const map = new maplibregl.Map({
maxZoom: 19,
container: 'map',
style: style,
hash: true
})
const nav = new maplibregl.NavigationControl()
map.addControl(nav, 'top-right')
const geolocation = new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
})
map.addControl(geolocation, 'top-right')
const scale = new maplibregl.ScaleControl()
map.addControl(scale, 'bottom-left')
})
</script>
</body>
</html>