From 99dd55920e7404e7d30420fc87f6dfa161945adb Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 7 Jan 2021 22:34:21 +0100 Subject: [PATCH] Restore stopClick functionality --- src/ol/interaction/Draw.js | 2 +- test/spec/ol/interaction/draw.test.js | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index ac4f58de1c..9818d2c223 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -649,7 +649,7 @@ class Draw extends PointerInteraction { } if (!pass && this.stopClick_) { - event.originalEvent.stopPropagation(); + event.stopPropagation(); } return pass; } diff --git a/test/spec/ol/interaction/draw.test.js b/test/spec/ol/interaction/draw.test.js index 6ef5f808a4..c7ed96369e 100644 --- a/test/spec/ol/interaction/draw.test.js +++ b/test/spec/ol/interaction/draw.test.js @@ -30,6 +30,7 @@ import { import {equals} from '../../../../src/ol/array.js'; import {listen} from '../../../../src/ol/events.js'; import {register} from '../../../../src/ol/proj/proj4.js'; +import {unByKey} from '../../../../src/ol/Observable.js'; describe('ol.interaction.Draw', function () { let target, map, source; @@ -97,6 +98,17 @@ describe('ol.interaction.Draw', function () { return simulatedEvent; } + function simulateBrowserEvent(type, x, y) { + const viewport = map.getViewport(); + // calculated in case body has top < 0 (test runner with small window) + const position = viewport.getBoundingClientRect(); + const evt = new PointerEvent(type, { + clientX: position.left + x + width / 2, + clientY: position.top + y + height / 2, + }); + (type === 'pointerup' ? document : map.getViewport()).dispatchEvent(evt); + } + describe('constructor', function () { it('creates a new interaction', function () { const draw = new Draw({ @@ -131,6 +143,24 @@ describe('ol.interaction.Draw', function () { }); expect(draw.dragVertexDelay_).to.be(42); }); + + it('accepts a stopClick option', function () { + const draw = new Draw({ + source: source, + type: 'Point', + stopClick: true, + }); + map.addInteraction(draw); + let clicked = false; + const clickKey = map.on('click', () => (clicked = true)); + simulateBrowserEvent('pointermove', 10, 20); + simulateBrowserEvent('pointerdown', 10, 20); + simulateBrowserEvent('pointerup', 10, 20); + //setTimeout(() => { + expect(clicked).to.be(false); + unByKey(clickKey); + //}, 300); + }); }); describe('specifying a geometryName', function () {