air overlay: hide legend when inactive, fix script tag comment bug
This commit is contained in:
parent
47c608f98e
commit
d2684efa1a
1 changed files with 6 additions and 6 deletions
|
|
@ -406,11 +406,6 @@
|
||||||
fetchAndPlot();
|
fetchAndPlot();
|
||||||
setInterval(fetchAndPlot, 60000);
|
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
|
// AQI color gradient: green→yellow→orange→red→purple
|
||||||
const AQI_GRADIENT = {
|
const AQI_GRADIENT = {
|
||||||
0.0: '#00e400', // Good (0-50)
|
0.0: '#00e400', // Good (0-50)
|
||||||
|
|
@ -478,6 +473,7 @@ async function toggleAirOverlay(metric) {
|
||||||
btnAqi.classList.remove('active');
|
btnAqi.classList.remove('active');
|
||||||
btnPm25.classList.remove('active');
|
btnPm25.classList.remove('active');
|
||||||
statusEl.textContent = 'live · ' + new Date().toLocaleTimeString();
|
statusEl.textContent = 'live · ' + new Date().toLocaleTimeString();
|
||||||
|
if (airLegend) { map.removeControl(airLegend); airLegend = null; }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,6 +505,9 @@ async function toggleAirOverlay(metric) {
|
||||||
|
|
||||||
layer.addTo(map);
|
layer.addTo(map);
|
||||||
statusEl.textContent = `${metric.toUpperCase()} overlay · ${points.length.toLocaleString()} pts`;
|
statusEl.textContent = `${metric.toUpperCase()} overlay · ${points.length.toLocaleString()} pts`;
|
||||||
|
|
||||||
|
// Show legend when overlay is active
|
||||||
|
if (!airLegend) { airLegend = buildAirLegend(); airLegend.addTo(map); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Legend ────────────────────────────────────────────────────────────────────
|
// ── Legend ────────────────────────────────────────────────────────────────────
|
||||||
|
|
@ -530,9 +529,10 @@ function buildAirLegend() {
|
||||||
return legend;
|
return legend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let airLegend = null;
|
||||||
|
|
||||||
// Call this after map init — wires up buttons and legend
|
// Call this after map init — wires up buttons and legend
|
||||||
function initAirOverlay() {
|
function initAirOverlay() {
|
||||||
buildAirLegend().addTo(map);
|
|
||||||
btnAqi.addEventListener('click', () => toggleAirOverlay('aqi'));
|
btnAqi.addEventListener('click', () => toggleAirOverlay('aqi'));
|
||||||
btnPm25.addEventListener('click', () => toggleAirOverlay('pm25'));
|
btnPm25.addEventListener('click', () => toggleAirOverlay('pm25'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue