From edb3b5f4fd7981c7342cabfe0066be125d0f4471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Mon, 28 Sep 2020 16:10:11 +0200 Subject: [PATCH 1/3] The vertex is always the same, no need to store it with the segment --- src/ol/interaction/Modify.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 70d54e5696..86aa1a07dd 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -960,7 +960,7 @@ class Modify extends PointerInteraction { !componentSegments[uid][1] && this.insertVertexCondition_(evt) ) { - insertVertices.push([segmentDataMatch, vertex]); + insertVertices.push(segmentDataMatch); } } @@ -969,7 +969,7 @@ class Modify extends PointerInteraction { } for (let j = insertVertices.length - 1; j >= 0; --j) { - this.insertVertex_.apply(this, insertVertices[j]); + this.insertVertex_(insertVertices[j], vertex); } } return !!this.vertexFeature_; From bf33bd0703955b89ed240f6561e62d648dd6707d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Tue, 29 Sep 2020 10:51:24 +0200 Subject: [PATCH 2/3] Add Modify test for identical line segments of same geometry --- test/spec/ol/interaction/modify.test.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index 26e74ade28..1cb46ba5b4 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -398,6 +398,33 @@ describe('ol.interaction.Modify', function () { }); }); + describe('vertex insertion', function () { + it('only inserts one vertex per geometry', function () { + const lineFeature = new Feature({ + geometry: new LineString([ + [-10, -10], + [10, 10], + [-10, -10], + [10, 10], + ]), + }); + features.length = 0; + features.push(lineFeature); + + 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(lineFeature.getGeometry().getCoordinates().length).to.equal(5); + }); + }); + describe('circle modification', function () { it('changes the circle radius and center', function () { const circleFeature = new Feature(new Circle([10, 10], 20)); From 6a5c3bde6242a489c4c4337909111fe25b008c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Mon, 28 Sep 2020 16:43:28 +0200 Subject: [PATCH 3/3] Do not insert more than one point per geometry at once --- src/ol/interaction/Modify.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 86aa1a07dd..f12d6685c0 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -1070,6 +1070,7 @@ class Modify extends PointerInteraction { if (dist <= this.pixelTolerance_) { /** @type {Object} */ const vertexSegments = {}; + vertexSegments[getUid(closestSegment)] = true; if ( node.geometry.getType() === GeometryType.CIRCLE && @@ -1091,14 +1092,18 @@ class Modify extends PointerInteraction { : closestSegment[0]; } this.createOrUpdateVertexFeature_(vertex); + const geometries = {}; + geometries[getUid(node.geometry)] = true; 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])) + (coordinatesEqual(closestSegment[0], segment[1]) && + coordinatesEqual(closestSegment[1], segment[0]))) && + !(getUid(nodes[i].geometry) in geometries) ) { + geometries[getUid(nodes[i].geometry)] = true; vertexSegments[getUid(segment)] = true; } else { break; @@ -1106,7 +1111,6 @@ class Modify extends PointerInteraction { } } - vertexSegments[getUid(closestSegment)] = true; this.vertexSegments_ = vertexSegments; return; }