frontend_nyla/src/components/UiComponents/MapView/LV95Converter.ts
2025-12-01 17:01:25 +01:00

25 lines
878 B
TypeScript

import proj4 from 'proj4';
// Define LV95 projection (EPSG:2056) and WGS84 (EPSG:4326)
// LV95 / Swiss TM 35
const LV95_PROJ = '+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs';
const WGS84_PROJ = 'EPSG:4326';
/**
* Convert LV95 coordinates to WGS84 (lat/lon)
* Uses proj4 for accurate coordinate transformation
*/
export function lv95ToWGS84(x: number, y: number): { lat: number; lon: number } {
const [lon, lat] = proj4(LV95_PROJ, WGS84_PROJ, [x, y]);
return { lat, lon };
}
/**
* Convert WGS84 (lat/lon) to LV95 coordinates
* Uses proj4 for accurate coordinate transformation
*/
export function wgs84ToLV95(lat: number, lon: number): { x: number; y: number } {
const [x, y] = proj4(WGS84_PROJ, LV95_PROJ, [lon, lat]);
return { x, y };
}