From 9f9fc49446d48df74c998df7ef84b7c0ea74cc51 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Sun, 8 Jun 2025 00:54:14 -0700 Subject: [PATCH] fixed live-display of CC using geojson --- .../map/_components/AircraftMarkerTabs.tsx | 4 +-- .../app/_helpers/findLeitstelleinPoint.ts | 25 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/dispatch/app/_components/map/_components/AircraftMarkerTabs.tsx b/apps/dispatch/app/_components/map/_components/AircraftMarkerTabs.tsx index fe91bd48..f1aca591 100644 --- a/apps/dispatch/app/_components/map/_components/AircraftMarkerTabs.tsx +++ b/apps/dispatch/app/_components/map/_components/AircraftMarkerTabs.tsx @@ -235,9 +235,9 @@ const RettungsmittelTab = ({ const livekitUser = participants.find((p) => (p.attributes.userId = aircraft.userId)); const lstName = useMemo(() => { - if (!aircraft.posLng || !aircraft.posLat) return; + if (!aircraft.posLng || !aircraft.posLat) return station.bosRadioArea; return findLeitstelleForPosition(aircraft.posLng, aircraft.posLat); - }, [aircraft]); + }, [aircraft.posLng, aircraft.posLat]); return (
diff --git a/apps/dispatch/app/_helpers/findLeitstelleinPoint.ts b/apps/dispatch/app/_helpers/findLeitstelleinPoint.ts index 3d047192..c4bfc5fd 100644 --- a/apps/dispatch/app/_helpers/findLeitstelleinPoint.ts +++ b/apps/dispatch/app/_helpers/findLeitstelleinPoint.ts @@ -1,18 +1,29 @@ -import { point, multiPolygon, booleanPointInPolygon } from "@turf/turf"; +import { point, multiPolygon, booleanPointInPolygon, booleanIntersects, polygon } from "@turf/turf"; import leitstellenGeoJSON from "../_components/map/_geojson/Leitstellen.json"; // Pfad anpassen export function findLeitstelleForPosition(lat: number, lng: number) { const heliPoint = point([lat, lng]); for (const feature of (leitstellenGeoJSON as any).features) { - if (feature.geometry.type === "MultiPolygon") { - const polygon = multiPolygon(feature.geometry.coordinates); - if (booleanPointInPolygon(heliPoint, polygon)) { - console.log("Point is inside polygon:", feature.properties.name); - return feature.properties.name ?? "Unbenannte Leitstelle"; + const geom = feature.geometry; + + if (geom.type === "Polygon") { + const turfPolygon = polygon(geom.coordinates); + if (booleanPointInPolygon(heliPoint, turfPolygon)) { + return feature.properties?.name ?? "Unbenannte Leitstelle"; } + } else if (geom.type === "MultiPolygon") { + // MultiPolygon: check each polygon + for (const coords of geom.coordinates) { + const turfPolygon = polygon(coords); + if (booleanPointInPolygon(heliPoint, turfPolygon)) { + return feature.properties?.name ?? "Unbenannte Leitstelle"; + } + } + } else { + continue; // Andere Geometrietypen ignorieren } } - return null; // Keine passende Leitstelle gefunden + return null; }