From bd4622940e8c2739ccf3b862b3eb26eb4268402e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Fri, 11 Dec 2020 00:29:30 +0100 Subject: [PATCH] Call the finishCondition when drawing points / circles --- src/ol/interaction/Draw.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 5cd5f0e5a9..ac4f58de1c 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -625,19 +625,22 @@ class Draw extends PointerInteraction { this.handlePointerMove_(event); if (this.shouldHandle_) { - if (!this.finishCoordinate_) { - this.startDrawing_(event.coordinate); - if (this.mode_ === Mode.POINT) { + switch (true) { + case !this.finishCoordinate_: + this.startDrawing_(event.coordinate); + if (this.mode_ !== Mode.POINT) { + break; + } + // eslint-disable-next-line no-fallthrough + case this.freehand_ || + (this.atFinish_(event.pixel) && this.finishCondition_(event)): this.finishDrawing(); - } - } else if (this.freehand_) { - this.finishDrawing(); - } else if (this.atFinish_(event.pixel)) { - if (this.finishCondition_(event)) { - this.finishDrawing(); - } - } else { - this.addToDrawing_(event.coordinate); + break; + case !this.freehand_: + this.addToDrawing_(event.coordinate); + break; + default: + break; } pass = false; } else if (this.freehand_) { @@ -695,7 +698,11 @@ class Draw extends PointerInteraction { let potentiallyDone = false; let potentiallyFinishCoordinates = [this.finishCoordinate_]; const mode = this.mode_; - if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) { + if (mode === Mode.POINT) { + at = true; + } else if (mode === Mode.CIRCLE) { + at = this.sketchCoords_.length === 2; + } else if (mode === Mode.LINE_STRING) { potentiallyDone = this.sketchCoords_.length > this.minPoints_; } else if (mode === Mode.POLYGON) { const sketchCoords = /** @type {PolyCoordType} */ (this.sketchCoords_);