"use client"; import { usePannelStore } from "_store/pannelStore"; import { Control, Icon, LatLngExpression } from "leaflet"; import { useEffect, useRef, useState } from "react"; import { LayerGroup, LayersControl, TileLayer, useMap, WMSTileLayer, GeoJSON, Circle, useMapEvent, FeatureGroup, Marker, Tooltip, } from "react-leaflet"; // @ts-ignore import type { FeatureCollection, Geometry } from "geojson"; import L from "leaflet"; import LEITSTELLENBERECHE from "./_geojson/Leitstellen.json"; import WINDFARMS from "./_geojson/Windfarms.json"; import { createCustomMarker } from "_components/map/_components/createCustomMarker"; import { Station } from "@repo/db"; import { useQuery } from "@tanstack/react-query"; import { getStationsAPI } from "_querys/stations"; import "./darkMapStyles.css"; const RadioAreaLayer = () => { const getColor = (randint: number) => { switch (randint) { case 1: return "#2b6eff"; case 2: return "#233ee5"; case 3: return "#7BA5FF"; case 4: return "#5087FF"; default: return "#7f7f7f"; } }; return ( } style={(feature) => { if (!feature || !feature.properties) return {}; // Early return if feature or its properties are undefined return { color: getColor(feature.properties.randint), weight: 1.5, className: "no-pointer", }; }} onEachFeature={(feature, layer) => { if (feature && feature.properties && feature.properties.name) { layer.bindTooltip( new L.Tooltip({ content: feature.properties.name, direction: "top", sticky: true, }), ); } }} /> ); }; const StationsLayer = ({ attribution }: { attribution: Control.Attribution }) => { const { data: stations } = useQuery({ queryKey: ["stations"], queryFn: () => getStationsAPI(), }); const [selectedStations, setSelectedStations] = useState([]); const [stationsWithIcon, setStationsWithIcon] = useState<(Station & { icon?: string })[]>([]); // Zustand für die Stationen mit Icon const attributionText = ""; const resetSelection = () => { setSelectedStations([]); }; useMapEvent("click", () => { resetSelection(); }); const handleMarkerClick = (stationId: number) => { if (selectedStations.includes(stationId)) { setSelectedStations((prevStations) => prevStations.filter((s) => s !== stationId)); } else { setSelectedStations((prevStations) => [...prevStations, stationId]); } }; useEffect(() => { // Erstelle die Icons für alle Stationen const fetchIcons = async () => { if (!stations) return; const urls = await Promise.all( stations.map(async (station) => { return createCustomMarker(station.operator); }), ); setStationsWithIcon(stations.map((station, index) => ({ ...station, icon: urls[index] }))); }; fetchIcons(); }, [stations]); return ( {stationsWithIcon.map((station) => { const coordinates: LatLngExpression = [station.latitude, station.longitude]; const typeLabel = station.bosUse.charAt(0).toUpperCase(); return ( { if (!station.hideRangeRings) handleMarkerClick(station.id); }, add: () => attribution.addAttribution(attributionText), remove: () => attribution.removeAttribution(attributionText), }} >
{station.bosCallsign} {` (${typeLabel})`}
{[ station.hasWinch ? "W" : null, station.is24h ? "24h" : null, station.hasNvg ? "N" : null, ] .filter(Boolean) .join(", ")}
); })} {selectedStations.map((stationId) => { const station = stations?.find((s) => s.id === stationId); if (!station) return null; const center: LatLngExpression = [station.latitude, station.longitude]; return (
{(station.bosUse === "SECONDARY" || station.bosUse === "DUAL_USE") && ( )}
); })}
); }; const EsriSatellite = ({ attribution }: { attribution: Control.Attribution }) => { const accessToken = process.env.NEXT_PUBLIC_ESRI_ACCESS; return ( <> {/* Satellite Imagery Layer; API KEY PROVIDED BY VAR0002 */} ); }; const StrassentexteEsri = () => { return ( ); }; const OpenAIP = ({ attribution }: { attribution: Control.Attribution }) => { const accessToken = process.env.NEXT_PUBLIC_OPENAIP_ACCESS; const ref = useRef(null); return ( { if (ref.current) { ref.current.bringToFront(); } }, }} ref={ref} attribution='© OpenAIP' url={`https://api.tiles.openaip.net/api/data/openaip/{z}/{x}/{y}.png?apiKey=${process.env.NEXT_PUBLIC_OPENAIP_ACCESS}`} /> ); }; const NiederschlagOverlay = ({ attribution }: { attribution: Control.Attribution }) => { const tileLayerRef = useRef(null); return ( { tileLayerRef.current?.bringToFront(); }, }} attribution="Quelle: Deutscher Wetterdienst" url="https://maps.dwd.de/geoserver/wms?" format="image/png" layers="dwd:Niederschlagsradar" transparent opacity={0.7} /> ); }; const WindfarmOutlineLayer = () => { const map = useMap(); const [isVisible, setIsVisible] = useState(false); useEffect(() => { const handleZoom = () => { setIsVisible(map.getZoom() < 13); }; // Initial check and event listener handleZoom(); map.on("zoomend", handleZoom); // Cleanup on unmount return () => { map.off("zoomend", handleZoom); }; }, [map]); return isVisible ? ( } style={() => ({ color: "#233EE5", weight: 1.5, dashArray: "7, 10", className: "no-pointer", })} onEachFeature={(feature, layer) => { layer.bindTooltip( new L.Tooltip({ content: feature.properties.Cluster_NR, direction: "top", sticky: true, }), ); }} /> ) : null; }; export const BaseMaps = () => { const map = useMap(); const isPannelOpen = usePannelStore((state) => state.isOpen); useEffect(() => { setTimeout(() => { map.invalidateSize(); }, 600); }, [isPannelOpen]); return ( ); };