From 29b1f0d55d6449fda35ed561b4ea1bb339ce5fb5 Mon Sep 17 00:00:00 2001 From: geonux Date: Mon, 6 Jul 2015 12:11:34 +0200 Subject: [PATCH] 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