import maplibregl from "maplibre-gl"; import Map, { MapProvider } from "react-map-gl"; import { useEffect, useRef } from "react"; import { Sidebar } from "../modules/Sidebar/Sidebar"; import { Layers } from "./Layers"; import { MapPopup } from "./Popup"; import { Basemap } from "./Basemap"; import { SignOut } from "../SignOut"; import debounce from "lodash.debounce"; import { Table } from "../modules/Table/Table"; import { usePopup } from "../stores/usePopup"; import { useClickedPointConfig } from "../stores/useClickedPointConfig"; import { Legend } from "../modules/Sidebar/Legend"; import { AddressSearch } from "../modules/Sidebar/AddressSearch"; export const MapComponent = () => { const mapRef = useRef(null); const mapContainerRef = useRef(null); const { popup, setPopup } = usePopup(); const { setClickedPointConfig } = useClickedPointConfig(); const handleClick = (event) => { if (!event.features) { setPopup(null); setClickedPointConfig(null); return; } const feature = event.features[0]; if (!feature) { setPopup(null); setClickedPointConfig(null); return; } const { lng: pointLng } = event.lngLat; if (feature.geometry.type === "Point") { const coordinates = feature.geometry.coordinates.slice(); while (Math.abs(pointLng - coordinates[0]) > 180) { coordinates[0] += pointLng > coordinates[0] ? 360 : -360; } setPopup({ features: event.features, coordinates }); } }; const handleMouseEnter = (event) => { const feature = event.features[0]; if (!feature) return; mapRef.current.getCanvas().style.cursor = "pointer"; }; const handleMouseLeave = (event) => { const feature = event.features[0]; if (!feature) { return; } mapRef.current.getCanvas().style.cursor = ""; }; useEffect(() => { const resizeObserver = new ResizeObserver( debounce(() => { mapRef?.current?.resize(); }, 16) ); if (mapContainerRef.current) { resizeObserver.observe(mapContainerRef.current); } return () => { resizeObserver.disconnect(); }; }, [mapContainerRef.current]); return (
{popup && ( { setPopup(null); setClickedPointConfig(null); }} /> )}
); };