Skip to content

Commit 2763530

Browse files
committed
PB-2064: fix add necessary projections to kmlUtils parseKml
1 parent 88c2ce5 commit 2763530

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/api/src/utils/kmlUtils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Type as GeometryType } from 'ol/geom/Geometry'
88
import type { Size } from 'ol/size'
99
import type Style from 'ol/style/Style'
1010

11-
import { WGS84 } from '@swissgeo/coordinates'
11+
import { registerProj4, WGS84 } from '@swissgeo/coordinates'
1212
import { KMLStyle } from '@swissgeo/layers'
1313
import log, { LogPreDefinedColor } from '@swissgeo/log'
1414
import {
@@ -26,7 +26,9 @@ import {
2626
} from 'ol/extent'
2727
import GeoJSON from 'ol/format/GeoJSON'
2828
import KML, { getDefaultStyle } from 'ol/format/KML'
29+
import { register } from 'ol/proj/proj4'
2930
import IconStyle from 'ol/style/Icon'
31+
import proj4 from 'proj4'
3032

3133
import 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

Comments
 (0)