Allow clicks to be stopped while drawing

This commit is contained in:
Tim Schaub
2017-11-29 10:55:15 -07:00
parent 45d2f8debb
commit b58073dd06
3 changed files with 24 additions and 1 deletions

View File

@@ -3005,6 +3005,7 @@ olx.interaction.DragZoomOptions.prototype.out;
* source: (ol.source.Vector|undefined), * source: (ol.source.Vector|undefined),
* snapTolerance: (number|undefined), * snapTolerance: (number|undefined),
* type: (ol.geom.GeometryType|string), * type: (ol.geom.GeometryType|string),
* stopClick: (boolean|undefined),
* maxPoints: (number|undefined), * maxPoints: (number|undefined),
* minPoints: (number|undefined), * minPoints: (number|undefined),
* finishCondition: (ol.EventsConditionType|undefined), * finishCondition: (ol.EventsConditionType|undefined),
@@ -3064,6 +3065,15 @@ olx.interaction.DrawOptions.prototype.snapTolerance;
olx.interaction.DrawOptions.prototype.type; 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 * The number of points that can be drawn before a polygon ring or line string
* is finished. The default is no restriction. * is finished. The default is no restriction.

View File

@@ -97,6 +97,14 @@ ol.interaction.Draw = function(options) {
*/ */
this.mode_ = ol.interaction.Draw.getMode_(this.type_); 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 * 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 * 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.finishCoordinate_ = null;
this.abortDrawing_(); this.abortDrawing_();
} }
if (!pass && this.stopClick_) {
event.stopPropagation();
}
return pass; return pass;
}; };

View File

@@ -172,7 +172,9 @@ ol.MapBrowserEventHandler.prototype.handlePointerUp_ = function(pointerEvent) {
// contact. isMouseActionButton returns true in these cases (evt.button is set // contact. isMouseActionButton returns true in these cases (evt.button is set
// to 0). // to 0).
// See http://www.w3.org/TR/pointerevents/#button-states // 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_); this.emulateClick_(this.down_);
} }