Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added updateSketchCondition as a Draw Interaction option #7535

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions externs/olx.js
Expand Up @@ -3015,6 +3015,7 @@ olx.interaction.DragZoomOptions.prototype.out;
* condition: (ol.EventsConditionType|undefined),
* freehand: (boolean|undefined),
* freehandCondition: (ol.EventsConditionType|undefined),
* updateSketchCondition: (ol.EventsConditionType|undefined),
* wrapX: (boolean|undefined)}}
*/
olx.interaction.DrawOptions;
Expand Down Expand Up @@ -3135,6 +3136,16 @@ olx.interaction.DrawOptions.prototype.geometryName;
*/
olx.interaction.DrawOptions.prototype.condition;

/**
* A function that takes an {@link ol.MapBrowserEvent} and returns a boolean
* to indicate whether the current sketch being drawn should be updated. This
* can be used to either limit the scope of the feature being drawn, or to
* skip events caused by panning/zooming on a touch device. By default
* {@link ol.events.condition.always}, i.e. it is always updated.
* @type {ol.EventsConditionType|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.updateSketchCondition;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new option must also be added in the olx.interaction.DrawOptions @typedef above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing, fixed by b53d61d.


/**
* Operate in freehand mode for lines, polygons, and circles. This makes the
Expand Down
10 changes: 10 additions & 0 deletions src/ol/interaction/draw.js
Expand Up @@ -279,6 +279,13 @@ ol.interaction.Draw = function(options) {
options.freehandCondition : ol.events.condition.shiftKeyOnly;
}

/**
* @private
* @type {ol.EventsConditionType}
*/
this.updateSketchCondition_ = options.updateSketchCondition ?
options.updateSketchCondition : ol.events.condition.always;

ol.events.listen(this,
ol.Object.getChangeEventType(ol.interaction.Property.ACTIVE),
this.updateState_, this);
Expand Down Expand Up @@ -525,6 +532,9 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
* @private
*/
ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
if (!this.updateSketchCondition_(event)) {
return;
}
var coordinate = event.coordinate;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, last;
Expand Down