-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
605 lines (542 loc) · 25.4 KB
/
index.html
File metadata and controls
605 lines (542 loc) · 25.4 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Biodiversity Map — Forest Health Monitoring</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
:root { --pad: 12px; --green:#2c7a2c; --green-dark:#256025; }
body { margin: 0; padding: 0; display: flex; }
#map { height: 100vh; width: 75%; }
#sidebar {
width: 25%; height: 100vh; overflow-y: auto; padding: var(--pad);
box-sizing: border-box; border-left: 1px solid #ccc;
font-family: sans-serif; background: #fafafa;
}
h2 { margin-top: 0; font-size: 1.4em; font-weight: 600; }
canvas { width: 100% !important; height: auto !important; margin-top: 10px; }
.leaflet-control-layers-expanded { width: auto !important; max-height: none !important; display: block !important; }
/* Controls */
#taxa-filter, #species-filter {
width: 100%; margin-bottom: 10px;
font-size: 1.05em; padding: 8px;
border-radius: 6px; border: 1px solid #ccc; background: #fff;
}
#species-filter:disabled { opacity: 0.6; }
#download-btn, .tool-btn {
width: 100%; font-size: 1.05em; padding: 10px; border-radius: 6px;
border: none; background: var(--green); color: #fff; cursor: pointer;
}
#download-btn:hover, .tool-btn:hover { background: var(--green-dark); }
#toolbar { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 8px 0 6px; }
#filter-note { font-size: 0.92em; color:#444; margin: 6px 0 8px; min-height: 1.1em; }
/* Permanent top-left logo */
#logo-overlay { position: fixed; top: var(--pad); left: var(--pad); z-index: 1000; pointer-events: none; }
#logo-overlay img { max-width: 220px; width: 20vw; height: auto; display:block; }
/* Splash */
#splash-screen {
position: fixed; inset: 0; background: rgba(255,255,255,0.97); z-index: 2000;
display: flex; align-items: center; justify-content: center; font-family: sans-serif;
}
#splash-content {
max-width: 700px; text-align: left; padding: 30px; border: 1px solid #ccc; border-radius: 12px; background: #fff;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
#splash-content img { max-width: 200px; margin-bottom: 20px; display:block; }
#splash-content h1 { margin-top: 0; }
#splash-button { margin-top: 20px; padding: 10px 20px; font-size: 16px; cursor: pointer; border-radius: 6px; border: none; background: var(--green); color: #fff; }
#splash-button:hover { background: var(--green-dark); }
/* Loading overlay */
#loading { position: fixed; inset: 0; background: rgba(255,255,255,0.85); z-index: 1500; display: flex; align-items: center; justify-content: center; font-family: sans-serif; }
#loading div { padding: 10px 14px; border-radius: 8px; border: 1px solid #ddd; background:#fff; box-shadow:0 2px 6px rgba(0,0,0,.08); }
/* Sidebar spacing */
#zone-details { margin-top: 10px; line-height: 1.4; }
#species-list { margin-top: 12px; }
/* Bigger 5/30 layer toggle */
.leaflet-control-layers { font-size: 16px !important; }
.leaflet-control-layers-expanded { padding: 12px 14px !important; }
.leaflet-control-layers-base label,
.leaflet-control-layers-overlays label {
line-height: 1.6 !important; display: flex !important; align-items: center !important; gap: 8px !important;
}
.leaflet-control-layers input.leaflet-control-layers-selector {
transform: scale(1.4) !important; transform-origin: left center !important; margin-right: 6px !important; accent-color: var(--green);
}
/* REMOVE rectangular focus outline around clicked polygons */
.leaflet-container .leaflet-interactive { outline: none !important; }
.leaflet-container .leaflet-interactive:focus,
.leaflet-container .leaflet-interactive:focus-visible,
.leaflet-container svg path:focus { outline: none !important; }
@media (max-width: 900px) {
body { flex-direction: column; }
#map { width: 100%; height: 60vh; }
#sidebar { width: 100%; height: 40vh; }
#splash-content { max-width: 90%; }
#logo-overlay img { max-width: 180px; width: 40vw; }
}
</style>
</head>
<body>
<!-- Splash -->
<div id="splash-screen">
<div id="splash-content">
<img src="ForesthealthLogo.png" alt="Forest Health Monitoring Logo">
<h1>Welcome to the Forest Health Monitoring Map</h1>
<p>
Since 2017, Nillumbik Shire Council has been working with partners, landholders, Landcare groups,
Melbourne Water, Parks Victoria and many others to build a unique dataset tracking which animal
species are present across our Shire. We’re pleased to share this information with you here —
free to explore and download.
</p>
<p>On the main map you can choose to view:</p>
<ul>
<li><strong>All data</strong> combined</li>
<li><strong>5 broad zones</strong> across the Shire</li>
<li><strong>30 detailed zones</strong> for finer-scale patterns</li>
</ul>
<p>
Simply click a zone to see its data (or hold <kbd>Ctrl</kbd>/<kbd>Cmd</kbd> to select multiple).
Use the filter on the right to focus on a particular group of animals (birds, mammals, reptiles)
or leave it on “All Taxa” for the full picture. Any selection can be downloaded directly using
the <strong>Download Data</strong> button at the bottom right.
</p>
<p>
For more information on the program, visit:<br>
👉 <a href="https://www.nillumbik.vic.gov.au/Explore/Environment/Environment-projects-and-programs/Forest-Health-Monitoring-Program" target="_blank" rel="noopener">
Forest Health Monitoring Program
</a>
</p>
<button id="splash-button">Start Exploring</button>
</div>
</div>
<!-- Loading -->
<div id="loading"><div>Loading data…</div></div>
<!-- Logo -->
<div id="logo-overlay"><img src="ForesthealthLogo.png" alt="Forest Health Monitoring Logo"></div>
<div id="map"></div>
<div id="sidebar">
<h2>Zone Info</h2>
<!-- Filters -->
<select id="taxa-filter">
<option value="all">All Taxa</option>
</select>
<select id="species-filter" disabled>
<option value="all">All species</option>
</select>
<!-- Matched zones indicator -->
<div id="filter-note"></div>
<!-- Toolbar -->
<div id="toolbar">
<button id="reset-btn" class="tool-btn" title="Clear all filters and selections">Reset filters</button>
<button id="zoom-btn" class="tool-btn" title="Zoom map to selected zones">Zoom to selection</button>
<button id="share-btn" class="tool-btn" title="Copy a link to this exact view">Copy link</button>
</div>
<!-- Details + charts -->
<div id="zone-details">Loading…</div>
<canvas id="barChart"></canvas>
<canvas id="lineChart"></canvas>
<div id="species-list"></div>
<button id="download-btn">Download Data</button>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// --- helpers ---
function normSite(x) {
return String(x).toUpperCase().replace(/-/g, '');
}
// Hide splash
document.getElementById('splash-button').addEventListener('click', () => {
document.getElementById('splash-screen').style.display = 'none';
});
// Map (fit to boundary once it loads to show full Shire)
const map = L.map('map');
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18, attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Boundary (non-interactive)
const boundaryStyle = { color: 'black', weight: 2, fillOpacity: 0, interactive: false };
let boundaryBounds = null;
// State
let barChart=null, lineChart=null;
let detections=[], latestSpeciesData={}, displayedDetections=[];
let selectedLayers=[], selectedZones=[]; // [{id,isBlock}]
let matchZones5 = new Set(), matchZones30 = new Set();
let currentBase = '5'; // '5' or '30'
// Layers
const fiveZoneLayer = L.layerGroup();
const thirtyZoneLayer = L.layerGroup();
let fiveLayerInstance = null, thirtyLayerInstance = null;
// Styles
const style5 = { color: 'darkgreen', weight: 1, fillOpacity: 0.3 };
const style5Hover = { color: 'lime', weight: 2 };
const style30 = { color: 'blue', weight: 0.5, fillOpacity: 0.2 };
const style30Hover = { color: 'cyan', weight: 2 };
const styleSelected = { color: '#ff9900', weight: 3, fillOpacity: 0.45 };
const styleMatch = { color: '#5252ff', weight: 2.5, fillOpacity: 0.35, dashArray: '3 2' };
const getBaseStyle = (layer) => (layer._isBlock ? style5 : style30);
const getHoverStyle = (layer) => (layer._isBlock ? style5Hover : style30Hover);
// Elements
const taxaFilterEl = document.getElementById('taxa-filter');
const speciesFilterEl = document.getElementById('species-filter');
const noteEl = document.getElementById('filter-note');
// URL state helpers
function parseQuery() {
const p = new URLSearchParams(location.search);
return {
layer: p.get('layer') || '5',
taxa: p.get('taxa') || 'all',
species: p.get('species') || 'all',
sel: (p.get('sel') || '').split('|').filter(Boolean), // IDs
view: p.get('view') || '' // "lat,lng,zoom"
};
}
function buildShareURL() {
const p = new URLSearchParams();
p.set('layer', currentBase);
p.set('taxa', taxaFilterEl.value);
p.set('species', speciesFilterEl.value);
const ids = selectedZones.map(z => z.id);
if (ids.length) p.set('sel', ids.join('|'));
const c = map.getCenter();
p.set('view', `${c.lat.toFixed(5)},${c.lng.toFixed(5)},${map.getZoom()}`);
return `${location.origin}${location.pathname}?${p.toString()}`;
}
async function copyShareURL() {
const url = buildShareURL();
try { await navigator.clipboard.writeText(url); alert('Link copied to clipboard'); }
catch(e){ prompt('Copy this URL', url); }
}
// Selection helpers
function isLayerSelected(layer) { return selectedLayers.includes(layer); }
function addSelection(layer, zoneId, isBlock) {
if (!isLayerSelected(layer)) {
selectedLayers.push(layer);
selectedZones.push({ id: zoneId, isBlock });
layer.setStyle(styleSelected);
}
}
function removeSelection(layer, zoneId, isBlock) {
const li = selectedLayers.indexOf(layer);
if (li >= 0) selectedLayers.splice(li, 1);
const zi = selectedZones.findIndex(z => z.id === zoneId && z.isBlock === isBlock);
if (zi >= 0) selectedZones.splice(zi, 1);
applyMatchStyleToLayer(layer);
}
function clearAllSelections() {
selectedLayers.forEach(l => applyMatchStyleToLayer(l));
selectedLayers = [];
selectedZones = [];
updateDetections();
}
// Species options
function repopulateSpeciesOptions() {
const taxa = taxaFilterEl.value;
speciesFilterEl.innerHTML = '';
const def = document.createElement('option');
def.value = 'all';
def.textContent = taxa === 'all' ? 'All species' : `All ${taxa}`;
speciesFilterEl.appendChild(def);
if (taxa === 'all') {
speciesFilterEl.disabled = true;
speciesFilterEl.value = 'all';
return;
}
const seen = new Map();
detections.forEach(d => {
if (String(d.taxa) !== taxa) return;
const key = d.name ? String(d.name) : (d.common_name ? String(d.common_name) : null);
if (!key) return;
const label = d.common_name ? `${d.common_name} (${d.name || 'n/a'})` : key;
if (!seen.has(key)) seen.set(key, label);
});
[...seen.entries()].sort((a,b)=>a[1].localeCompare(b[1])).forEach(([value,label])=>{
const opt=document.createElement('option'); opt.value=value; opt.textContent=label; speciesFilterEl.appendChild(opt);
});
speciesFilterEl.disabled = false;
if (![...speciesFilterEl.options].some(o=>o.value===speciesFilterEl.value)) speciesFilterEl.value='all';
}
// Reverse highlight sets
function computeMatchSets() {
matchZones5.clear(); matchZones30.clear();
const taxa = taxaFilterEl.value;
const species = speciesFilterEl.value;
if (taxa === 'all') return;
detections.forEach(d => {
if (String(d.taxa) !== taxa) return;
if (species !== 'all') {
const nm = String(d.name || '');
const cm = String(d.common_name || '');
if (nm !== species && cm !== species) return;
}
if (d.block != null) matchZones5.add(String(d.block));
if (d.site != null) matchZones30.add(normSite(d.site));
});
}
function applyMatchStyleToLayer(layer) {
const matched = layer._isBlock ? matchZones5.has(layer._zoneId) : matchZones30.has(layer._zoneId);
layer.setStyle(matched ? styleMatch : getBaseStyle(layer));
}
function applyMatchStylesToGroup(groupInstance) {
if (!groupInstance) return;
groupInstance.eachLayer(layer => {
if (isLayerSelected(layer)) layer.setStyle(styleSelected);
else applyMatchStyleToLayer(layer);
});
}
function updateReverseHighlight() {
computeMatchSets();
applyMatchStylesToGroup(fiveLayerInstance);
applyMatchStylesToGroup(thirtyLayerInstance);
// Note
if (taxaFilterEl.value === 'all') noteEl.textContent = '';
else {
const count30 = matchZones30.size;
noteEl.textContent = (speciesFilterEl.value === 'all')
? `Occurrences in ${count30} of 30 zones`
: `Selected species occurs in ${count30} of 30 zones`;
}
}
// Sidebar + charts
function updateSpeciesList(group) {
const speciesSet = latestSpeciesData[group];
if (!speciesSet) return;
const listHTML = [...speciesSet].sort().map(s => `<li>${s}</li>`).join('');
document.getElementById('species-list').innerHTML =
`<h4>${group === 'native' ? 'Native' : 'Non-native'} Species List</h4><ul>${listHTML}</ul>`;
}
function updateCharts(native, nonnative, trendNative, trendNonNative, years) {
if (barChart) barChart.destroy();
if (lineChart) lineChart.destroy();
barChart = new Chart(document.getElementById('barChart').getContext('2d'), {
type: 'bar',
data: { labels: ['Native', 'Non-native'],
datasets: [{ label: 'Species Richness', data: [native, nonnative], backgroundColor: ['green', 'red'] }] },
options: { responsive: true, plugins: { legend: { display: false } },
onClick: (e, els) => { if (els.length) updateSpeciesList(els[0].index === 0 ? 'native' : 'nonnative'); } }
});
lineChart = new Chart(document.getElementById('lineChart').getContext('2d'), {
type: 'line',
data: { labels: years,
datasets: [
{ label: 'Native Richness', data: trendNative, borderColor: 'green', fill: false },
{ label: 'Non-native Richness', data: trendNonNative, borderColor: 'red', fill: false }
] },
options: { responsive: true, plugins: { legend: { position: 'top' } } }
});
}
function updateDetections() {
const selectedTaxa = taxaFilterEl.value;
const selectedSpecies = speciesFilterEl.value;
displayedDetections = detections.filter(d => {
const matchZone = (selectedZones.length === 0)
? true
: selectedZones.some(z => z.isBlock ? String(d.block) === z.id : normSite(d.site) === normSite(z.id));
const matchTaxa = (selectedTaxa === 'all') || String(d.taxa) === selectedTaxa;
let matchSpecies = true;
if (selectedTaxa !== 'all' && selectedSpecies !== 'all') {
const nm = String(d.name || '');
const cm = String(d.common_name || '');
matchSpecies = (nm === selectedSpecies || cm === selectedSpecies);
}
return matchZone && matchTaxa && matchSpecies;
});
const nativeSpecies = new Set(), nonNativeSpecies = new Set(), trends = {};
displayedDetections.forEach(d => {
const isNative = (d.native || '').toLowerCase() === 'native';
const label = `${d.common_name || ''} (${d.name})`;
const year = d.year;
if (!trends[year]) trends[year] = { native: new Set(), nonnative: new Set() };
(isNative ? trends[year].native : trends[year].nonnative).add(label);
(isNative ? nativeSpecies : nonNativeSpecies).add(label);
});
latestSpeciesData = { native: nativeSpecies, nonnative: nonNativeSpecies };
const years = Object.keys(trends).sort();
const trendNative = years.map(y => trends[y].native.size);
const trendNonNative = years.map(y => trends[y].nonnative.size);
let zoneLabel = 'All Zones';
if (selectedZones.length === 1) zoneLabel = selectedZones[0].id;
if (selectedZones.length > 1) {
const ids = selectedZones.map(z => z.id);
const joined = ids.join(', ');
zoneLabel = joined.length > 60 ? ids.slice(0,5).join(', ') + ` … (+${ids.length-5} more)` : joined;
}
document.getElementById('zone-details').innerHTML = `
<h3>${zoneLabel}</h3>
<p><strong>Detections:</strong> ${displayedDetections.length}</p>
<p><strong>Unique Native Species:</strong> ${nativeSpecies.size}</p>
<p><strong>Unique Non-native Species:</strong> ${nonNativeSpecies.size}</p>
`;
updateCharts(nativeSpecies.size, nonNativeSpecies.size, trendNative, trendNonNative, years);
document.getElementById('species-list').innerHTML = '';
}
// Download
document.getElementById('download-btn').addEventListener('click', () => {
if (!displayedDetections.length) return;
const keys = Object.keys(displayedDetections[0]);
const header = keys.join(',');
const rows = displayedDetections.map(obj => keys.map(k => String(obj[k]).replace(/"/g,'""')).join(','));
const blob = new Blob([header + '\n' + rows.join('\n')], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a'); a.href = url;
let fname = 'All_Zones_data.csv';
if (selectedZones.length === 1) fname = `${selectedZones[0].id}_data.csv`;
if (selectedZones.length > 1) fname = `Multi_Zones_${selectedZones.length}_data.csv`;
a.download = fname; a.click(); URL.revokeObjectURL(url);
});
// Toolbar buttons
document.getElementById('reset-btn').addEventListener('click', () => {
taxaFilterEl.value = 'all';
repopulateSpeciesOptions();
clearAllSelections(); // also calls updateDetections()
updateReverseHighlight();
if (boundaryBounds) map.fitBounds(boundaryBounds, { padding: [20,20] });
});
document.getElementById('zoom-btn').addEventListener('click', () => {
if (selectedLayers.length === 0) return;
const b = L.latLngBounds();
selectedLayers.forEach(l => { if (l.getBounds) b.extend(l.getBounds()); });
if (b.isValid()) map.fitBounds(b, { padding: [20,20] });
});
document.getElementById('share-btn').addEventListener('click', copyShareURL);
// Feature interaction
function attachFeatureHandlers(feature, layer, isBlock) {
layer._isBlock = isBlock;
const zoneId = String(isBlock ? feature.properties.block : feature.properties.site);
layer._zoneId = zoneId;
// Tooltip with zone ID
layer.bindTooltip(zoneId, { sticky: true, direction: 'auto' });
layer.on('mouseover', () => {
if (!isLayerSelected(layer)) layer.setStyle(getHoverStyle(layer));
});
layer.on('mouseout', () => {
if (!isLayerSelected(layer)) applyMatchStyleToLayer(layer);
});
layer.on('click', (e) => {
const toggle = e.originalEvent.ctrlKey || e.originalEvent.metaKey;
if (toggle) {
if (isLayerSelected(layer)) removeSelection(layer, zoneId, isBlock);
else addSelection(layer, zoneId, isBlock);
} else {
if (isLayerSelected(layer) && selectedLayers.length === 1) { clearAllSelections(); return; }
clearAllSelections(); addSelection(layer, zoneId, isBlock);
}
updateDetections();
});
}
// Data + layers loading tracker
const loaded = { det:false, five:false, thirty:false, boundary:false };
function maybeFinalizeInit() {
if (loaded.det && loaded.five && loaded.thirty && loaded.boundary) {
applyURLState(); // initialize from URL, then hide loading
document.getElementById('loading').style.display = 'none';
}
}
// Load detections
const blockFiles = [
'detections_block_1.json','detections_block_2.json','detections_block_3.json',
'detections_block_4.json','detections_block_5.json'
];
Promise.all(blockFiles.map(f => fetch(f).then(r => r.json()))).then(results => {
detections = results.flat();
// Populate taxa
const taxaSet = new Set(detections.map(d => d.taxa).filter(Boolean));
[...taxaSet].sort().forEach(t => {
const opt = document.createElement('option'); opt.value = t; opt.textContent = t;
taxaFilterEl.appendChild(opt);
});
taxaFilterEl.addEventListener('change', () => { repopulateSpeciesOptions(); updateDetections(); updateReverseHighlight(); });
speciesFilterEl.addEventListener('change', () => { updateDetections(); updateReverseHighlight(); });
repopulateSpeciesOptions();
updateDetections();
updateReverseHighlight();
loaded.det = true; maybeFinalizeInit();
});
// 5-zone polygons (active on load)
fetch('blocks.geojson').then(r => r.json()).then(data => {
fiveLayerInstance = L.geoJSON(data, {
style: style5, onEachFeature: (feature, layer) => attachFeatureHandlers(feature, layer, true)
});
fiveZoneLayer.addLayer(fiveLayerInstance);
fiveZoneLayer.addTo(map);
currentBase = '5';
updateReverseHighlight();
loaded.five = true; maybeFinalizeInit();
});
// 30-zone polygons
fetch('nillumbik_30zones.geojson').then(r => r.json()).then(data => {
thirtyLayerInstance = L.geoJSON(data, {
style: style30, onEachFeature: (feature, layer) => attachFeatureHandlers(feature, layer, false)
});
thirtyZoneLayer.addLayer(thirtyLayerInstance);
updateReverseHighlight();
loaded.thirty = true; maybeFinalizeInit();
});
// Boundary + initial fit (show full Shire on load)
fetch('nillumbik_boundary.geojson')
.then(r => r.json())
.then(data => {
const boundaryLayer = L.geoJSON(data, { style: boundaryStyle }).addTo(map);
boundaryBounds = boundaryLayer.getBounds();
if (boundaryBounds) map.fitBounds(boundaryBounds, { padding: [20,20] });
loaded.boundary = true; maybeFinalizeInit();
});
// Base layer control (exclusive)
const baseMaps = { '5 Zones': fiveZoneLayer, '30 Zones': thirtyZoneLayer };
L.control.layers(baseMaps, null, { collapsed: false }).addTo(map);
map.on('baselayerchange', (e) => {
currentBase = (e.name.includes('30')) ? '30' : '5';
if (selectedLayers.length) clearAllSelections();
updateReverseHighlight();
});
// Apply URL state after everything is ready
function applyURLState() {
const qs = parseQuery();
// Fit to boundary by default (already done above)
// Layer
if (qs.layer === '30') {
if (map.hasLayer(fiveZoneLayer)) { map.removeLayer(fiveZoneLayer); }
if (!map.hasLayer(thirtyZoneLayer)) { thirtyZoneLayer.addTo(map); }
currentBase = '30';
} else {
if (map.hasLayer(thirtyZoneLayer)) { map.removeLayer(thirtyZoneLayer); }
if (!map.hasLayer(fiveZoneLayer)) { fiveZoneLayer.addTo(map); }
currentBase = '5';
}
// Filters
if ([...taxaFilterEl.options].some(o=>o.value===qs.taxa)) {
taxaFilterEl.value = qs.taxa;
repopulateSpeciesOptions();
if (qs.species && [...speciesFilterEl.options].some(o=>o.value===qs.species)) {
speciesFilterEl.value = qs.species;
}
}
updateDetections();
updateReverseHighlight();
// Selection for the active layer
if (qs.sel.length) {
const idSet = new Set(qs.sel);
const group = (currentBase === '5') ? fiveLayerInstance : thirtyLayerInstance;
selectedLayers = []; selectedZones = [];
group && group.eachLayer(layer => {
const zId = layer._zoneId;
if (idSet.has(zId)) {
addSelection(layer, zId, layer._isBlock);
} else {
applyMatchStyleToLayer(layer);
}
});
updateDetections();
}
// Map view override
if (qs.view) {
const parts = qs.view.split(',').map(Number);
if (parts.length === 3 && parts.every(x=>!Number.isNaN(x))) {
map.setView([parts[0], parts[1]], parts[2]);
}
}
}
</script>
</body>
</html>