From 190b20ebce90dab848bbdbeee3600b4e62050c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 6 Dec 2020 15:23:36 +0100 Subject: [PATCH 1/2] Add vertex insertion test for modify interaction --- test/spec/ol/interaction/modify.test.js | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index 1cb46ba5b4..367033ce8c 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -423,6 +423,37 @@ describe('ol.interaction.Modify', function () { expect(lineFeature.getGeometry().getCoordinates().length).to.equal(5); }); + it('inserts one vertex into both linestrings with duplicate segments each', function () { + const lineFeature1 = new Feature( + new LineString([ + [-10, -10], + [10, 10], + [-10, -10], + ]) + ); + const lineFeature2 = new Feature( + new LineString([ + [10, 10], + [-10, -10], + [10, 10], + ]) + ); + features.length = 0; + features.push(lineFeature1, lineFeature2); + + const modify = new Modify({ + features: new Collection(features), + }); + map.addInteraction(modify); + + // Click on line + simulateEvent('pointermove', 0, 0, null, 0); + simulateEvent('pointerdown', 0, 0, null, 0); + simulateEvent('pointerup', 0, 0, null, 0); + + expect(lineFeature1.getGeometry().getCoordinates().length).to.be(4); + expect(lineFeature2.getGeometry().getCoordinates().length).to.be(4); + }); }); describe('circle modification', function () { From c4dd6e6b04df4d0a830f6fe680783ecde2b7d96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 6 Dec 2020 15:25:31 +0100 Subject: [PATCH 2/2] Fixes Modify vertex insertion with duplicate segments If one feature has duplicate segments it prevented insertion for other features with the same segment. --- src/ol/interaction/Modify.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index f12d6685c0..3c946bffc4 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -1097,14 +1097,16 @@ class Modify extends PointerInteraction { for (let i = 1, ii = nodes.length; i < ii; ++i) { const segment = nodes[i].segment; if ( - ((coordinatesEqual(closestSegment[0], segment[0]) && + (coordinatesEqual(closestSegment[0], segment[0]) && coordinatesEqual(closestSegment[1], segment[1])) || - (coordinatesEqual(closestSegment[0], segment[1]) && - coordinatesEqual(closestSegment[1], segment[0]))) && - !(getUid(nodes[i].geometry) in geometries) + (coordinatesEqual(closestSegment[0], segment[1]) && + coordinatesEqual(closestSegment[1], segment[0])) ) { - geometries[getUid(nodes[i].geometry)] = true; - vertexSegments[getUid(segment)] = true; + const geometryUid = getUid(nodes[i].geometry); + if (!(geometryUid in geometries)) { + geometries[geometryUid] = true; + vertexSegments[getUid(segment)] = true; + } } else { break; }