diff --git a/externs/olx.js b/externs/olx.js index ee208c49fe..32dadbe6cf 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -3005,6 +3005,7 @@ olx.interaction.DragZoomOptions.prototype.out; * source: (ol.source.Vector|undefined), * snapTolerance: (number|undefined), * type: (ol.geom.GeometryType|string), + * stopClick: (boolean|undefined), * maxPoints: (number|undefined), * minPoints: (number|undefined), * finishCondition: (ol.EventsConditionType|undefined), @@ -3064,6 +3065,15 @@ olx.interaction.DrawOptions.prototype.snapTolerance; olx.interaction.DrawOptions.prototype.type; +/** + * Stop click, singleclick, and doubleclick events from firing during drawing. + * Default is `false`. + * @type {boolean|undefined} + * @api + */ +olx.interaction.DrawOptions.prototype.stopClick; + + /** * The number of points that can be drawn before a polygon ring or line string * is finished. The default is no restriction. diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index db70bf0efc..38030c194d 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -97,6 +97,14 @@ ol.interaction.Draw = function(options) { */ this.mode_ = ol.interaction.Draw.getMode_(this.type_); + /** + * Stop click, singleclick, and doubleclick events from firing during drawing. + * Default is `false`. + * @type {boolean} + * @private + */ + this.stopClick_ = !!options.stopClick; + /** * The number of points that must be drawn before a polygon ring or line * string can be finished. The default is 3 for polygon rings and 2 for @@ -384,6 +392,9 @@ ol.interaction.Draw.handleUpEvent_ = function(event) { this.finishCoordinate_ = null; this.abortDrawing_(); } + if (!pass && this.stopClick_) { + event.stopPropagation(); + } return pass; }; diff --git a/src/ol/mapbrowsereventhandler.js b/src/ol/mapbrowsereventhandler.js index ea06f1bc39..3e71883a17 100644 --- a/src/ol/mapbrowsereventhandler.js +++ b/src/ol/mapbrowsereventhandler.js @@ -172,7 +172,9 @@ ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) { // contact. isMouseActionButton returns true in these cases (evt.button is set // to 0). // See http://www.w3.org/TR/pointerevents/#button-states - if (!this.dragging_ && this.isMouseActionButton_(pointerEvent)) { + // We only fire click, singleclick, and doubleclick if nobody has called + // event.stopPropagation() or event.preventDefault(). + if (!newEvent.propagationStopped && !this.dragging_ && this.isMouseActionButton_(pointerEvent)) { this.emulateClick_(this.down_); }