From 60513d7b4ab1338361141b6a32b14779649c9815 Mon Sep 17 00:00:00 2001 From: Suprita Naik Date: Tue, 11 Aug 2026 19:23:23 +0530 Subject: [PATCH] feat: add pollutant-specific map layers --- src/components/LocationMap.jsx | 59 +++++++++++++++++++++++++++++-- src/services/airQualityService.ts | 26 +++++++++++--- src/types/airQuality.ts | 7 ++++ 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/components/LocationMap.jsx b/src/components/LocationMap.jsx index 73c94ff..5ce4f8e 100644 --- a/src/components/LocationMap.jsx +++ b/src/components/LocationMap.jsx @@ -3,11 +3,21 @@ import { MapContainer, TileLayer, CircleMarker, Popup, Marker } from 'react-leaf import { useState, useEffect } from 'react'; import L from 'leaflet'; import { eventBus } from '../core/events'; +import { getPollutantColor } from '../services/airQualityService'; import PropTypes from "prop-types"; const COMMUNITY_REPORTS_STORAGE_KEY = 'pollution-community-reports'; const SYMPTOM_REPORTS_STORAGE_KEY = 'pollution-symptom-reports'; +const POLLUTANT_LAYERS = [ + { key: 'aqi', label: 'AQI' }, + { key: 'pm2_5', label: 'PM2.5', limit: 15 }, + { key: 'pm10', label: 'PM10', limit: 45 }, + { key: 'nitrogen_dioxide', label: 'NO₂', limit: 25 }, + { key: 'ozone', label: 'O₃', limit: 100 }, + { key: 'carbon_monoxide', label: 'CO', limit: 4000 }, +]; + function readGeotaggedCommunityReports() { try { const raw = localStorage.getItem(COMMUNITY_REPORTS_STORAGE_KEY); @@ -63,7 +73,7 @@ export default function LocationMap({ center, nearbyPoints, confidenceScore, win const [communityReports, setCommunityReports] = useState(() => readGeotaggedCommunityReports()); const [showSymptomReports, setShowSymptomReports] = useState(false); const [symptomReports, setSymptomReports] = useState(() => readGeotaggedSymptomReports()); - + const [selectedLayer, setSelectedLayer] = useState('aqi'); useEffect(() => { const updateReports = () => { setCommunityReports(readGeotaggedCommunityReports()); @@ -132,6 +142,15 @@ export default function LocationMap({ center, nearbyPoints, confidenceScore, win iconAnchor: [14, 14], }); + const activeLayer = POLLUTANT_LAYERS.find((l) => l.key === selectedLayer) || POLLUTANT_LAYERS[0]; + + const getMarkerColor = (point) => { + if (selectedLayer === 'aqi') { + return point.aqi > 150 ? '#b91c1c' : point.aqi > 100 ? '#f97316' : '#16a34a'; + } + return getPollutantColor(point.pollutants?.[selectedLayer], activeLayer.limit); + }; + return (
@@ -141,6 +160,30 @@ export default function LocationMap({ center, nearbyPoints, confidenceScore, win {windError &&

Wind data unavailable: {windError}

}
+