-
Notifications
You must be signed in to change notification settings - Fork 4
/
toggle-layers.html
160 lines (140 loc) · 4.35 KB
/
toggle-layers.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></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.13.2/mapbox-gl-dev.js'></script>
<!--script src='mapbox-gl-js-0.37.0/src/index.js'></script-->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.13.2/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#menu {
background: #fff;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
border-radius: 3px;
width: 120px;
border: 1px solid rgba(0,0,0,0.4);
font-family: 'Open Sans', sans-serif;
}
#menu a {
font-size: 13px;
color: #404040;
display: block;
margin: 0;
padding: 0;
padding: 10px;
text-decoration: none;
border-bottom: 1px solid rgba(0,0,0,0.25);
text-align: center;
}
#menu a:last-child {
border: none;
}
#menu a:hover {
background-color: #f8f8f8;
color: #404040;
}
#menu a.active {
background-color: #3887be;
color: #ffffff;
}
#menu a.active:hover {
background: #3074a4;
}
</style>
<nav id="menu"></nav>
<div id="map"></div>
<script>
//mapboxgl.accessToken = 'pk.eyJ1IjoiYW5uZWIiLCJhIjoiOVR1NFVoRSJ9.x0d9OLRZADt-GJaDqE0XPg';
var map = new mapboxgl.Map({
container: 'map',
style: 'styles/freetilehosting/ktbasic.json',
zoom: 6,
center: [-55, 4.9]
});
map.on('load', function () {
map.addSource('suriname villages', {
type: 'vector',
//url: 'mapbox://anneb.cj2oqrxsc00572wrp5r8p3pwp-3u7xc'
"tiles": [
//"http://saturnus.geodan.nl:9090/data/suriname_dorpen/z/x/y.pbf"
"https://tiles.edugis.nl/data/public.suriname_dorpen/mvt/{z}/{x}/{y}?geom_column=geom&columns=naam&include_nulls=0"
],
"bounds": [-57.4,2.0,-54.0,5.9]
});
map.addLayer({
'id': 'suriname villages',
'type': 'circle',
'source': 'suriname villages',
'layout': {
'visibility': 'visible'
},
'paint': {
'circle-radius': 8,
'circle-color': 'rgba(55,148,179,1)'
},
'source-layer': 'public.suriname_dorpen'
});
map.addSource('suriname districten', {
type: 'vector',
//url: 'mapbox://mapbox.mapbox-terrain-v2'
"tiles": [
"https://tiles.edugis.nl/data/public.suriname_districten/mvt/{z}/{x}/{y}?geom_column=geom&columns=district,bevolking&include_nulls=0"
],
"bounds": [-58.4,1.46,-54.0,6.0]
});
map.addLayer({
'id': 'suriname districten',
'type': 'line',
'source': 'suriname districten',
'source-layer': 'public.suriname_districten',
'layout': {
'visibility': 'visible',
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
//'line-color': '#877b59',
'line-color': '#cc5555',
'line-width': 2
}
});
});
var toggleableLayerIds = [ 'suriname districten', 'suriname villages' ];
for (var i = 0; i < toggleableLayerIds.length; i++) {
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = 'active';
link.textContent = id;
link.onclick = function (e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
if (visibility === 'visible') {
map.setLayoutProperty(clickedLayer, 'visibility', 'none');
this.className = '';
} else {
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
map.on('load', () => {
map.addControl(new mapboxgl.ScaleControl({position: 'bottom-left'}));
});
</script>
</body>
</html>