From 4cd65cc441804861b68798b801de1c9e3b1f1afc Mon Sep 17 00:00:00 2001 From: Kayos Date: Fri, 13 Mar 2026 12:18:43 -0700 Subject: [PATCH] air overlay: hide legend when inactive, fix script tag comment bug --- docs/adamaps-index-preview.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/adamaps-index-preview.html b/docs/adamaps-index-preview.html index 495e946..a8ff7b1 100644 --- a/docs/adamaps-index-preview.html +++ b/docs/adamaps-index-preview.html @@ -406,11 +406,6 @@ fetchAndPlot(); setInterval(fetchAndPlot, 60000); -// ============ AIR QUALITY OVERLAY (add to adamaps.org/index.html) ============ -// Requires: leaflet-heat plugin -// Add to : -// - // AQI color gradient: green→yellow→orange→red→purple const AQI_GRADIENT = { 0.0: '#00e400', // Good (0-50) @@ -478,6 +473,7 @@ async function toggleAirOverlay(metric) { btnAqi.classList.remove('active'); btnPm25.classList.remove('active'); statusEl.textContent = 'live · ' + new Date().toLocaleTimeString(); + if (airLegend) { map.removeControl(airLegend); airLegend = null; } return; } @@ -509,6 +505,9 @@ async function toggleAirOverlay(metric) { layer.addTo(map); statusEl.textContent = `${metric.toUpperCase()} overlay · ${points.length.toLocaleString()} pts`; + + // Show legend when overlay is active + if (!airLegend) { airLegend = buildAirLegend(); airLegend.addTo(map); } } // ── Legend ──────────────────────────────────────────────────────────────────── @@ -530,9 +529,10 @@ function buildAirLegend() { return legend; } +let airLegend = null; + // Call this after map init — wires up buttons and legend function initAirOverlay() { - buildAirLegend().addTo(map); btnAqi.addEventListener('click', () => toggleAirOverlay('aqi')); btnPm25.addEventListener('click', () => toggleAirOverlay('pm25')); }