From fad6d368a60fbfd2b5ec158e9755691c32a57d17 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 14 Oct 2016 18:10:20 -0600 Subject: [PATCH] Allow freehand drawing without a modifier key --- externs/olx.js | 10 ++++++++++ src/ol/interaction/draw.js | 17 +++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index d89440409a..a07c65f73d 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -2695,6 +2695,16 @@ olx.interaction.DrawOptions.prototype.geometryName; olx.interaction.DrawOptions.prototype.condition; +/** + * Operate in freehand mode for lines, polygons, and circles. This makes the + * interaction always operate in freehand mode and takes precedence over any + * `freehandCondition` option. + * @type {boolean|undefined} + * @api + */ +olx.interaction.DrawOptions.prototype.freehand; + + /** * Condition that activates freehand drawing for lines and polygons. This * function takes an {@link ol.MapBrowserEvent} and returns a boolean to diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index ffbf8f34f3..ad688a2c86 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -251,8 +251,13 @@ ol.interaction.Draw = function(options) { * @private * @type {ol.EventsConditionType} */ - this.freehandCondition_ = options.freehandCondition ? - options.freehandCondition : ol.events.condition.shiftKeyOnly; + this.freehandCondition_; + if (options.freehand) { + this.freehandCondition_ = ol.events.condition.always; + } else { + this.freehandCondition_ = options.freehandCondition ? + options.freehandCondition : ol.events.condition.shiftKeyOnly; + } ol.events.listen(this, ol.Object.getChangeEventType(ol.interaction.Interaction.Property.ACTIVE), @@ -319,15 +324,15 @@ ol.interaction.Draw.handleEvent = function(mapBrowserEvent) { * @private */ ol.interaction.Draw.handleDownEvent_ = function(event) { - if (this.condition_(event)) { - this.downPx_ = event.pixel; - return true; - } else if (this.freehand_) { + if (this.freehand_) { this.downPx_ = event.pixel; if (!this.finishCoordinate_) { this.startDrawing_(event); } return true; + } else if (this.condition_(event)) { + this.downPx_ = event.pixel; + return true; } else { return false; }