-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
778 lines (664 loc) · 36.2 KB
/
Copy pathindex.html
File metadata and controls
778 lines (664 loc) · 36.2 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EPFL tree map</title>
<meta name="deployment" content="local" hidden>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" as="style">
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js" as="script">
<link rel="preload" href="data.json" as="fetch" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Spectral:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol/dist/L.Control.Locate.min.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" media="print" onload="this.media='all'">
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.bootstrap5.min.css" media="print" onload="this.media='all'" />
<style>
@media (max-width: 768px) { #map { height: 60vh !important; } }
#map { height: calc(97vh - 2rem); width: 100%; }
#locationTextbox { display: none; }
.tab-content { padding: 1rem; background-color: #f8f9fa; }
@media (min-width: 768px) {
#locationTextbox { display: block; margin-top: 10px; }
}
.highlighted-tree-marker {
filter: drop-shadow(0 0 8px rgba(255, 193, 7, 0.8));
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
.highlight-card {
border-left: 4px solid #ffc107;
background-color: #fffbf0;
}
.highlight-badge {
background-color: #ffc107;
color: #000;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85rem;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container-fluid my-2">
<div class="row">
<div class="col-12 col-md-8 order-1 order-md-2 mp-0">
<div id="map"></div>
<div id="loading-overlay" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.9); display: flex; align-items: center; justify-content: center; z-index: 1000;">
<div>Loading map...</div>
</div>
<input type="text" id="locationTextbox" class="form-control" readonly placeholder="Clicked location">
</div>
<div class="col-12 col-md-4 order-2 order-md-1">
<div class="right-panel p-3 p-md-0"></div>
<div class="mb-3">
<h2>
epfl tree map
</h2>
this is a map of trees around epfl.
all trees are mapped manually, if you would like to contribute:
either use github or google.
<div class="mb-3"></div>
<a href="https://github.com/m8/trees" target="_blank" class="d-inline-flex align-items-center text-decoration-none">
<img src="https://img.shields.io/github/stars/m8/trees?style=social" alt="GitHub stars">
<span class="ms-2">Contribute on GitHub</span>
</a>
<div class="row mb-3">
<div class="col-6">
<div class="card shadow-sm hover-shadow border-0 rounded-3 mb-2">
<div class="card-body d-flex align-items-center p-3">
<div class="bg-light rounded-circle p-2 me-3 d-flex justify-content-center align-items-center" style="width: 56px; height: 56px;">
<img src="tree.png" alt="Tree" style="width: 36px; height: 36px;">
</div>
<div>
<h6 class="card-title mb-0 text-secondary">Trees Mapped</h6>
<span class="fs-3 fw-bold" id="total-trees">0</span>
</div>
</div>
</div>
</div>
<div class="col-6">
<div class="card shadow-sm hover-shadow border-0 rounded-3 mb-2">
<div class="card-body d-flex align-items-center p-3">
<div class="bg-light rounded-circle p-2 me-3 d-flex justify-content-center align-items-center" style="width: 56px; height: 56px;">
<span style="font-size: 32px;">🌿</span>
</div>
<div>
<h6 class="card-title mb-0 text-secondary">Species Found</h6>
<span class="fs-3 fw-bold" id="total-species">0</span>
</div>
</div>
</div>
</div>
</div>
<!-- Monthly Highlights Section -->
<div class="mb-3">
<h6 class="mb-2" id="sidebar-month-title">Monthly Highlights</h6>
<div id="sidebar-highlights-list">
<p class="text-muted small">Loading...</p>
</div>
</div>
<div class="alert alert-warning mt-3 mb-3" role="alert">
<p class="mb-0"><strong>⚠️ Safety Warning:</strong> This map might have inaccuracies, do not consume any fruits or nuts without proper knowledge of the tree species.</p>
</div>
</div>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="tree-data-tab" data-bs-toggle="tab"
data-bs-target="#tree-data" type="button" role="tab" aria-controls="tree-data"
aria-selected="true">Tree Data</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="tree-stats-tab" data-bs-toggle="tab" data-bs-target="#tree-stats"
type="button" role="tab" aria-controls="tree-stats" aria-selected="false">Tree
Statistics</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="google-form-tab" data-bs-toggle="tab" data-bs-target="#google-form"
type="button" role="tab" aria-controls="google-form" aria-selected="false">Report a
Tree</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="monthly-highlights-tab" data-bs-toggle="tab" data-bs-target="#monthly-highlights"
type="button" role="tab" aria-controls="monthly-highlights" aria-selected="false">Monthly Highlights</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="links-tab" data-bs-toggle="tab" data-bs-target="#links"
type="button" role="tab" aria-controls="links" aria-selected="false">Useful Links</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="tree-data" role="tabpanel"
aria-labelledby="tree-data-tab">
<div class="table-responsive pt-2">
<!-- <div class="row mb-2">
<div class="col-md-6">
<input id="coordinateSearch" class="form-control" type="text"
placeholder="Search by coordinates (lat,lng)">
</div>
<div class="col-md-6 text-end">
<select id="treeFilter" class="form-select">
<option value="">Show All</option>
<option value="pine" data-keywords="pinus">🌲 Pines</option>
<option value="Oak">🌳 Oak</option>
<option value="Maple">🍁 Maple</option>
<option value="Birch">Birch</option>
<option value="Cherry">🌸 Cherry</option>
</select>
</div>
</div> -->
<table id="treeTable" class="table table-hover table-striped">
<thead class="table-light">
<tr>
<th style="display: none;">Random</th>
<th>Id</th>
<th>Name</th>
<!-- <th>Time</th> -->
<!-- <th>Note</th> -->
<th class="text-center">Show</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="tree-stats" role="tabpanel" aria-labelledby="tree-stats-tab">
<div id="treeStatistics" class="mb-4">
<h4>Tree Data Statistics</h4>
<h5>General Statistics</h5>
<table class="table table-striped table-bordered mb-4">
<tbody>
<tr>
<td>Total Trees</td>
<td><span id="total-trees-stat">0</span></td>
</tr>
<tr>
<td>Most Common Tree Species</td>
<td><span id="most-common-species">N/A</span></td>
</tr>
</tbody>
</table>
<h5>Tree Species Breakdown</h5>
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>Species</th>
<th>Count</th>
</tr>
</thead>
<tbody id="species-breakdown">
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="google-form" role="tabpanel" aria-labelledby="google-form-tab">
<iframe
src="https://docs.google.com/forms/d/e/1FAIpQLSdEifyC5R4j3r2QyzNqIgI_v5SJ9Gr3AUsEvRugSgb4H9tJ2g/viewform?usp=dialog"
width="100%" height="600" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe>
</div>
<div class="tab-pane fade" id="monthly-highlights" role="tabpanel" aria-labelledby="monthly-highlights-tab">
<h4 id="current-month-title">Monthly Highlights</h4>
<p class="text-muted mb-3">Trees that are particularly interesting this month with seasonal features like flowering, fruiting, or autumn colors.</p>
<div id="monthly-highlights-content">
<p class="text-center text-muted">Loading highlights...</p>
</div>
</div>
<div class="tab-pane fade" id="links" role="tabpanel" aria-labelledby="links-tab">
<h4>Useful Links</h4>
<ul class="list-unstyled">
<li><a href="https://map.lausanne.ch/" target="_blank">Lausanne tree map</a> (select "Arbres" in "Environnement construit")</li>
<li><a href="https://www.picturethisai.com/" target="_blank">PictureThis</a> nice tool to identify trees</li>
<li><a href="https://www.amazon.com/Collins-Tree-Guide-S/dp/0007207719" target="_blank">Collins Tree Guide</a> nice book for identifying trees</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.79.0/dist/L.Control.Locate.min.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
<script src="https://cdn.datatables.net/2.1.8/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
// EPFL
const EPFL_LAT = 46.5191;
const EPFL_LNG = 6.5668;
const INITIAL_ZOOM = 17;
let tree_types = new Map();
let data_file = "data.json";
let monthly_highlights_data = null;
let highlighted_species = [];
// Initialize the map
let map = L.map('map').setView([EPFL_LAT, EPFL_LNG], INITIAL_ZOOM);
let locationMarker;
let markers = new Map();
let data_table;
let tree_data;
let treeLayer = L.layerGroup();
const treeIcon = L.icon({
iconUrl: 'tree.png',
iconSize: [36, 36],
});
const highlightedTreeIcon = L.icon({
iconUrl: 'tree.png',
iconSize: [42, 42],
className: 'highlighted-tree-marker'
});
const baseMaps = {
"Satellite": L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
maxZoom: 21
}),
"Street View": L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 21,
attribution: '© OpenStreetMap contributors',
})
};
let selectedLocationMarker = null;
document.addEventListener('DOMContentLoaded', function() {
baseMaps["Satellite"].addTo(map);
L.control.layers(baseMaps).addTo(map);
L.control.locate({
keepCurrentZoomLevel: true,
flyTo: true,
showPopup: false,
locateOptions: { enableHighAccuracy: true },
drawCircle: false,
}).addTo(map);
setTimeout(() => {
fetch(data_file)
.then(response => response.text())
.then(data => {
tree_data = parseGoogleVisualizationResponse(data);
$('#total-trees').text(tree_data.length);
loadTreeData();
});
// Load monthly highlights data
fetch('monthly-highlights.json')
.then(response => response.json())
.then(data => {
monthly_highlights_data = data;
loadMonthlyHighlights();
})
.catch(err => {
console.error('Error loading monthly highlights:', err);
document.getElementById('monthly-highlights-content').innerHTML =
'<p class="text-muted">Could not load monthly highlights data.</p>';
});
}, 100);
});
map.on('click', function (e) {
const { lat, lng } = e.latlng;
const locationTextbox = document.getElementById('locationTextbox');
locationTextbox.value = lat + ', ' + lng;
if (window.navigator.clipboard) {
window.navigator.clipboard.writeText(lat + ', ' + lng).then(() => {
console.log('Location copied to clipboard');
}).catch(err => {
console.error('Could not copy text: ', err);
});
} else {
console.error('Clipboard API not available');
}
if (locationMarker) {
map.removeLayer(locationMarker);
}
locationMarker = L.marker([lat, lng], { draggable: true }).addTo(map);
locationMarker.on('dragend', function (e) {
const { lat, lng } = e.target.getLatLng();
locationTextbox.value = lat + ', ' + lng;
if (navigator.clipboard) {
navigator.clipboard.writeText(lat + ', ' + lng).then(() => {
console.log('Location copied to clipboard');
}).catch(err => {
console.error('Could not copy text: ', err);
});
}
});
});
function parseGoogleVisualizationResponse(jsonString) {
try {
const cleanJson = jsonString.replace('/*O_o*/', '')
.replace('google.visualization.Query.setResponse(', '')
.replace(');', '');
const data = JSON.parse(cleanJson);
const results = [];
let columns = data.table.cols.map(col =>
(col.label || '').toLowerCase().trim()
);
columns = columns.map(col => {
if (typeof col !== 'string') return '';
return col.startsWith('zaman') || col.startsWith('timestamp') ? 'timestamp':
col.startsWith('agac') || col.startsWith('tree') ? 'tree':
col.startsWith('konum') || col.startsWith('location') || col.startsWith('loc') ? 'loc':
col.startsWith('not') || col.startsWith('note') ? 'note':
col.startsWith('bio') ? 'bio':
col.startsWith('id') ? 'id':
col.startsWith('family') || col.startsWith('fam') ? 'family':
col;
});
data.table.rows.forEach(row => {
const item = {};
columns.forEach((col, index) => {
if (row.c && row.c[index] && 'v' in row.c[index]) {
item[col] = String(row.c[index].v);
} else {
item[col] = '';
}
});
results.push(item);
});
return results;
} catch (error) {
console.error('Error parsing response:', error);
return [];
}
}
function render_markers(data) {
treeLayer.clearLayers();
markers.clear();
data.forEach((row, i) => {
if (!row["loc"]) return;
const [lat, lng] = row["loc"].split(',').map(Number);
// Check if this tree is highlighted this month
const isHighlighted = highlighted_species.includes(row['bio']);
const markerIcon = isHighlighted ? highlightedTreeIcon : treeIcon;
const marker = L.marker([lat, lng], { icon: markerIcon }).bindPopup(`
<div class="p-2">
<h5 style="color: #2c3e50; margin-bottom: -10px;">
${escapeHtml(row['tree'] || 'Unknown')}
</h5>
<p class="text-muted mb-3" style="border-bottom: 1px solid #eee; padding-bottom: 5px;">
<em>${escapeHtml(row['bio'] || '')}</em>
${row['bio'] ? `<a href="https://en.wikipedia.org/wiki/${encodeURIComponent(row['bio'])}" target="_blank" title="View on Wikipedia"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg></a>` : ''}
</p>
<div class="mb-2 d-flex">
<span class="me-2" style="min-width: 70px;">Family:</span>
<strong>${escapeHtml(row['family'] || 'Unknown')}</strong>
${row['family'] ? `<a href="https://en.wikipedia.org/wiki/${encodeURIComponent(row['family'])}" target="_blank" class="ms-1" title="View on Wikipedia"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg></a>` : ''}
</div>
<div class="mb-2 d-flex">
<span class="me-2" style="min-width: 70px;">ID:</span>
<strong>${escapeHtml(row['id'] || 'Unknown')}</strong>
</div>
<div class="d-flex align-items-center">
<button class="btn btn-sm btn-outline-secondary" onclick="copyToClipboard('${escapeHtml(row['loc'])}')">
📍 Loc
</button>
</div>
</div>
`, { minWidth: 200 });
treeLayer.addLayer(marker);
let id = row['id'] || -1;
id = parseInt(id) - 1;
markers.set(id, marker);
});
// Always ensure the tree layer is visible on the map
if (map.hasLayer(treeLayer)) {
map.removeLayer(treeLayer);
}
treeLayer.addTo(map);
}
async function loadTreeData(filter = '') {
try {
let data = tree_data;
const uniqueSpecies = new Set(data.map(row => row['bio']).filter(bio => bio && bio.trim()));
$('#total-species').text(uniqueSpecies.size);
if (filter) {
data = data.filter(row => row['tree'].toLowerCase().includes(filter.toLowerCase()));
}
const tableData = data.map((row, i) => {
if (!row["loc"]) return null;
return [
Math.random(),
escapeHtml(row['id'] || 'Unknown'),
escapeHtml(row['tree'] || 'Unknown') + `<br> <small class="text-muted">${escapeHtml(row['bio'] || '')}</small>`,
`<button class="btn btn-gray btn-sm" onclick="showOnMap(${parseInt(row['id'])-1})">
<i class="bi bi-geo-alt"></i> 📍
</button>`
];
}).filter(row => row !== null);
render_markers(data);
data_table = $('#treeTable').DataTable({
data: tableData,
pageLength: 10,
responsive: true,
dom: '<<t>fip>',
order: [[0, 'asc']],
language: {
search: "Search trees:",
lengthMenu: "Show _MENU_ trees per page"
},
columnDefs: [
{ visible: false, targets: 0 },
{ className: "text-center", targets: 1 },
{ className: "text-left", targets: -1 },
]
});
updateTreeStatistics(data);
treeLayer.addTo(map);
document.getElementById('loading-overlay').style.display = 'none';
} catch (err) {
console.error('Error:', err);
alert('Failed to load data. Check console for details.');
}
}
function updateTreeStatistics(data) {
const totalTrees = data.length;
$('#total-trees-stat').text(totalTrees);
// Species breakdown
const speciesCount = {};
data.forEach(row => {
const species = row['tree'];
if (species) {
speciesCount[species] = (speciesCount[species] || 0) + 1;
}
});
console.log(speciesCount)
const mostCommonSpecies = Object.entries(speciesCount)
.reduce((max, entry) => entry[1] > max[1] ? entry : max, ['', 0])[0];
$('#most-common-species').text(mostCommonSpecies || 'N/A');
const speciesList = $('#species-breakdown');
speciesList.empty();
for (const species in speciesCount) {
speciesList.append(
'<tr><td>' + species + '</td><td>' + speciesCount[species] + '</td></tr>'
);
}
console.log(speciesList);
}
$('#treeFilter').on('change', function () {
const filter = this.value;
data_table.column(1).search(filter, true, false).draw();
let data = tree_data.filter(row => row['tree'].toLowerCase().includes(filter.toLowerCase()));
render_markers(data);
});
document.getElementById('coordinateSearch').addEventListener('input', function () {
const query = this.value.trim();
if (!query) {
render_markers(tree_data);
return;
}
const [lat, lng] = query.split(',').map(Number);
if (!isNaN(lat) && !isNaN(lng)) {
const filteredData = tree_data.filter(row => {
if (!row['loc']) return false;
const [rowLat, rowLng] = row['loc'].split(',').map(Number);
return Math.abs(rowLat - lat) < 0.0005 && Math.abs(rowLng - lng) < 0.0005;
});
render_markers(filteredData);
}
});
function showOnMap(i) {
console.log('Show on map:', i);
const marker = markers.get(i);
if (marker) {
console.log('Showing marker:', marker);
if (selectedLocationMarker) map.removeLayer(selectedLocationMarker);
selectedLocationMarker = marker;
marker.addTo(map).openPopup();
map.flyTo(marker.getLatLng(), 18);
}
}
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function copyToClipboard(text) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
.then(() => {
alert('Coordinates copied to clipboard');
})
.catch(err => {
console.error('Could not copy text: ', err);
alert('Failed to copy coordinates');
});
} else {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
alert('Coordinates copied to clipboard');
} catch (err) {
console.error('Could not copy text: ', err);
alert('Failed to copy coordinates');
}
document.body.removeChild(textArea);
}
}
function loadMonthlyHighlights() {
if (!monthly_highlights_data) return;
const currentDate = new Date();
const currentMonth = currentDate.getMonth() + 1; // JavaScript months are 0-indexed
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
// Update titles
document.getElementById('current-month-title').textContent =
`${monthNames[currentMonth - 1]} Highlights`;
document.getElementById('sidebar-month-title').textContent =
`${monthNames[currentMonth - 1]} Highlights`;
// Find highlighted species for current month
highlighted_species = [];
const highlightsForMonth = [];
for (const [species, info] of Object.entries(monthly_highlights_data.highlights)) {
if (info.months.includes(currentMonth)) {
highlighted_species.push(species);
highlightsForMonth.push({
species: species,
commonName: info.commonName,
highlight: info.highlights[currentMonth]
});
}
}
// Display in sidebar (show 4, expandable)
const sidebarDiv = document.getElementById('sidebar-highlights-list');
if (highlightsForMonth.length === 0) {
sidebarDiv.innerHTML = '<p class="text-muted small">No special highlights for this month.</p>';
} else {
let sidebarHtml = '';
highlightsForMonth.slice(0, 4).forEach((item, index) => {
sidebarHtml += `
<div class="card border-0 mb-2 highlight-item-${index}" style="background-color: #fff3e0; border-left: 3px solid #ff9800 !important;">
<div class="card-body p-2">
<strong style="font-size: 0.9rem; color: #e65100;">${escapeHtml(item.commonName)}</strong><br>
<span class="text-muted small">${escapeHtml(item.highlight)}</span>
</div>
</div>
`;
});
// Add expand button if more than 4
if (highlightsForMonth.length > 4) {
sidebarHtml += `
<button class="btn btn-sm btn-link text-decoration-none p-0 mb-2" id="expand-highlights">
Show ${highlightsForMonth.length - 4} more...
</button>
<div id="extra-highlights" style="display: none;">
`;
highlightsForMonth.slice(4).forEach((item, index) => {
sidebarHtml += `
<div class="card border-0 mb-2" style="background-color: #fff3e0; border-left: 3px solid #ff9800 !important;">
<div class="card-body p-2">
<strong style="font-size: 0.9rem; color: #e65100;">${escapeHtml(item.commonName)}</strong><br>
<span class="text-muted small">${escapeHtml(item.highlight)}</span>
</div>
</div>
`;
});
sidebarHtml += `
</div>
<button class="btn btn-sm btn-link text-decoration-none p-0 mb-2" id="collapse-highlights" style="display: none;">
Show less
</button>
`;
}
sidebarDiv.innerHTML = sidebarHtml;
// Add expand/collapse functionality
if (highlightsForMonth.length > 4) {
document.getElementById('expand-highlights').addEventListener('click', function() {
document.getElementById('extra-highlights').style.display = 'block';
this.style.display = 'none';
document.getElementById('collapse-highlights').style.display = 'block';
});
document.getElementById('collapse-highlights').addEventListener('click', function() {
document.getElementById('extra-highlights').style.display = 'none';
this.style.display = 'none';
document.getElementById('expand-highlights').style.display = 'block';
});
}
}
// Display in tab (full list)
const contentDiv = document.getElementById('monthly-highlights-content');
if (highlightsForMonth.length === 0) {
contentDiv.innerHTML = '<p class="text-muted">No special highlights for this month.</p>';
return;
}
let html = '<div class="list-group">';
highlightsForMonth.forEach(item => {
html += `
<div class="list-group-item highlight-card mb-2">
<div class="d-flex w-100 justify-content-between align-items-start">
<h6 class="mb-1">${escapeHtml(item.commonName)}</h6>
<span class="highlight-badge">In Season</span>
</div>
<p class="mb-1"><em>${escapeHtml(item.species)}</em></p>
<p class="mb-0 text-muted"><strong>${escapeHtml(item.highlight)}</strong></p>
</div>
`;
});
html += '</div>';
contentDiv.innerHTML = html;
// Count highlighted trees in current data
if (tree_data) {
const highlightedCount = tree_data.filter(row =>
highlighted_species.includes(row['bio'])
).length;
if (highlightedCount > 0) {
contentDiv.innerHTML += `
<div class="alert alert-info mt-3">
<strong>${highlightedCount}</strong> highlighted tree(s) found on the map for this month!
</div>
`;
}
}
}
</script>
</body>
</html>