From 08a118cc9417d86c38e73e03634f7bbeb872259f Mon Sep 17 00:00:00 2001 From: Thomas Chandelle Date: Thu, 16 Feb 2017 16:52:04 +0100 Subject: [PATCH] Determine if we should handle the drawing when the pointer is moving --- src/ol/interaction/draw.js | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index 2b40080802..840c6f6342 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -44,6 +44,12 @@ ol.interaction.Draw = function(options) { handleUpEvent: ol.interaction.Draw.handleUpEvent_ }); + /** + * @type {boolean} + * @private + */ + this.shouldHandle_ = false; + /** * @type {ol.Pixel} * @private @@ -325,6 +331,8 @@ ol.interaction.Draw.handleEvent = function(event) { * @private */ ol.interaction.Draw.handleDownEvent_ = function(event) { + this.shouldHandle_ = !this.freehand_; + if (this.freehand_) { this.downPx_ = event.pixel; if (!this.finishCoordinate_) { @@ -347,18 +355,13 @@ ol.interaction.Draw.handleDownEvent_ = function(event) { * @private */ ol.interaction.Draw.handleUpEvent_ = function(event) { - var downPx = this.downPx_; - var clickPx = event.pixel; - var dx = downPx[0] - clickPx[0]; - var dy = downPx[1] - clickPx[1]; - var squaredDistance = dx * dx + dy * dy; var pass = true; - var shouldHandle = this.freehand_ ? - squaredDistance > this.squaredClickTolerance_ : - squaredDistance <= this.squaredClickTolerance_; + + this.handlePointerMove_(event); + var circleMode = this.mode_ === ol.interaction.Draw.Mode_.CIRCLE; - if (shouldHandle) { - this.handlePointerMove_(event); + + if (this.shouldHandle_) { if (!this.finishCoordinate_) { this.startDrawing_(event); if (this.mode_ === ol.interaction.Draw.Mode_.POINT) { @@ -374,7 +377,7 @@ ol.interaction.Draw.handleUpEvent_ = function(event) { this.addToDrawing_(event); } pass = false; - } else if (circleMode && this.freehand_) { + } else if (this.freehand_) { this.finishCoordinate_ = null; this.abortDrawing_(); } @@ -389,6 +392,19 @@ ol.interaction.Draw.handleUpEvent_ = function(event) { * @private */ ol.interaction.Draw.prototype.handlePointerMove_ = function(event) { + if (this.downPx_ && + ((!this.freehand_ && this.shouldHandle_) || + (this.freehand_ && !this.shouldHandle_))) { + var downPx = this.downPx_; + var clickPx = event.pixel; + var dx = downPx[0] - clickPx[0]; + var dy = downPx[1] - clickPx[1]; + var squaredDistance = dx * dx + dy * dy; + this.shouldHandle_ = this.freehand_ ? + squaredDistance > this.squaredClickTolerance_ : + squaredDistance <= this.squaredClickTolerance_; + } + if (this.finishCoordinate_) { this.modifyDrawing_(event); } else {