import { useMapStore } from "_store/mapStore"; import { Marker as LMarker } from "leaflet"; import { Ref, use, useEffect, useRef } from "react"; import { Marker, Polygon, Polyline, Popup } from "react-leaflet"; import L from "leaflet"; export const SearchElements = () => { const { searchElements, searchPopup, setSearchPopup } = useMapStore(); const poppupRef = useRef(null); useEffect(() => { if (searchPopup?.isOpen) { poppupRef.current?.openPopup(); } else { poppupRef.current?.closePopup(); } }, [searchPopup]); const SearchElement = ({ element, }: { element: (typeof searchElements)[1]; }) => { const ref = useRef(null); useEffect(() => { if (ref.current) { console.log(ref.current); ref.current.on("click", () => { console.log("click"); const center = ref.current.getBounds().getCenter(); setSearchPopup({ isOpen: true, lat: center.lat, lng: center.lng, elementId: element.id, }); console.log(element); }); } }, []); return ( [node.lat, node.lon])} color="#46b7a3" ref={ref} /> ); }; return ( <> {searchElements.map((element) => { return ; })} {searchPopup && (
test
)} ); };