From 504e01f7bb80447cfbcf285295fa9a4e7113a459 Mon Sep 17 00:00:00 2001 From: Pascal Barth Date: Thu, 6 Jun 2024 17:54:39 +0200 Subject: [PATCH] PB-562 : do not force drawing module's style onto external KMLs forcing this resulted in KMLs being misrepresented, with colors not matching what was in the KML's data --- src/utils/__tests__/kmlUtils.spec.js | 6 +++- src/utils/__tests__/legacyKmlUtils.spec.js | 6 +++- src/utils/kmlUtils.js | 37 ++++++++++++---------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/utils/__tests__/kmlUtils.spec.js b/src/utils/__tests__/kmlUtils.spec.js index 3d6461f2f3..22cd0901dc 100644 --- a/src/utils/__tests__/kmlUtils.spec.js +++ b/src/utils/__tests__/kmlUtils.spec.js @@ -6,6 +6,7 @@ import { beforeEach, describe, it } from 'vitest' import { DrawingIcon, DrawingIconSet } from '@/api/icon.api' import KMLLayer from '@/api/layers/KMLLayer.class' +import { API_SERVICE_KML_BASE_URL } from '@/config.js' import { fakeIconSets } from '@/utils/__tests__/legacyKmlUtils.spec.js' import { WEBMERCATOR } from '@/utils/coordinates/coordinateSystems' import { BLUE } from '@/utils/featureStyleUtils' @@ -126,7 +127,10 @@ describe('Test KML utils', () => { beforeEach(() => { const kml = readFileSync(resolve(__dirname, './webmapviewerOffsetTestKml.kml'), 'utf8') - const kmlLayer = new KMLLayer({ kmlFileUrl: '', kmlData: kml }) + const kmlLayer = new KMLLayer({ + kmlFileUrl: API_SERVICE_KML_BASE_URL, // so that it is not considered external + kmlData: kml, + }) const olFeatures = parseKml(kmlLayer, WEBMERCATOR, fakeIconSets) features = olFeatures.map((f) => { const ef = f.get('editableFeature') diff --git a/src/utils/__tests__/legacyKmlUtils.spec.js b/src/utils/__tests__/legacyKmlUtils.spec.js index be2b0b59ff..d1d0220435 100644 --- a/src/utils/__tests__/legacyKmlUtils.spec.js +++ b/src/utils/__tests__/legacyKmlUtils.spec.js @@ -6,6 +6,7 @@ import { beforeEach, describe, it } from 'vitest' import { EditableFeatureTypes } from '@/api/features/EditableFeature.class' import { DrawingIcon, DrawingIconSet } from '@/api/icon.api' import KMLLayer from '@/api/layers/KMLLayer.class' +import { API_SERVICE_KML_BASE_URL } from '@/config.js' import { WEBMERCATOR } from '@/utils/coordinates/coordinateSystems' import { BLACK, @@ -111,7 +112,10 @@ describe('Validate deserialization of the mf-geoadmin3 viewer kml format', () => beforeEach(() => { const kml = readFileSync(resolve(__dirname, './mfgeoadmin3TestKml.kml'), 'utf8') - const kmlLayer = new KMLLayer({ kmlFileUrl: '', kmlData: kml }) + const kmlLayer = new KMLLayer({ + kmlFileUrl: API_SERVICE_KML_BASE_URL, // so that it is not considered external + kmlData: kml, + }) const olFeatures = parseKml(kmlLayer, WEBMERCATOR, fakeIconSets) features = olFeatures.map((f) => { const ef = f.get('editableFeature') diff --git a/src/utils/kmlUtils.js b/src/utils/kmlUtils.js index 771b205d13..fa06e2abb5 100644 --- a/src/utils/kmlUtils.js +++ b/src/utils/kmlUtils.js @@ -463,24 +463,27 @@ export function parseKml(kmlLayer, projection, iconSets) { dataProjection: WGS84.epsg, // KML files should always be in WGS84 featureProjection: projection.epsg, }) - features.forEach((olFeature) => { - const editableFeature = getEditableFeatureFromKmlFeature(olFeature, kmlLayer, iconSets) - - if (editableFeature) { - // Set the EditableFeature coordinates from the olFeature geometry - editableFeature.setCoordinatesFromFeature(olFeature) - olFeature.set('editableFeature', editableFeature) - olFeature.setStyle(featureStyleFunction) - - if (editableFeature.isLineOrMeasure()) { - /* The featureStyleFunction uses the geometries calculated in the geodesic object - if present. The lines connecting the vertices of the geometry will appear - geodesic (follow the shortest path) in this case instead of linear (be straight on - the screen) */ - olFeature.set('geodesic', new GeodesicGeometries(olFeature, projection)) + // we do not force our DrawingModule styling (especially colors) to external/non-drawing KMLs + if (!kmlLayer.isExternal) { + features.forEach((olFeature) => { + const editableFeature = getEditableFeatureFromKmlFeature(olFeature, kmlLayer, iconSets) + + if (editableFeature) { + // Set the EditableFeature coordinates from the olFeature geometry + editableFeature.setCoordinatesFromFeature(olFeature) + olFeature.set('editableFeature', editableFeature) + olFeature.setStyle(featureStyleFunction) + + if (editableFeature.isLineOrMeasure()) { + /* The featureStyleFunction uses the geometries calculated in the geodesic object + if present. The lines connecting the vertices of the geometry will appear + geodesic (follow the shortest path) in this case instead of linear (be straight on + the screen) */ + olFeature.set('geodesic', new GeodesicGeometries(olFeature, projection)) + } } - } - }) + }) + } return features }