forked from socrse/rse-groups
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rse-groups.js
53 lines (47 loc) · 1.51 KB
/
rse-groups.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
48
49
50
51
52
53
/*
* SPDX-FileCopyrightText: © 2022 Matt Williams <matt@milliams.com>
* SPDX-License-Identifier: MIT
*/
async function create_map(div) {
var map = L.map(div).setView([20, 0.], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
maxZoom: 18,
}).addTo(map);
const requestURL = 'groups.json';
const request = new Request(requestURL);
const response = await fetch(request);
const rse_groups = await response.json();
populateMap(map, rse_groups);
}
var headers = {
"head" : "Head of RSE",
"phone" : "Contact number",
"email" : "Contact email",
"postcode" : "Location",
"website" : "Website",
"twitter" : "Twitter Handle"
}
function onEachFeature(feature, layer) {
// does this feature have a property named popupContent?
if (feature.properties) {
var html = [];
html.push(`<b>${feature.properties["name"]}</b><br>\n`)
html.push("<dl>")
for (const header in headers) {
if (feature.properties[header]) {
html.push(`<dt>${headers[header]}</dt>`)
html.push(`<dd>${feature.properties[header]}</dd>`)
}
}
html.push("</dl>")
layer.bindPopup(html.join("\n"));
}
}
function populateMap(map, data) {
for (const group of data) {
L.geoJSON(group, {
onEachFeature: onEachFeature
}).addTo(map);
}
}