forked from AGU-Data/open-ocean-science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (73 loc) · 2.78 KB
/
index.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
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
/* list of participants */
fetch('people.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
var mainContainer = document.getElementById("peopleData");
for (var i = 0; i < data.length; i++) {
var div = document.createElement("div");
div.innerHTML = data[i].name + ', ' + data[i].organization + ', ';
var link = document.createElement("a");
link.innerText = '@' + data[i].github;
link.href = 'https://github.com/' + data[i].github;
div.appendChild(link);
mainContainer.appendChild(div);
}
})
.catch(function (err) {
console.log('error: ' + err);
});
/* map */
var map = L.map('mapid', {dragging: !L.Browser.mobile}).setView([0, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
/* add places and organizations to map */
fetch('places.geojson')
.then(function (response) {
return response.json();
})
.then(function (data) {
L.geoJSON(data, {
onEachFeature: function (feature, layer) {
var content = `<h3>${feature.properties.name}</h3>`;
content += `<h5>${feature.properties.type}</h5><ul>
<li>Location: ${feature.properties.location}</li>
<li>Description: ${feature.properties.description}</li>
</ul>`;
layer.bindPopup(content);
},
pointToLayer: function (feature, latlng) {
let color = undefined;
if (feature.properties.type === 'Organization') {
color = "#ff7800";
} else {
color = "#0078ff";
}
let geojsonMarkerOptions = {
radius: 8,
fillColor: color,
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
return L.circleMarker(latlng, geojsonMarkerOptions);
}
}
).addTo(map);
})
.catch(function (err) {
console.log('error: ' + err);
});
/* Legend Specific */
var legend = L.control({ position: "bottomright" });
legend.onAdd = function (map) {
var div = L.DomUtil.create("div", "legend");
div.innerHTML += "<h4>Legend</h4>";
div.innerHTML += '<i style="background: #FF7800"></i><span>Organization</span><br>';
div.innerHTML += '<i style="background: #0078FF"></i><span>Ocean Feature</span><br>';
return div;
};
legend.addTo(map);