@@ -8,7 +8,7 @@ import type { Type as GeometryType } from 'ol/geom/Geometry'
88import type { Size } from 'ol/size'
99import type Style from 'ol/style/Style'
1010
11- import { WGS84 } from '@swissgeo/coordinates'
11+ import { registerProj4 , WGS84 } from '@swissgeo/coordinates'
1212import { KMLStyle } from '@swissgeo/layers'
1313import log , { LogPreDefinedColor } from '@swissgeo/log'
1414import {
@@ -26,7 +26,9 @@ import {
2626} from 'ol/extent'
2727import GeoJSON from 'ol/format/GeoJSON'
2828import KML , { getDefaultStyle } from 'ol/format/KML'
29+ import { register } from 'ol/proj/proj4'
2930import IconStyle from 'ol/style/Icon'
31+ import proj4 from 'proj4'
3032
3133import type {
3234 EditableFeature ,
@@ -758,6 +760,17 @@ function parseKml(
758760 const kmlData = kmlLayer . kmlData
759761 const files = kmlLayer . internalFiles
760762
763+ // Register projections with proj4 only if they're not already defined
764+ const projectionDefined = proj4 . defs ( projection . epsg )
765+ const wgs84Defined = proj4 . defs ( WGS84 . epsg )
766+
767+ if ( ! projectionDefined || ! wgs84Defined ) {
768+ // Register all Swiss projections (LV95, LV03, WebMercator) with proj4
769+ registerProj4 ( proj4 )
770+ // Register proj4 with OpenLayers
771+ register ( proj4 )
772+ }
773+
761774 const features = new KML ( {
762775 iconUrlFunction : ( url : string ) => handleIconUrl ( url , iconUrlProxy , files ) ,
763776 } ) . readFeatures ( kmlData , {
0 commit comments