Skip to content

Commit

Permalink
#9319 - Fix: Exception when printing a annotation (Polygon) with modi…
Browse files Browse the repository at this point in the history
…fied vertices (#9444)
  • Loading branch information
dsuren1 authored Sep 20, 2023
1 parent bed8897 commit 5386433
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
19 changes: 19 additions & 0 deletions web/client/epics/__tests__/annotations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,25 @@ describe('annotations Epics', () => {
}]);
store.dispatch(action);

});
it('load annotations - polygon malformed', done => {
store.subscribe(() => {
const actions = store.getActions();
if (actions.length >= 2) {
expect(actions[1].type).toBe(UPDATE_NODE);
const [coordinate] = actions[1].options.features[0].features[0].geometry.coordinates;
expect(coordinate.length).toBe(6);
expect(coordinate[0]).toEqual(coordinate[coordinate.length - 1]);
done();
}
});
const coordinates = [[30.732623291015646, 43.136779336145906], [-22.91268615722654, 54.045449124395184], [12.895632934570349, 35.135869069174184], [21.890032959, 43.0816377459838], [-20.581082153320306, 35.501163186848196]];
const action = loadAnnotations([{
type: "FeatureCollection",
features: [{geometry: { coordinates: [coordinates], type: "Polygon"}}]
}], true);
store.dispatch(action);

});
it('load annotations and create layer', done => {
store = mockStore({
Expand Down
19 changes: 17 additions & 2 deletions web/client/epics/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ import {
STYLE_POINT_MARKER,
STYLE_POINT_SYMBOL,
DEFAULT_SHAPE,
DEFAULT_PATH, ANNOTATIONS
DEFAULT_PATH, ANNOTATIONS,
isCompletePolygon
} from '../utils/AnnotationsUtils';
import { MEASURE_TYPE } from '../utils/MeasurementUtils';
import { createSvgUrl } from '../utils/VectorStyleUtils';
Expand Down Expand Up @@ -565,7 +566,21 @@ export default {
const {messages = {}} = (getState()).locale || {};
const oldFeature = annotationsLayer && annotationsLayer.features || [];
const normFeatures = features.map((a) => normalizeAnnotation(a, messages));
const newFeatures = override ? normFeatures : oldFeature.concat(normFeatures);
let newFeatures = override ? normFeatures : oldFeature.concat(normFeatures);
newFeatures = newFeatures.map(newFeature => {
return {
...newFeature,
features: get(newFeature, 'features', []).map(feature => {
if (get(feature, 'geometry.type') === 'Polygon') {
let coordinates = get(feature, 'geometry.coordinates', []);
const isComplete = isCompletePolygon(coordinates);
coordinates = isComplete ? coordinates : [[...coordinates[0], coordinates[0][0]]];
return {...feature, geometry: {...feature?.geometry, coordinates}};
}
return feature;
})
};
});
const action = annotationsLayer ? updateNode(ANNOTATIONS, 'layer', {
features: removeDuplicate(newFeatures)}) : addLayer({
type: 'vector',
Expand Down
33 changes: 33 additions & 0 deletions web/client/reducers/__tests__/annotations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,39 @@ describe('Test the annotations reducer', () => {

expect(state.selected.properties).toNotEqual(state2.selected.properties);
});
it('changeSelected, geometry type polygon', () => {
const selected = {
properties: {
canEdit: true,
id: "259d79d0-053e-11ea-b0b3-379d853a3ff4",
isValidFeature: true
},
geometry: {
type: "Polygon",
coordinates: [[30.732623291015646, 43.136779336145906], [-23.91268615722654, 54.045449124395184], [12.895632934570349, 35.135869069174184], [21.890032959, 43.0816377459838], [-20.581082153320306, 35.501163186848196]]
}
};
const featureColl = {
type: "FeatureCollection",
features: [selected],
tempFeatures: [],
properties: {
id: '1asdfads'
},
style: {}
};
const coordinates = [[30.732623291015646, 43.136779336145906], [-22.91268615722654, 54.045449124395184], [12.895632934570349, 35.135869069174184], [21.890032959, 43.0816377459838], [-20.581082153320306, 35.501163186848196]];
const state = annotations({
editing: featureColl,
selected,
featureType: "Polygon",
unsavedGeometry: true
}, changeSelected(coordinates, 3567, null, "EPSG:3857"));

expect(state.selected.geometry.coordinates).toNotEqual(coordinates);
const [coordinate] = state.selected.geometry.coordinates;
expect(coordinate[0]).toEqual(coordinate[coordinate.length - 1]); // first and last vertices are equal
});
it('UPDATE_SYMBOLS', () => {
let annotationsState = annotations({}, updateSymbols());
expect(annotationsState.symbolList.length).toBe(0);
Expand Down
18 changes: 12 additions & 6 deletions web/client/reducers/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
getAvailableStyler,
getBaseCoord,
getComponents, getGeometryType,
isCompletePolygon,
updateAllStyles,
validateCoordsArray,
validateFeature
Expand Down Expand Up @@ -115,13 +116,18 @@ function annotations(state = {validationErrors: {}}, action) {
}
if (!isNil(coordinates)) {

validCoordinates = coordinates;// .filter(validateCoordsArray);
validCoordinates = coordinates;
switch (ftChanged.geometry.type) {
case "Polygon": ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: fixCoordinates(validCoordinates, ftChanged.geometry.type)
})
}); break;
case "Polygon":
let _coordinates = fixCoordinates(validCoordinates, ftChanged.geometry.type);
const isComplete = isCompletePolygon(_coordinates);
_coordinates = isComplete ? _coordinates : [[..._coordinates[0], _coordinates[0][0]]];
coordinates = _coordinates[0];
ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: _coordinates
})
}); break;
case "LineString": case "MultiPoint": ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: fixCoordinates(validCoordinates, ftChanged.geometry.type)
Expand Down

0 comments on commit 5386433

Please sign in to comment.