-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
275 lines (239 loc) · 7.9 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html>
<!--Inspired by https://docs.mapbox.com/mapbox-gl-js/example/timeline-animation/ -->
<head>
<meta charset="utf-8">
<title>Erreichbarkeit Kitas KRZN Verbandsgebiet</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<style>
.map-overlay {
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
position: absolute;
width: 15%;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay h2 {
line-height: 24px;
display: block;
margin: 0 0 10px;
}
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
</style>
<script src="https://unpkg.com/@maplibre/[email protected]/dist/maplibre-gl-geocoder.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@maplibre/[email protected]/dist/maplibre-gl-geocoder.css"
type="text/css">
<div id="map"></div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<h2>Erreichbarkeit Kitas</h2>
<label id="intervall"></label>
<input id="slider" type="range" min="1" max="10" step="1" value="1" autocomplete="off">
</div>
</div>
<script>
var bbox = [
[5.918225, 51.11454],
[6.810864, 51.90785]
];
var map = new maplibregl.Map({
container: 'map',
style: 'https://sgx.geodatenzentrum.de/gdz_basemapde_vektor/styles/bm_web_gry.json',
bounds: bbox,
attributionControl: false
});
map.fitBounds(bbox, {
padding: 20
});
// https://maplibre.org/maplibre-gl-js-docs/example/geocoder/
var geocoder_api = {
forwardGeocode: async (config) => {
const features = [];
try {
let request =
'https://nominatim.openstreetmap.org/search?q=' +
config.query +
'&format=geojson&polygon_geojson=1&addressdetails=1';
const response = await fetch(request);
const geojson = await response.json();
for (let feature of geojson.features) {
let center = [
feature.bbox[0] +
(feature.bbox[2] - feature.bbox[0]) / 2,
feature.bbox[1] +
(feature.bbox[3] - feature.bbox[1]) / 2
];
let point = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: center
},
place_name: feature.properties.display_name,
properties: feature.properties,
text: feature.properties.display_name,
place_type: ['place'],
center: center
};
features.push(point);
}
} catch (e) {
console.error(`Failed to forwardGeocode with error: ${e}`);
}
return {
features: features
};
}
};
map.addControl(
new MaplibreGeocoder(geocoder_api, {
maplibregl: maplibregl
})
);
map.addControl(new maplibregl.NavigationControl());
map.addControl(new maplibregl.AttributionControl({
customAttribution: 'Kitas NRW © Land NRW <a href="https://www.govdata.de/dl-de/by-2-0" target="_blank" rel="noopener noreferrer">dl-de/by-2-0</a>'
}));
var minutes
map.on('click', 'isochronen', function (e) {
new maplibregl.Popup()
.setLngLat(e.lngLat)
.setHTML("Folgende Einrichtungen sind innerhalb von " + minutes + " Minute(n) zu Fuß erreichbar:<ul><li>" + e.features.map(function (feature) {
return feature.properties.name;
}).join('</li><li>') + "</li></ul>")
.addTo(map);
});
map.on('mouseenter', 'isochronen', () => {
map.getCanvas().style.cursor = 'pointer'
})
map.on('mouseleave', 'isochronen', () => {
map.getCanvas().style.cursor = ''
})
var intervalle = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function filterBy(intervall) {
var filters = ['==', 'AA_MINS', intervall];
map.setFilter('isochronen', filters);
document.getElementById('intervall').textContent = "Fußweg maximal " + intervalle[intervall] + " Minute(n)";
}
map.on('load', function () {
map.addSource('isochronen', {
'type': 'geojson',
'data': 'https://kreis-viersen.github.io/kita-erreichbarkeit/geojson/isochronen_verband.geojson',
'attribution': 'Isochronen generiert mit QGIS Plugin ORS Tools © openrouteservice.org by HeiGIT auf Basis von OSM-Daten © <a href="https://www.openstreetmap.org/copyright/" target="_blank" rel="noopener noreferrer">OpenStreetMap</a> contributors'
});
map.addLayer({
'id': 'isochronen',
'type': 'fill',
'source': 'isochronen',
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'AA_MINS'],
1,
'#2b83ba',
10,
'#d7191c'
],
'fill-opacity': 0.3
}
}, 'Gebaeude2D_alle');
map.addSource('kitas-nrw', {
'type': 'vector',
'tiles': [
'https://ogc-api.nrw.de/inspire-us-kindergarten/v1/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt'
],
'minzoom': 10,
'maxzoom': 18
});
map.addLayer(
{
'id': 'kitas-nrw',
'type': 'circle',
'source': 'kitas-nrw',
'source-layer': 'governmentalservice',
'paint': {
'circle-color': '#000080',
'circle-stroke-color': 'white',
'circle-stroke-width': 1.5
}
});
map.addSource('verbandsgrenze', {
type: 'geojson',
data: 'https://kreis-viersen.github.io/kita-erreichbarkeit/geojson/grenze_verband.geojson'
});
map.addLayer({
'id': 'verbandsgrenze',
'type': 'fill',
'source': 'verbandsgrenze',
'paint': {
'fill-color': 'white',
'fill-opacity': 0.7
}
});
filterBy(1);
document
.getElementById('slider')
.addEventListener('input', function (e) {
const popup = document.getElementsByClassName('maplibregl-popup');
if (popup.length) {
popup[0].remove();
}
var intervall = parseInt(e.target.value, 10);
filterBy(intervall);
minutes = intervall
});
var kita_info = new maplibregl.Popup({
closeButton: false,
closeOnClick: false
});
map.on('mouseenter', 'kitas-nrw', function (e) {
map.getCanvas().style.cursor = 'pointer';
var coordinates = e.features[0].geometry.coordinates;
feature = e.features[0].properties
var content = '<b>' + feature.name + '</b>'
+ '<br>' + feature["pointOfContact.address.thoroughfare"] + ' ' + feature["pointOfContact.address.locatorDesignator"]
+ '<br>' + feature["pointOfContact.address.postCode"] + ' ' + feature["pointOfContact.address.adminUnit"]
+ '<br><br>Telefon: ' + feature["pointOfContact.telephoneVoice"]
+ '<br>Art: ' + feature["serviceType.title"];
kita_info.setLngLat(coordinates).setHTML(content).addTo(map);
});
map.on('mouseleave', 'kitas-nrw', function () {
map.getCanvas().style.cursor = '';
kita_info.remove();
});
});
</script>
</body>
</html>