Fix removeLastPoint when removing last point

This commit is contained in:
Andreas Hocevar
2020-12-03 19:10:57 +01:00
parent 62c7853ed7
commit 651c1aa6c4
+21 -11
View File
@@ -585,7 +585,7 @@ class Draw extends PointerInteraction {
if (this.freehand_) { if (this.freehand_) {
this.downPx_ = event.pixel; this.downPx_ = event.pixel;
if (!this.finishCoordinate_) { if (!this.finishCoordinate_) {
this.startDrawing_(event); this.startDrawing_(event.coordinate);
} }
return true; return true;
} else if (this.condition_(event)) { } else if (this.condition_(event)) {
@@ -630,7 +630,7 @@ class Draw extends PointerInteraction {
if (this.shouldHandle_) { if (this.shouldHandle_) {
if (!this.finishCoordinate_) { if (!this.finishCoordinate_) {
this.startDrawing_(event); this.startDrawing_(event.coordinate);
if (this.mode_ === Mode.POINT) { if (this.mode_ === Mode.POINT) {
this.finishDrawing(); this.finishDrawing();
} }
@@ -771,12 +771,11 @@ class Draw extends PointerInteraction {
/** /**
* Start the drawing. * Start the drawing.
* @param {import("../MapBrowserEvent.js").default} event Event. * @param {import("../coordinate.js").Coordinate} start Start coordinate.
* @private * @private
*/ */
startDrawing_(event) { startDrawing_(start) {
const start = event.coordinate; const projection = this.getMap().getView().getProjection();
const projection = event.map.getView().getProjection();
this.finishCoordinate_ = start; this.finishCoordinate_ = start;
if (this.mode_ === Mode.POINT) { if (this.mode_ === Mode.POINT) {
this.sketchCoords_ = start.slice(); this.sketchCoords_ = start.slice();
@@ -937,7 +936,7 @@ class Draw extends PointerInteraction {
this.geometryFunction_(this.sketchCoords_, geometry, projection); this.geometryFunction_(this.sketchCoords_, geometry, projection);
} }
if (coordinates.length === 0) { if (coordinates.length === 1) {
this.abortDrawing(); this.abortDrawing();
} }
@@ -1026,21 +1025,32 @@ class Draw extends PointerInteraction {
* Append coordinates to the end of the geometry that is currently being drawn. * Append coordinates to the end of the geometry that is currently being drawn.
* This can be used when drawing LineStrings or Polygons. Coordinates will * This can be used when drawing LineStrings or Polygons. Coordinates will
* either be appended to the current LineString or the outer ring of the current * either be appended to the current LineString or the outer ring of the current
* Polygon. * Polygon. If no geometry is being drawn, a new one will be created.
* @param {!LineCoordType} coordinates Linear coordinates to be appended into * @param {!LineCoordType} coordinates Linear coordinates to be appended to
* the coordinate array. * the coordinate array.
* @api * @api
*/ */
appendCoordinates(coordinates) { appendCoordinates(coordinates) {
const mode = this.mode_; const mode = this.mode_;
let sketchCoords = []; const newDrawing = !this.sketchFeature_;
if (newDrawing) {
this.startDrawing_(coordinates[0]);
}
/** @type {LineCoordType} */
let sketchCoords;
if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) { if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) {
sketchCoords = /** @type {LineCoordType} */ this.sketchCoords_; sketchCoords = /** @type {LineCoordType} */ (this.sketchCoords_);
} else if (mode === Mode.POLYGON) { } else if (mode === Mode.POLYGON) {
sketchCoords = sketchCoords =
this.sketchCoords_ && this.sketchCoords_.length this.sketchCoords_ && this.sketchCoords_.length
? /** @type {PolyCoordType} */ (this.sketchCoords_)[0] ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0]
: []; : [];
} else {
return;
}
if (newDrawing) {
sketchCoords.shift();
} }
// Remove last coordinate from sketch drawing (this coordinate follows cursor position) // Remove last coordinate from sketch drawing (this coordinate follows cursor position)