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')); }