Add the capability to remove(undo) the last drawed segments.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user