diff --git a/platform/src/common/components/Map/AirQoMap.jsx b/platform/src/common/components/Map/AirQoMap.jsx index 9380b48918..f968b2df6e 100644 --- a/platform/src/common/components/Map/AirQoMap.jsx +++ b/platform/src/common/components/Map/AirQoMap.jsx @@ -33,7 +33,7 @@ const mapStyles = [ { url: 'mapbox://styles/mapbox/satellite-v9', name: 'Satellite', image: SatelliteMode }, ]; -const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) => { +const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant, resizeMap }) => { const dispatch = useDispatch(); const mapContainerRef = useRef(null); const mapRef = useRef(null); @@ -48,6 +48,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) const [toastMessage, setToastMessage] = useState({ message: '', type: '', + bgColor: '', }); const [NodeType, setNodeType] = useState('Emoji'); const [selectedSite, setSelectedSite] = useState(null); @@ -60,10 +61,13 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) /** * Clear data on unmount * @sideEffect - * - Clear data + * - Clear data on unmount when lat, lng and zm are not present + * @returns {void} */ useEffect(() => { - dispatch(clearData()); + if (!lat && !lng && !zm) { + dispatch(clearData()); + } }, []); /** @@ -129,6 +133,13 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) /** * Initialize the map + * @sideEffect + * - Initialize the map + * - Add map controls + * - Load data + * - Update clusters + * - Fetch location boundaries + * @returns {void} */ useEffect(() => { const initializeMap = async () => { @@ -263,6 +274,12 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) const marker = new mapboxgl.Marker(el) .setLngLat(feature.geometry.coordinates) .addTo(map); + + // Add click event to zoom in when a user clicks on a cluster + el.addEventListener('click', () => { + map.flyTo({ center: feature.geometry.coordinates, zoom: zoom + 2 }); + }); + markers.push(marker); } }); @@ -287,6 +304,17 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) }; }, [mapStyle, mapboxApiAccessToken, refresh, pollutant, NodeType]); + /** + * Resize the map + * @sideEffect + * - Resizes the map when the window is resized and side bar is closed + */ + useEffect(() => { + if (!resizeMap) { + mapRef.current.resize(); + } + }, [!resizeMap]); + /** * Fetch location boundaries */ @@ -399,6 +427,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) setToastMessage({ message: 'Location URL copied to clipboard', type: 'success', + bgColor: 'bg-blue-600', }); } catch (error) { setToastMessage({ @@ -409,17 +438,14 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) }; return ( -
+
{/* Map */}
{/* Loader */} {refresh || (loading && ( -
+
@@ -478,7 +504,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant }) timeout={3000} dataTestId='map-toast' size='lg' - bgColor='bg-blue-600' + bgColor={toastMessage.bgColor} position='bottom' /> )} diff --git a/platform/src/common/components/Map/components/LayerModal.js b/platform/src/common/components/Map/components/LayerModal.js index 4c6d806f11..adeb77f187 100644 --- a/platform/src/common/components/Map/components/LayerModal.js +++ b/platform/src/common/components/Map/components/LayerModal.js @@ -35,7 +35,14 @@ const Option = ({ isSelected, children, onSelect, image, disabled }) => ( className={`w-14 h-14 relative rounded-lg ${ isSelected ? 'border-2 border-blue-500 ring-4 ring-light-blue-100' : '' } border-2`}> - {children} + {children}
{children} @@ -84,7 +91,7 @@ const LayerModal = ({ if (!isOpen) return null; return ( -
+