-
Notifications
You must be signed in to change notification settings - Fork 0
/
nys-data.js
41 lines (33 loc) · 1.33 KB
/
nys-data.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
let nycMap = L.map("map");
L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(nycMap);
nycMap.setView([40.7690, -73.920], 12);
L.geoJSON(geojsonFeature, {
onEachFeature: (feature, layer) => {
layer.bindPopup(`<h3>${feature.properties.school}</h3>
<hr>
<b>${feature.properties.address}</b><br>
<b>${feature.properties.status}<hr>${feature.properties.established}</b>`);
}
}).addTo(nycMap);
let schools = geojsonFeature.features.map(feature => feature.properties.school)
.filter(school => school !== "")
.sort();
console.log(schools);
schools.forEach(school => {
$("#sidebar").append(`<a href ='#'><li>${school}</li></a>`);
});
$("#sidebar").on("click", "li", function() {
let schoolText = $(this).text();
let feature = geojsonFeature.features.find(feature => feature.properties.school === schoolText);
if (feature) {
let coordinates = feature.geometry.coordinates;
nycMap.panTo(new L.LatLng(coordinates[1], coordinates[0]));
nycMap.setZoom(16);
} else {
console.error(`School not found: ${schoolText}`);
}
});
const sidebar = L.control.sidebar('sidebar').addTo(nycMap);