-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmap.js
47 lines (40 loc) · 1.37 KB
/
map.js
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
function updateMap(map, mapData, filePrefix = "") {
var allMarkers = []
for (var markerData of mapData.markers) {
var icon = getMarkerIcon('blue')
if (markerData.hasOwnProperty('color')) {
icon = getMarkerIcon(markerData.color)
}
var marker = L.marker(markerData.point, {icon})
if (markerData.hasOwnProperty('text')) {
marker.bindPopup(markerData.text)
}
marker.addTo(map)
allMarkers.push(markerData.point)
}
for (var polygonData of mapData.polygons) {
console.log(polygonData)
var color = 'blue'
if (polygonData.hasOwnProperty('color')) {
color = polygonData.color
}
var polygon = L.polygon(polygonData.points, {color})
if (polygonData.hasOwnProperty('text')) {
polygon.bindPopup(polygonData.text)
}
polygon.addTo(map)
allMarkers = allMarkers.concat(polygonData.points)
}
map.fitBounds(allMarkers)
function getMarkerIcon(color) {
return L.icon({
iconRetinaUrl: filePrefix + 'assets/markers/marker-icon-2x-' + color + '.png',
iconUrl: filePrefix + 'assets/markers/marker-icon-' + color + '.png',
shadowUrl: filePrefix + 'assets/markers/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
})
}
}