diff --git a/web/client/plugins/Annotations/utils/AnnotationsUtils.js b/web/client/plugins/Annotations/utils/AnnotationsUtils.js index 87df386570..3e2cba37ca 100644 --- a/web/client/plugins/Annotations/utils/AnnotationsUtils.js +++ b/web/client/plugins/Annotations/utils/AnnotationsUtils.js @@ -485,13 +485,15 @@ export const cleanPolygonCoordinates = (coordinates) => { }; export const parseUpdatedCoordinates = (geometryType, updatedCoordinates) => { + const hasHeight = !!updatedCoordinates.find((coords) => coords[2] !== undefined); + const coordinates = hasHeight ? updatedCoordinates.map(([lng, lat, height]) => [lng, lat, height === undefined ? 0 : height]) : updatedCoordinates; if (geometryType === 'Point') { - return updatedCoordinates[0]; + return coordinates[0]; } if (geometryType === 'Polygon') { - return cleanPolygonCoordinates([updatedCoordinates]); + return cleanPolygonCoordinates([coordinates]); } - return updatedCoordinates; + return coordinates; }; export const annotationsSymbolizerDefaultProperties = { diff --git a/web/client/plugins/Annotations/utils/__tests__/AnnotationsUtils-test.js b/web/client/plugins/Annotations/utils/__tests__/AnnotationsUtils-test.js index 60841aa833..f78c0a8eaf 100644 --- a/web/client/plugins/Annotations/utils/__tests__/AnnotationsUtils-test.js +++ b/web/client/plugins/Annotations/utils/__tests__/AnnotationsUtils-test.js @@ -552,7 +552,7 @@ describe('AnnotationsUtils', () => { expect(checkInvalidCoordinate(0)).toBe(false); }); it('parseUpdatedCoordinates', () => { - expect(parseUpdatedCoordinates('Polygon', [[[0, 0], [1, 1], [1, 0], [0, 0]]])).toEqual([ [ [ [ 0, 0 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ] ] ] ]); + expect(parseUpdatedCoordinates('Polygon', [[0, 0], [1, 1], [1, 0], [0, 0]])).toEqual([[[ 0, 0 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ]]]); expect(parseUpdatedCoordinates('LineString', [[0, 0], [1, 1], [1, 0]])).toEqual([[0, 0], [1, 1], [1, 0]]); expect(parseUpdatedCoordinates('Point', [[0, 0]])).toEqual([0, 0]); }); diff --git a/web/client/utils/cesium/ModifyGeoJSONInteraction.js b/web/client/utils/cesium/ModifyGeoJSONInteraction.js index 41d97710db..f30211f8ec 100644 --- a/web/client/utils/cesium/ModifyGeoJSONInteraction.js +++ b/web/client/utils/cesium/ModifyGeoJSONInteraction.js @@ -54,6 +54,10 @@ function featureToCartesianCoordinates(geometryType, feature) { } } +function updateCoordinatesHeight(coordinates) { + return coordinates.map(([lng, lat, height]) => [lng, lat, height === undefined ? 0 : height]); +} + function updateFeatureCoordinates(feature, updateCallback) { if (feature?.geometry === null) { return feature; @@ -65,7 +69,7 @@ function updateFeatureCoordinates(feature, updateCallback) { ...feature, geometry: { type: 'Point', - coordinates: [feature.geometry.coordinates].reduce(updateCallback, [])[0] + coordinates: updateCoordinatesHeight([feature.geometry.coordinates].reduce(updateCallback, []))[0] } }; case 'LineString': @@ -73,7 +77,7 @@ function updateFeatureCoordinates(feature, updateCallback) { ...feature, geometry: { type: 'LineString', - coordinates: feature.geometry.coordinates.reduce(updateCallback, []) + coordinates: updateCoordinatesHeight(feature.geometry.coordinates.reduce(updateCallback, [])) } }; case 'Polygon': @@ -81,7 +85,7 @@ function updateFeatureCoordinates(feature, updateCallback) { ...feature, geometry: { type: 'Polygon', - coordinates: [feature.geometry.coordinates[0].reduce(updateCallback, [])] + coordinates: [updateCoordinatesHeight(feature.geometry.coordinates[0].reduce(updateCallback, []))] } }; default: