From 29b1f0d55d6449fda35ed561b4ea1bb339ce5fb5 Mon Sep 17 00:00:00 2001 From: geonux Date: Mon, 6 Jul 2015 12:11:34 +0200 Subject: [PATCH 1/4] Add the capability to remove(undo) the last drawed segments. --- src/ol/interaction/drawinteraction.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index beb7d1b273..7c1729feb4 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -617,6 +617,31 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) { }; +/** + * Remove last drawed point of the currently edited feature. + * @api + */ +ol.interaction.Draw.prototype.removeLastPoint = function() { + var geometry = this.sketchFeature_.getGeometry(); + var coordinates, sketchLineGeom; + if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) { + coordinates = this.sketchCoords_; + coordinates.splice(-2, 1); + this.geometryFunction_(coordinates, geometry); + } else if (this.mode_ === ol.interaction.DrawMode.POLYGON) { + coordinates = this.sketchCoords_[0]; + coordinates.splice(-2, 1); + sketchLineGeom = this.sketchLine_.getGeometry(); + sketchLineGeom.setCoordinates(coordinates); + this.geometryFunction_(this.sketchCoords_, geometry); + } + + if (coordinates.length === 0) this.finishCoordinate_ = null; + + this.updateSketchFeatures_(); +}; + + /** * Stop drawing and add the sketch feature to the target layer. * The {@link ol.interaction.DrawEventType.DRAWEND} event is dispatched before From 314b04df7ab29cd68d34fba66289427d3f18bc81 Mon Sep 17 00:00:00 2001 From: geonux Date: Mon, 6 Jul 2015 13:49:42 +0200 Subject: [PATCH 2/4] Add assertions to pass the validation step. --- src/ol/interaction/drawinteraction.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index 7c1729feb4..7b9c950664 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -623,6 +623,8 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) { */ ol.interaction.Draw.prototype.removeLastPoint = function() { var geometry = this.sketchFeature_.getGeometry(); + goog.asserts.assertInstanceof(geometry, ol.geom.SimpleGeometry, + 'geometry must be an ol.geom.SimpleGeometry'); var coordinates, sketchLineGeom; if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) { coordinates = this.sketchCoords_; @@ -632,6 +634,8 @@ ol.interaction.Draw.prototype.removeLastPoint = function() { coordinates = this.sketchCoords_[0]; coordinates.splice(-2, 1); sketchLineGeom = this.sketchLine_.getGeometry(); + goog.asserts.assertInstanceof(sketchLineGeom, ol.geom.LineString, + 'sketchLineGeom must be an ol.geom.LineString'); sketchLineGeom.setCoordinates(coordinates); this.geometryFunction_(this.sketchCoords_, geometry); } From 64ab764827c74589848588b3c25eb26c73c5a9b1 Mon Sep 17 00:00:00 2001 From: geonux Date: Mon, 6 Jul 2015 15:07:56 +0200 Subject: [PATCH 3/4] Renaming the method description according to 'probins' proposal. --- src/ol/interaction/drawinteraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index 7b9c950664..0bb01627f4 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -618,7 +618,7 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) { /** - * Remove last drawed point of the currently edited feature. + * Remove last point of the feature currently being drawn. * @api */ ol.interaction.Draw.prototype.removeLastPoint = function() { From 999880f350773c5cf7c388a6fbe145288b1a4b3d Mon Sep 17 00:00:00 2001 From: geonux Date: Tue, 4 Aug 2015 15:02:49 +0200 Subject: [PATCH 4/4] Add missing braces on statement --- src/ol/interaction/drawinteraction.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index 0bb01627f4..e7147b2457 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -640,7 +640,9 @@ ol.interaction.Draw.prototype.removeLastPoint = function() { this.geometryFunction_(this.sketchCoords_, geometry); } - if (coordinates.length === 0) this.finishCoordinate_ = null; + if (coordinates.length === 0) { + this.finishCoordinate_ = null; + } this.updateSketchFeatures_(); };