-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (113 loc) · 3.8 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
<!DOCTYPE html>
<html>
<head>
<title>OpenStreetMap Notes</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Leaflet CSS -->
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
/>
<!-- Leaflet JavaScript -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
let map = L.map('map').setView([52.3851, 4.6306], 12)
let markers = {
red:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
blue:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png',
green:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
orange:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-orange.png',
yellow:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-yellow.png',
black:
'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-black.png',
}
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution:
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
maxZoom: 18,
}).addTo(map)
const colors = {
ONTWERP: markers.orange,
VOORBEREIDING: markers.yellow,
UITVOERING: markers.green,
FUTURE: markers.blue,
}
function fetchNotes() {
let bounds = map.getBounds()
let bbox = bounds.toBBoxString()
map.eachLayer((layer) => {
if (layer instanceof L.Marker) {
if (!bounds.contains(layer.getLatLng())) {
map.removeLayer(layer)
}
}
})
fetch(`https://www.openstreetmap.org/api/0.6/notes.json?bbox=${bbox}`)
.then((response) => response.json())
.then((data) => {
data.features.forEach((feature) => {
if (feature.properties.status === 'closed') {
return
}
let colorFound = null
// get key value pair from colors
for (const [key, value] of Object.entries(colors)) {
if (
feature.properties.comments[0].text
.toLowerCase()
.includes(key.toLowerCase())
) {
colorFound = value
break
}
}
if (!colorFound) {
colorFound = markers.black
}
let marker = L.marker(
[
feature.geometry.coordinates[1],
feature.geometry.coordinates[0],
],
{
icon: L.icon({
iconUrl: colorFound,
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41],
}),
},
)
.bindPopup(
`<b>${feature.properties.comments[0].text}</b><br><a href="https://www.openstreetmap.org/note/${feature.properties.id}">View on OpenStreetMap</a>`,
)
.addTo(map)
})
})
.catch((error) => console.error(error))
}
map.on('load', fetchNotes)
map.on('moveend zoomend', fetchNotes)
</script>
</body>
</html>