import { useMapStore } from "_store/mapStore"; import { Marker as LMarker } from "leaflet"; import { useEffect, useRef } from "react"; import { Marker, Polygon, Polyline, Popup } from "react-leaflet"; import L from "leaflet"; export const SearchElements = () => { const { searchElements, searchPopup, setSearchPopup, setContextMenu } = useMapStore(); const poppupRef = useRef(null); const intervalRef = useRef(null); const searchPopupElement = searchElements.find( (element) => element.id === searchPopup?.elementId, ); const SearchElement = ({ element, }: { element: (typeof searchElements)[1]; }) => { const ref = useRef(null); useEffect(() => { if (ref.current) { ref.current.on("click", () => { const center = ref.current.getBounds().getCenter(); if (searchPopup?.elementId !== element.id) { setSearchPopup({ lat: center.lat, lng: center.lng, elementId: element.id, }); } else { setSearchPopup(null); } setContextMenu(null); }); } }, []); return ( [node.lat, node.lon])} color={searchPopup?.elementId === element.id ? "#ff4500" : "#46b7a3"} ref={ref} /> ); }; const SearchElementPopup = ({ element, }: { element: (typeof searchElements)[1]; }) => { if (!searchPopup) return null; return (

{element.tags?.building === "yes" ? "Gebäude" : element.tags?.building} {!element.tags?.building && "unbekannt"}

{element.tags?.["addr:street"]} {element.tags?.["addr:housenumber"]}

{element.tags?.["addr:suburb"]} {element.tags?.["addr:postcode"]}

); }; console.log("searchPopupElement", searchPopupElement, searchPopup); return ( <> {searchElements.map((element) => { return ; })} {searchPopup && ( {!searchPopupElement && (
)}
)} {searchPopupElement && ( )} ); };