import proj4 from 'proj4' ; import type { LatLngLiteral } from 'leaflet' ; import { RD , WGS84 } from '../../../pages/MapPage/legacy/services/crs-config' ; export interface Wsg84Coordinate { latitude : number ; longitude : number ; } export interface RdCoordinate { x : number ; y : number ; } param coordinate export function wgs84ToRd ( coordinate ) { const lng = 'lng' in coordinate ? coordinate . lng : coordinate . longitude ; const lat = 'lat' in coordinate ? coordinate . lat : coordinate . latitude ; const [ x , y ] = proj4 ( RD . projection , [ lng , lat ] ) ; return { x , y } ; } param coordinate export function rdToWgs84 ( coordinate ) { const [ longitude , latitude ] = proj4 ( RD . projection , WGS84 . projection , [ coordinate . x , coordinate . y ] ) ; return { latitude , longitude , } ; } export const parseLocationString = ( location ) => ( { lat : parseFloat ( location . split ( ',' ) [ 0 ] ) , lng : parseFloat ( location . split ( ',' ) [ 1 ] ) , } ) ; export const normalizeCoordinate = ( coordinate ? , precision ? ) => coordinate ? parseFloat ( coordinate . toFixed ( precision ) ) : 0 ; export const normalizeLocation = ( location , precision ? ) => Object . keys ( location ) . reduce ( ( acc , key ) => { acc [ key ] = normalizeCoordinate ( location [ key ] , precision ) ; return acc ; } , { } ) ;