diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index 554ec6573a..619328cc80 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -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; }; diff --git a/test/spec/ol/interaction/draw.test.js b/test/spec/ol/interaction/draw.test.js index e51b06f548..dc9214d666 100644 --- a/test/spec/ol/interaction/draw.test.js +++ b/test/spec/ol/interaction/draw.test.js @@ -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();