fixed live-display of CC using geojson
This commit is contained in:
@@ -235,9 +235,9 @@ const RettungsmittelTab = ({
|
|||||||
const livekitUser = participants.find((p) => (p.attributes.userId = aircraft.userId));
|
const livekitUser = participants.find((p) => (p.attributes.userId = aircraft.userId));
|
||||||
|
|
||||||
const lstName = useMemo(() => {
|
const lstName = useMemo(() => {
|
||||||
if (!aircraft.posLng || !aircraft.posLat) return;
|
if (!aircraft.posLng || !aircraft.posLat) return station.bosRadioArea;
|
||||||
return findLeitstelleForPosition(aircraft.posLng, aircraft.posLat);
|
return findLeitstelleForPosition(aircraft.posLng, aircraft.posLat);
|
||||||
}, [aircraft]);
|
}, [aircraft.posLng, aircraft.posLat]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4 text-base-content">
|
<div className="p-4 text-base-content">
|
||||||
|
|||||||
@@ -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
|
import leitstellenGeoJSON from "../_components/map/_geojson/Leitstellen.json"; // Pfad anpassen
|
||||||
|
|
||||||
export function findLeitstelleForPosition(lat: number, lng: number) {
|
export function findLeitstelleForPosition(lat: number, lng: number) {
|
||||||
const heliPoint = point([lat, lng]);
|
const heliPoint = point([lat, lng]);
|
||||||
|
|
||||||
for (const feature of (leitstellenGeoJSON as any).features) {
|
for (const feature of (leitstellenGeoJSON as any).features) {
|
||||||
if (feature.geometry.type === "MultiPolygon") {
|
const geom = feature.geometry;
|
||||||
const polygon = multiPolygon(feature.geometry.coordinates);
|
|
||||||
if (booleanPointInPolygon(heliPoint, polygon)) {
|
if (geom.type === "Polygon") {
|
||||||
console.log("Point is inside polygon:", feature.properties.name);
|
const turfPolygon = polygon(geom.coordinates);
|
||||||
return feature.properties.name ?? "Unbenannte Leitstelle";
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user