-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.html
82 lines (78 loc) · 2.73 KB
/
map.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
82
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display buildings in 3D</title>
<meta property="og:description" content="Use extrusions to display buildings' height in 3D." />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/[email protected]/dist/maplibre-gl.css' />
<script src='https://unpkg.com/[email protected]/dist/maplibre-gl.js'></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const MAPTILER_KEY = 'get_your_own_OpIi9ZULNHzrESv6T2vL';
const map = new maplibregl.Map({
style: `https://api.maptiler.com/maps/basic-v2/style.json?key=${MAPTILER_KEY}`,
center: [-89.40380931694997, 43.074425658918905],
zoom: 18.5,
pitch: 45,
bearing: -17.6,
container: 'map',
antialias: true
});
// The 'building' layer in the streets vector source contains building-height
// data from OpenStreetMap.
map.on('load', () => {
// Insert the layer beneath any symbol layer.
const layers = map.getStyle().layers;
let labelLayerId;
for (let i = 0; i < layers.length; i++) {
if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
labelLayerId = layers[i].id;
break;
}
}
map.addSource('openmaptiles', {
url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${MAPTILER_KEY}`,
type: 'vector',
});
map.addLayer(
{
'id': '3d-buildings',
'source': 'openmaptiles',
'source-layer': 'building',
'type': 'fill-extrusion',
'minzoom': 15,
'filter': ['!=', ['get', 'hide_3d'], true],
'paint': {
'fill-extrusion-color': [
'interpolate',
['linear'],
['get', 'render_height'], 0, 'lightgray', 200, 'royalblue', 400, 'lightblue'
],
'fill-extrusion-height': [
'interpolate',
['linear'],
['zoom'],
15,
0,
16,
['get', 'render_height']
],
'fill-extrusion-base': ['case',
['>=', ['get', 'zoom'], 16],
['get', 'render_min_height'], 0
]
}
},
labelLayerId
);
});
</script>
</body>
</html>