Merge pull request #6067 from ahocevar/freehand-circle
Do not draw circle when pointer not moved
This commit is contained in:
@@ -355,6 +355,7 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
|
||||
var shouldHandle = this.freehand_ ?
|
||||
squaredDistance > this.squaredClickTolerance_ :
|
||||
squaredDistance <= this.squaredClickTolerance_;
|
||||
var circleMode = this.mode_ === ol.interaction.Draw.Mode.CIRCLE;
|
||||
if (shouldHandle) {
|
||||
this.handlePointerMove_(event);
|
||||
if (!this.finishCoordinate_) {
|
||||
@@ -362,7 +363,7 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
|
||||
if (this.mode_ === ol.interaction.Draw.Mode.POINT) {
|
||||
this.finishDrawing();
|
||||
}
|
||||
} else if (this.freehand_ || this.mode_ === ol.interaction.Draw.Mode.CIRCLE) {
|
||||
} else if (this.freehand_ || circleMode) {
|
||||
this.finishDrawing();
|
||||
} else if (this.atFinish_(event)) {
|
||||
if (this.finishCondition_(event)) {
|
||||
@@ -372,6 +373,8 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
|
||||
this.addToDrawing_(event);
|
||||
}
|
||||
pass = false;
|
||||
} else if (circleMode) {
|
||||
this.finishCoordinate_ = null;
|
||||
}
|
||||
return pass;
|
||||
};
|
||||
|
||||
@@ -728,6 +728,24 @@ describe('ol.interaction.Draw', function() {
|
||||
expect(geometry.getRadius()).to.eql(20);
|
||||
});
|
||||
|
||||
it('supports freehand drawing for circles', function() {
|
||||
draw.freehand_ = true;
|
||||
draw.freehandCondition_ = ol.events.condition.always;
|
||||
|
||||
// no feture created when not moved
|
||||
simulateEvent('pointermove', 10, 20);
|
||||
simulateEvent('pointerdown', 10, 20);
|
||||
simulateEvent('pointerup', 10, 20);
|
||||
expect(source.getFeatures()).to.have.length(0);
|
||||
|
||||
// feature created when moved
|
||||
simulateEvent('pointermove', 10, 20);
|
||||
simulateEvent('pointerdown', 10, 20);
|
||||
simulateEvent('pointermove', 30, 20);
|
||||
simulateEvent('pointerup', 30, 20);
|
||||
expect(source.getFeatures()).to.have.length(1);
|
||||
});
|
||||
|
||||
it('triggers draw events', function() {
|
||||
var ds = sinon.spy();
|
||||
var de = sinon.spy();
|
||||
|
||||
Reference in New Issue
Block a user