Merge pull request #5973 from tschaub/freehand-option
Add a freehand option to the draw interaction
This commit is contained in:
@@ -2582,6 +2582,7 @@ olx.interaction.DragZoomOptions.prototype.out;
|
|||||||
* geometryFunction: (ol.DrawGeometryFunctionType|undefined),
|
* geometryFunction: (ol.DrawGeometryFunctionType|undefined),
|
||||||
* geometryName: (string|undefined),
|
* geometryName: (string|undefined),
|
||||||
* condition: (ol.EventsConditionType|undefined),
|
* condition: (ol.EventsConditionType|undefined),
|
||||||
|
* freehand: (boolean|undefined),
|
||||||
* freehandCondition: (ol.EventsConditionType|undefined),
|
* freehandCondition: (ol.EventsConditionType|undefined),
|
||||||
* wrapX: (boolean|undefined)}}
|
* wrapX: (boolean|undefined)}}
|
||||||
*/
|
*/
|
||||||
@@ -2695,6 +2696,16 @@ olx.interaction.DrawOptions.prototype.geometryName;
|
|||||||
olx.interaction.DrawOptions.prototype.condition;
|
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
|
* Condition that activates freehand drawing for lines and polygons. This
|
||||||
* function takes an {@link ol.MapBrowserEvent} and returns a boolean to
|
* function takes an {@link ol.MapBrowserEvent} and returns a boolean to
|
||||||
|
|||||||
@@ -251,8 +251,13 @@ ol.interaction.Draw = function(options) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.EventsConditionType}
|
* @type {ol.EventsConditionType}
|
||||||
*/
|
*/
|
||||||
this.freehandCondition_ = options.freehandCondition ?
|
this.freehandCondition_;
|
||||||
options.freehandCondition : ol.events.condition.shiftKeyOnly;
|
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.events.listen(this,
|
||||||
ol.Object.getChangeEventType(ol.interaction.Interaction.Property.ACTIVE),
|
ol.Object.getChangeEventType(ol.interaction.Interaction.Property.ACTIVE),
|
||||||
@@ -319,15 +324,15 @@ ol.interaction.Draw.handleEvent = function(mapBrowserEvent) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Draw.handleDownEvent_ = function(event) {
|
ol.interaction.Draw.handleDownEvent_ = function(event) {
|
||||||
if (this.condition_(event)) {
|
if (this.freehand_) {
|
||||||
this.downPx_ = event.pixel;
|
|
||||||
return true;
|
|
||||||
} else if (this.freehand_) {
|
|
||||||
this.downPx_ = event.pixel;
|
this.downPx_ = event.pixel;
|
||||||
if (!this.finishCoordinate_) {
|
if (!this.finishCoordinate_) {
|
||||||
this.startDrawing_(event);
|
this.startDrawing_(event);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else if (this.condition_(event)) {
|
||||||
|
this.downPx_ = event.pixel;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,22 @@ describe('ol.interaction.Draw', function() {
|
|||||||
expect(draw).to.be.a(ol.interaction.Interaction);
|
expect(draw).to.be.a(ol.interaction.Interaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts a freehand option', function() {
|
||||||
|
var draw = new ol.interaction.Draw({
|
||||||
|
source: source,
|
||||||
|
type: 'LineString',
|
||||||
|
freehand: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var event = new ol.pointer.PointerEvent('pointerdown', {
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0,
|
||||||
|
shiftKey: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(draw.freehandCondition_(event)).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('specifying a geometryName', function() {
|
describe('specifying a geometryName', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user