air overlay: hide legend when inactive, fix script tag comment bug

This commit is contained in:
Kayos 2026-03-13 12:18:43 -07:00
parent 33cdc3a50c
commit 4cd65cc441

View file

@ -406,11 +406,6 @@
fetchAndPlot();
setInterval(fetchAndPlot, 60000);
// ============ AIR QUALITY OVERLAY (add to adamaps.org/index.html) ============
// Requires: leaflet-heat plugin
// Add to <head>:
// <script src="https://unpkg.com/leaflet.heat@0.2.0/dist/leaflet-heat.js"></script>
// 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'));
}