From 3d9dfe2654f5d29e13bc9929a42d5049c927cc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ziela=C5=84ski?= Date: Mon, 29 Jun 2020 10:48:17 +0200 Subject: [PATCH] By modifying the common vertex, not all geometries were changed when the geometries were aggregated in the collection --- examples/modify-test.js | 19 ++++-- src/ol/interaction/Modify.js | 2 +- test/spec/ol/interaction/modify.test.js | 84 +++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/examples/modify-test.js b/examples/modify-test.js index ef141d096e..13f6b17384 100644 --- a/examples/modify-test.js +++ b/examples/modify-test.js @@ -212,10 +212,21 @@ const geojsonObject = { 'type': 'Polygon', 'coordinates': [ [ - [1e6, -6e6], - [2e6, -4e6], - [3e6, -6e6], - [1e6, -6e6], + [1e6, -5e6], + [2e6, -3.5e6], + [3e6, -5e6], + [1e6, -5e6], + ], + ], + }, + { + 'type': 'Polygon', + 'coordinates': [ + [ + [1e6, -5e6], + [2e6, -6.5e6], + [3e6, -5e6], + [1e6, -5e6], ], ], }, diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 117340865d..70d54e5696 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -897,7 +897,7 @@ class Modify extends PointerInteraction { for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) { const segmentDataMatch = segmentDataMatches[i]; const segment = segmentDataMatch.segment; - let uid = getUid(segmentDataMatch.feature); + let uid = getUid(segmentDataMatch.geometry); const depth = segmentDataMatch.depth; if (depth) { uid += '-' + depth.join('-'); // separate feature components diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index af4efd9aca..26e74ade28 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -2,6 +2,7 @@ import Circle from '../../../../src/ol/geom/Circle.js'; import Collection from '../../../../src/ol/Collection.js'; import Event from '../../../../src/ol/events/Event.js'; import Feature from '../../../../src/ol/Feature.js'; +import GeometryCollection from '../../../../src/ol/geom/GeometryCollection.js'; import LineString from '../../../../src/ol/geom/LineString.js'; import Map from '../../../../src/ol/Map.js'; import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; @@ -602,6 +603,89 @@ describe('ol.interaction.Modify', function () { }); }); + describe('geometry collection modification', function () { + it('all geometries should be modified', function () { + const firstPolygon = new Polygon([ + [ + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0], + ], + ]); + const secondPolygon = firstPolygon.clone(); + + const firstLineString = new LineString([ + [-2, 0], + [0, 0], + [2, 0], + ]); + const secondLineString = new LineString([ + [0, 2], + [0, 0], + [0, -2], + ]); + + const point = new Point([0, 0]); + + const circle = new Circle([0, 0], 1); + + const geometryCollection = new GeometryCollection([ + firstPolygon, + secondPolygon, + firstLineString, + secondLineString, + point, + circle, + ]); + + const feature = new Feature({ + geometry: geometryCollection, + }); + + features.length = 0; + features.push(feature); + + const modify = new Modify({ + features: new Collection(features), + }); + map.addInteraction(modify); + + // Move vertex + simulateEvent('pointermove', 0, 0, null, 0); + simulateEvent('pointerdown', 0, 0, null, 0); + simulateEvent('pointermove', -1, 0, null, 0); + simulateEvent('pointerdrag', -1, 0, null, 0); + simulateEvent('pointerup', -1, 0, null, 0); + + let geomCoords; + geomCoords = firstPolygon.getCoordinates()[0]; + expect(geomCoords[0][0]).to.equal(-1); + expect(geomCoords[0][1]).to.equal(0); + + geomCoords = secondPolygon.getCoordinates()[0]; + expect(geomCoords[0][0]).to.equal(-1); + expect(geomCoords[0][1]).to.equal(0); + + geomCoords = firstLineString.getCoordinates(); + expect(geomCoords[1][0]).to.equal(-1); + expect(geomCoords[1][1]).to.equal(0); + + geomCoords = secondLineString.getCoordinates(); + expect(geomCoords[1][0]).to.equal(-1); + expect(geomCoords[1][1]).to.equal(0); + + geomCoords = point.getCoordinates(); + expect(geomCoords[0]).to.equal(-1); + expect(geomCoords[1]).to.equal(0); + + geomCoords = circle.getCenter(); + expect(geomCoords[0]).to.equal(-1); + expect(geomCoords[1]).to.equal(0); + }); + }); + describe('double click deleteCondition', function () { let modify, feature, events;