Files
var-monorepo/apps/dispatch/app/_helpers/findLeitstelleinPoint.ts
2025-07-10 00:35:34 -07:00

30 lines
987 B
TypeScript

import { point, booleanPointInPolygon, 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 GeoJSON.FeatureCollection).features) {
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;
}