From 6bada6ab984dc24b38efe28665147fd264af9ab7 Mon Sep 17 00:00:00 2001 From: Greg Gianforcaro Date: Sat, 23 Nov 2019 16:11:27 -0500 Subject: [PATCH] Add test modifying circle with snap enabled --- test/spec/ol/interaction/modify.test.js | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index ed51f51ec5..7deae8d5d7 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -9,6 +9,7 @@ import LineString from '../../../../src/ol/geom/LineString.js'; import Point from '../../../../src/ol/geom/Point.js'; import Polygon from '../../../../src/ol/geom/Polygon.js'; import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js'; +import Snap from '../../../../src/ol/interaction/Snap.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorSource from '../../../../src/ol/source/Vector.js'; import Event from '../../../../src/ol/events/Event.js'; @@ -737,4 +738,43 @@ describe('ol.interaction.Modify', function() { }); }); + describe('circle modification with snap', function() { + it('changes the circle radius and center', function() { + const circleFeature = new Feature(new Circle([10, 10], 20)); + features.length = 0; + features.push(circleFeature); + + const modify = new Modify({ + features: new Collection(features) + }); + map.addInteraction(modify); + + const snap = new Snap({ + features: new Collection(features), + pixelTolerance: 1 + }); + map.addInteraction(snap); + + // Change center + simulateEvent('pointermove', 10, -10, null, 0); + simulateEvent('pointerdown', 10, -10, null, 0); + simulateEvent('pointermove', 5, -5, null, 0); + simulateEvent('pointerdrag', 5, -5, null, 0); + simulateEvent('pointerup', 5, -5, null, 0); + + expect(circleFeature.getGeometry().getRadius()).to.equal(20); + expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]); + + // Increase radius + simulateEvent('pointermove', 25, -4, null, 0); + simulateEvent('pointerdown', 25, -4, null, 0); + simulateEvent('pointermove', 30, -5, null, 0); + simulateEvent('pointerdrag', 30, -5, null, 0); + simulateEvent('pointerup', 30, -5, null, 0); + + expect(circleFeature.getGeometry().getRadius()).to.equal(25); + expect(circleFeature.getGeometry().getCenter()).to.eql([5, 5]); + }); + }); + });