Skip to content

Commit

Permalink
fix height coordinates computation of annotation between 2D/3D
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Sep 11, 2023
1 parent b17e6a1 commit 30da897
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions web/client/plugins/Annotations/utils/AnnotationsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down
10 changes: 7 additions & 3 deletions web/client/utils/cesium/ModifyGeoJSONInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,23 +69,23 @@ 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':
return {
...feature,
geometry: {
type: 'LineString',
coordinates: feature.geometry.coordinates.reduce(updateCallback, [])
coordinates: updateCoordinatesHeight(feature.geometry.coordinates.reduce(updateCallback, []))
}
};
case 'Polygon':
return {
...feature,
geometry: {
type: 'Polygon',
coordinates: [feature.geometry.coordinates[0].reduce(updateCallback, [])]
coordinates: [updateCoordinatesHeight(feature.geometry.coordinates[0].reduce(updateCallback, []))]
}
};
default:
Expand Down

0 comments on commit 30da897

Please sign in to comment.