Fix modifying polygons with overlapping vertices

When a polygonal geometry, where one of the vertices overlaps the first
vertex in the same ring, is modified, ensure the correct vertices are
updated.
This commit is contained in:
Hubert Argasinski
2022-06-08 18:36:37 -04:00
parent d530435e2e
commit 5bcbd23cca
2 changed files with 68 additions and 5 deletions

View File

@@ -419,6 +419,52 @@ describe('ol.interaction.Modify', function () {
expect(lineFeature.getGeometry().getCoordinates()[2][2]).to.equal(30);
expect(lineFeature.getGeometry().getCoordinates()[4][2]).to.equal(50);
});
it('keeps polygon geometries valid', function () {
const overlappingVertexFeature = new Feature({
geometry: new Polygon([
[
[10, 20],
[0, 20],
[0, 0],
[20, 0],
[20, 20],
[10, 20],
[15, 15],
[5, 15],
[10, 20],
],
]),
});
features.length = 0;
features.push(overlappingVertexFeature);
const modify = new Modify({
features: new Collection(features),
});
map.addInteraction(modify);
let coords, exteriorRing;
coords = overlappingVertexFeature.getGeometry().getCoordinates();
exteriorRing = coords[0];
expect(exteriorRing.length).to.equal(9);
expect(exteriorRing[0]).to.eql(exteriorRing[exteriorRing.length - 1]);
// move the overlapping vertice
simulateEvent('pointermove', 10, -20, null, 0);
simulateEvent('pointerdown', 10, -20, null, 0);
simulateEvent('pointermove', 10, -25, null, 0);
simulateEvent('pointerdrag', 10, -25, null, 0);
simulateEvent('pointerup', 10, -25, null, 0);
coords = overlappingVertexFeature.getGeometry().getCoordinates();
exteriorRing = coords[0];
expect(exteriorRing.length).to.equal(9);
expect(exteriorRing[0]).to.eql([10, 25]);
expect(exteriorRing[0]).to.eql(exteriorRing[exteriorRing.length - 1]);
});
});
describe('vertex insertion', function () {