-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmapbox.html
More file actions
99 lines (93 loc) · 2.54 KB
/
mapbox.html
File metadata and controls
99 lines (93 loc) · 2.54 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Add a vector tile source</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.1/mapbox-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.1/mapbox-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
mapboxgl.accessToken =
'<your access token here>';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
zoom: 7,
center: [3.4, 52.2],
});
map.on('load', function() {
// Change the source to filter
map.addSource('points', {
type: 'vector',
tiles: ['http://localhost:3005/points/{z}/{x}/{y}/tile.mvt'],
});
map.addLayer({
id: 'clusters',
type: 'circle',
source: 'points',
'source-layer': 'points',
interactive: true,
filter: ['>', ['get', 'count'], 1],
paint: {
'circle-radius': 20
}
});
map.addLayer({
id: 'cluster_count',
type: 'symbol',
source: 'points',
'source-layer': `points`,
interactive: true,
filter: ['>', ['get', 'count'], 1],
layout: {
'text-field': ['get', 'count'],
'text-size': 12,
},
paint: {
'text-color': '#ffffff',
},
});
map.addLayer({
id: 'unclustered-point',
type: 'circle',
source: 'points',
'source-layer': `points`,
filter: ['==', ['get', 'count'], 1],
paint: {
'circle-color': '#11b4da',
'circle-radius': 4,
'circle-stroke-width': 1,
'circle-stroke-color': '#fff',
},
});
map.on('click', function({ point, target }) {
const features = target.queryRenderedFeatures(point, { layers: ['clusters', 'cluster_count', 'unclustered-point']});
if (features && features.length > 0) {
map.flyTo({center: [features[0].properties.lng, features[0].properties.lat]})
}
});
});
</script>
</body>
</html>