-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (66 loc) · 2.21 KB
/
script.js
File metadata and controls
73 lines (66 loc) · 2.21 KB
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
// Initialize the map and set its view to a specific location and zoom level
var map = L.map("map").setView([39.754, -75.588], 5);
// Add a tile layer (map background) from OpenStreetMap
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
// Add a marker to the map
var marker = L.marker([39.754, -75.588])
.addTo(map)
.bindTooltip("Charter School of Wilmington", {
permanent: false,
direction: "top",
offset: [0, -10],
});
var googleSheetUrl =
"https://docs.google.com/spreadsheets/d/e/2PACX-1vQeetniEzIb5VYYipz4mgbbg1LKT5FCOLvZ3zr-T4EKU-1L7TQQNJLq4BDokQu9OFx2Jh9mkRsswMzh/pub?gid=0&single=true&output=csv";
Papa.parse(googleSheetUrl, {
download: true, // Fetch the file
header: true,
complete: function (results) {
var universities = results.data; // Array of university objects
// Add red dot markers with tooltips
for (var i = 0; i < universities.length; i++) {
var uni = universities[i];
// Ensure coordinates are numbers
var lat = parseFloat(uni.latitude);
var lon = parseFloat(uni.longitude);
if (!isNaN(lat) && !isNaN(lon)) {
// Check for valid coordinates
L.circleMarker([lat, lon], {
radius: 5,
fillColor: "#ff0000",
color: "#ff0000",
weight: 1,
opacity: 1,
fillOpacity: 0.8,
})
.addTo(map)
.bindTooltip(uni.college_name, {
permanent: false,
direction: "top",
offset: [0, -10],
});
}
}
// Fit the map to show all markers
var group = new L.featureGroup(
universities
.filter(
(u) =>
!isNaN(parseFloat(u.latitude)) && !isNaN(parseFloat(u.longitude))
)
.map((u) =>
L.circleMarker([parseFloat(u.latitude), parseFloat(u.longitude)], {
radius: 5,
})
)
);
map.fitBounds(group.getBounds());
},
error: function (error) {
console.error("Error fetching Google Sheet:", error);
},
});