-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
28 lines (25 loc) · 872 Bytes
/
helpers.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
/**
* Converts the london_boroughs.geojson into an encoded version, saving a lot of data!
*/
function encodeBoroughs() {
let boroughs = [];
fetch('/data/london_boroughs.geojson')
.then(r => r.json())
.then(data => data.features.forEach(borough => {
const name = borough.properties.name;
const coordinates = borough.geometry.coordinates[0].map(p => [p[1], p[0]]);
const region = L.polygon(coordinates, {
color: 'black',
fillColor: '#000',
fillOpacity: 0
});
region.bindPopup(name);
region.addTo(mymap);
const line = L.polyline(coordinates).encodePath();
boroughs.push({
name: name,
region: line
})
}))
.then(() => console.log(boroughs));
}