Skip to content

Commit

Permalink
#9937 - Fix: Circle radius is modified when saving the annotation (#9938
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsuren1 authored Jan 31, 2024
1 parent 4cf4769 commit 1dfbf08
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/client/components/map/openlayers/Feature.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
86 changes: 86 additions & 0 deletions web/client/components/map/openlayers/__tests__/Feature-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Feature
options={options}
geometry={geometry}
type={type}
properties={properties}
msId={msId}
container={container}
featuresCrs={"EPSG:4326"}
crs={"EPSG:3857"}
/>, 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(
<Feature
options={options}
geometry={geometry}
type={type}
properties={properties}
msId={msId}
container={container}
featuresCrs={"EPSG:4326"}
crs={"EPSG:3857"}
/>, 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',
Expand Down

0 comments on commit 1dfbf08

Please sign in to comment.