From 1dfbf08442bbe7445c35cda9f6da7aa1083e4cbd Mon Sep 17 00:00:00 2001 From: Suren Date: Wed, 31 Jan 2024 18:45:57 +0530 Subject: [PATCH] #9937 - Fix: Circle radius is modified when saving the annotation (#9938) --- .../components/map/openlayers/Feature.jsx | 2 +- .../map/openlayers/__tests__/Feature-test.jsx | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/web/client/components/map/openlayers/Feature.jsx b/web/client/components/map/openlayers/Feature.jsx index bb4596b524..eaf155646a 100644 --- a/web/client/components/map/openlayers/Feature.jsx +++ b/web/client/components/map/openlayers/Feature.jsx @@ -89,7 +89,7 @@ export default class Feature extends React.Component { }); this._feature.map(f => { let newF = f; - if (f.getProperties().isCircle) { + if (f.getProperties().isCircle && !f.getProperties().isGeodesic) { newF = transformPolygonToCircle(f, props.crs || 'EPSG:3857', props.featuresCrs); newF.setGeometry(newF.getGeometry().transform(props.crs || 'EPSG:3857', props.featuresCrs)); } diff --git a/web/client/components/map/openlayers/__tests__/Feature-test.jsx b/web/client/components/map/openlayers/__tests__/Feature-test.jsx index 381fe40d57..a0b4ea8313 100644 --- a/web/client/components/map/openlayers/__tests__/Feature-test.jsx +++ b/web/client/components/map/openlayers/__tests__/Feature-test.jsx @@ -120,6 +120,92 @@ describe('Test Feature', () => { count = container.getSource().getFeatures().length; expect(count).toBe(0); }); + it('adding a feature of type circle and geodesic', () => { + let options = { + crs: 'EPSG:4326', + features: { + type: 'FeatureCollection', + crs: { + 'type': 'name', + 'properties': { + 'name': 'EPSG:4326' + } + }, + features: [ + { + type: 'Feature', + geometry: { + type: 'Polygon', + coordinates: [[ + [13, 43], + [15, 43], + [15, 44], + [13, 44] + ]] + }, + properties: { + 'name': "some name", + isGeodesic: true, + isCircle: true, + radius: 1000, + center: [13, 43] + } + } + ] + } + }; + let source = new VectorSource({ + features: [] + }); + const msId = "some value"; + let container = new VectorLayer({ + msId, + source: source, + visible: true, + zIndex: 1 + }); + const geometry = options.features.features[0].geometry; + const type = options.features.features[0].type; + let properties = {...options.features.features[0].properties, isGeodesic: false}; + + // create layers with feature visible + let layer = ReactDOM.render( + , document.getElementById("container")); + + expect(layer).toBeTruthy(); + // count layers + let [feature] = container.getSource().getFeatures(); + expect(feature).toBeTruthy(); + expect(feature.getGeometry().getType()).toBe('Circle'); + + properties = options.features.features[0].properties; + layer = ReactDOM.render( + , document.getElementById("container")); + + expect(layer).toExist(); + + [feature] = container.getSource().getFeatures(); + expect(feature).toBeTruthy(); + expect(feature.getGeometry().getType()).toBe('Polygon'); + }); it('adding a feature without a geometry', () => { var options = { crs: 'EPSG:4326',