-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
287 lines (241 loc) · 11.5 KB
/
index.html
File metadata and controls
287 lines (241 loc) · 11.5 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Disaster Response Dashboard</title>
<link rel="stylesheet" href="stylesheet.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
</head>
<body>
<body>
<div class="container">
<header class="header">
<h1 id="titlesize">Disaster Response Dashboard</h1>
<p id="description">
<strong>Disaster Relay</strong> is a live public dashboard that shows the current situation across communities following <strong>Hurricane Melissa</strong>. Each update on the dashboard comes from real calls and reports that have been converted into structured data. Communities are grouped by <b>priority level</b> so viewers can quickly see where help is most urgently needed. By clicking on a community, users can view reported needs such as <b>food, water, or shelter</b>, as well as whether <b>injuries have been reported</b>. This allows the public and responders to clearly understand which areas are most affected and what support those communities require.
</p>
<p id="update-status">Last updated: <span id="time-display">Fetching...</span></p>
<div id="map"></div>
</header>
<section class="priority high">
<h2>High Priority</h2>
<div class="parish-grid" id="high-grid"></div>
</section>
<section class="priority medium">
<h2>Medium Priority</h2>
<div class="parish-grid" id="medium-grid"></div>
</section>
<section class="priority low">
<h2>Low Priority</h2>
<div class="parish-grid" id="low-grid"></div>
</section>
</div>
<script>
// ====== Map Setup ======
var jamaicaBounds = [[17.6, -78.6],[18.6, -75.9]];
var map = L.map('map',{
center: [18.1096,-77.2975],
zoom: 10,
minZoom: 9.5,
maxZoom: 18,
maxBounds: jamaicaBounds,
maxBoundsViscosity: 1.0,
zoomControl:true
});
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
attribution:'© OpenStreetMap contributors'
}).addTo(map);
// Use a LayerGroup to manage markers so we can clear them during refresh
var markerLayer = L.layerGroup().addTo(map);
// ====== Function to create markers with DROP ANIMATION ======
function addCountMarkerWithIcon(communities, color, priorityText, iconUrl){
communities.forEach(function(comm){
// Count bubble marker
var countMarkerIcon = L.divIcon({
html: '<div style="background:'+color+'; color:white; border-radius:50%; width:30px; height:30px; display:flex; align-items:center; justify-content:center; font-weight:bold; border:2px solid white;" class="pulse-animation">'+comm.count+'</div>',
className:'',
iconSize:[30,30],
iconAnchor:[15,15],
popupAnchor:[0,-15]
});
var countMarker = L.marker([comm.coords[0], comm.coords[1]], {icon: countMarkerIcon}).addTo(markerLayer);
countMarker.on('add', function() {
setTimeout(() => {
if (countMarker.getElement()) {
countMarker.getElement().classList.add('drop-animation');
}
}, 10);
});
// Standard pin marker
var standardIcon = new L.Icon({
iconUrl: iconUrl,
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/images/marker-shadow.png',
iconSize: [25,41],
iconAnchor: [12,41],
popupAnchor: [1,-34],
shadowSize: [41,41]
});
var marker = L.marker([comm.coords[0], comm.coords[1]], {icon: standardIcon})
.addTo(markerLayer)
.bindPopup("<b>"+comm.name+"</b><br>"+priorityText+(comm.count>1?" (x"+comm.count+")":""));
marker.on('add', function() {
setTimeout(() => {
if (marker.getElement()) {
marker.getElement().classList.add('drop-animation');
}
}, 10);
});
});
}
// ====== Create parish cards ======
function createParishCard(parishName, communities) {
const card = document.createElement('div');
card.className = 'parish-card';
const h3 = document.createElement('h3');
h3.textContent = parishName;
card.appendChild(h3);
communities.sort((a,b)=>a.community.localeCompare(b.community));
communities.forEach(comm=>{
const details = document.createElement('details');
details.className = 'community';
const summary = document.createElement('summary');
summary.textContent = comm.count>1 ? `${comm.community} x${comm.count}` : comm.community;
details.appendChild(summary);
const info = document.createElement('div');
info.className = 'community-info';
const needsP = document.createElement('p');
needsP.className = 'needs';
const needIcons = [];
comm.needs.forEach(need=>{
const n = need.toLowerCase();
if(n.includes('food')) needIcons.push('🍞 Food');
if(n.includes('water')) needIcons.push('💧 Water');
if(n.includes('shelter')) needIcons.push('🏠 Shelter');
if(n.includes('medical')) needIcons.push('🏥 Medical');
});
needsP.innerHTML = needIcons.join(' | ') || 'No specific needs';
info.appendChild(needsP);
const injuryP = document.createElement('p');
const hasMedical = comm.needs.some(n=>n.toLowerCase().includes('medical'));
injuryP.className = hasMedical ? 'injured' : 'none';
injuryP.innerHTML = hasMedical ? '⚠ Injuries Reported' : '✔ No Injuries';
info.appendChild(injuryP);
details.appendChild(info);
card.appendChild(details);
});
return card;
}
// ====== Load and Process CSV Data ======
const csvUrl = 'https://docs.google.com/spreadsheets/d/13WUAN1zNK3fH_wX32QLb44EnQNiA5Z0_jwTtYA_2XHA/export?format=csv&gid=0';
function loadDashboardData() {
// Cache busting timestamp
const fetchUrl = `${csvUrl}&t=${new Date().getTime()}`;
fetch(fetchUrl)
.then(response => response.text())
.then(csvText => {
const lines = csvText.split(/\r?\n/);
const headers = lines[0].split(',').map(h => h.trim().replace(/^\uFEFF/, ''));
const data = [];
for(let i = 1; i < lines.length; i++) {
if(!lines[i].trim()) continue;
const values = lines[i].split(',').map(v => v.trim());
const row = {};
headers.forEach((h, idx) => { row[h] = values[idx] || ''; });
data.push(row);
}
const communities = {};
data.forEach(row => {
const parish = row.Parish?.trim();
const community = row.Community?.trim();
const rawPriority = (row.Severity || row.Priority || "").toLowerCase().trim();
const rawNeeds = row.Needs?.trim() || '';
if(!parish || !community) return;
let priority = 'low';
if (rawPriority.includes('urgent') || rawPriority.includes('critical') || rawPriority.includes('high')) {
priority = 'high';
} else if (rawPriority.includes('moderate') || rawPriority.includes('medium') || rawPriority.includes('med')) {
priority = 'medium';
}
let needs = [];
if (rawNeeds) {
needs = rawNeeds.replace(/[\[\]"]/g, '').split(',').map(n => n.trim()).filter(n => n.length > 0);
}
const key = `${parish}|${community}`;
if(!communities[key]) {
communities[key] = { parish, community, priority, needs, count: 1 };
} else {
const prioRank = {high:3, medium:2, low:1};
if(prioRank[priority] > prioRank[communities[key].priority]) {
communities[key].priority = priority;
}
needs.forEach(n => {
if(!communities[key].needs.includes(n)) communities[key].needs.push(n);
});
communities[key].count++;
}
});
const commArray = Object.values(communities);
const grouped = { high: {}, medium: {}, low: {} };
commArray.forEach(item => {
if (!grouped[item.priority][item.parish]) grouped[item.priority][item.parish] = [];
grouped[item.priority][item.parish].push(item);
});
// Clear existing markers before redraw
markerLayer.clearLayers();
// Update UI Grids
['high', 'medium', 'low'].forEach(prio => {
const grid = document.querySelector(`.priority.${prio} .parish-grid`);
if (grid) {
grid.innerHTML = '';
const parishes = Object.keys(grouped[prio]).sort();
parishes.forEach(parish => {
grid.appendChild(createParishCard(parish, grouped[prio][parish]));
});
}
});
// ====== Map markers ======
const colors = {high:'red', medium:'orange', low:'blue'};
const icons = {
high:'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-red.png',
medium:'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-gold.png',
low:'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-blue.png'
};
const coordsMap = {
'Angels': [18.0167, -76.9167],
'August Town': [18.0, -76.75],
'Ludo Town': [18.3093, -76.8895],
'Breadbasket': [17.9557, -77.2405],
'Montego Bay': [18.4762, -77.8939],
'La Bubu Town': [18.3093, -76.8895],
'Johnstone': [18.2, -77.1],
'Oriott': [18.25, -77.35],
'Yekkiw': [18.32, -77.42]
};
const baseCoords = [18.1096, -77.2975];
commArray.forEach((c, i) => {
const coords = coordsMap[c.community] || [baseCoords[0] + 0.01*i, baseCoords[1] + 0.01*i];
addCountMarkerWithIcon([{
name: c.community,
coords: coords,
count: c.count
}], colors[c.priority], c.priority.charAt(0).toUpperCase() + c.priority.slice(1) + ' Priority', icons[c.priority]);
});
document.getElementById('time-display').innerText = new Date().toLocaleTimeString();
})
.catch(err => {
console.error('Error loading CSV:', err);
document.getElementById('time-display').innerText = 'Error fetching data';
});
}
// Initial Load
loadDashboardData();
// Refresh every 10 seconds
setInterval(loadDashboardData, 10000);
</script>
</body>
</html>