From bc79d59811ee3f4cc7bcdd9df0195353301b3bbd Mon Sep 17 00:00:00 2001 From: Otto Pellinen Date: Sat, 7 Dec 2019 16:13:43 +0200 Subject: [PATCH] Use private function addToDrawing_ in appendCoordinates --- src/ol/interaction/Draw.js | 42 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 9807de8b8a..3449bd565f 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -505,7 +505,7 @@ class Draw extends PointerInteraction { if (this.freehand_ && event.type === MapBrowserEventType.POINTERDRAG && this.sketchFeature_ !== null) { - this.addToDrawing_(event); + this.addToDrawing_(event.coordinate); pass = false; } else if (this.freehand_ && event.type === MapBrowserEventType.POINTERDOWN) { @@ -580,7 +580,7 @@ class Draw extends PointerInteraction { this.finishDrawing(); } } else { - this.addToDrawing_(event); + this.addToDrawing_(event.coordinate); } pass = false; } else if (this.freehand_) { @@ -764,11 +764,10 @@ class Draw extends PointerInteraction { /** * Add a new coordinate to the drawing. - * @param {import("../MapBrowserEvent.js").default} event Event. + * @param {!PointCoordType} coordinate Coordinate * @private */ - addToDrawing_(event) { - const coordinate = event.coordinate; + addToDrawing_(coordinate) { const geometry = this.sketchFeature_.getGeometry(); const projection = event.map.getView().getProjection(); let done; @@ -912,36 +911,25 @@ class Draw extends PointerInteraction { * @api */ appendCoordinates(coordinateExtension) { - const ending = coordinateExtension[coordinateExtension.length - 1].slice(); const mode = this.mode_; - let coordinates = []; if (mode === Mode.LINE_STRING) { - coordinates = this.sketchCoords_; + coordinates = /** @type {LineCoordType} */ this.sketchCoords_; } else if (mode === Mode.POLYGON) { - coordinates = (this.sketchCoords_)[0]; - } else { - return; + coordinates = this.sketchCoords_ && this.sketchCoords_.length ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0] : []; } - // (1) Remove last coordinate, (2) append coordinate list and (3) clone last coordinate - coordinates.pop(); - Array.prototype.push.apply(coordinates, coordinateExtension); - coordinates.push(ending); + // Remove last coordinate from sketch drawing (this coordinate follows cursor position) + const ending = coordinates.pop(); - // Update geometry and sketch line - this.geometryFunction_(this.sketchCoords_, this.sketchFeature_.getGeometry()); - - if (mode === Mode.POLYGON) { - this.sketchLineCoords_ = this.sketchCoords_[0]; - if (this.sketchLine_ !== null) { - this.sketchLine_.getGeometry().setCoordinates(this.sketchLineCoords_); - } else { - this.sketchLine_ = new Feature( - new LineString(this.sketchLineCoords_)); - } + // Append coordinate list + for (let i = 0; i < coordinateExtension.length; i++) { + this.addToDrawing_(coordinateExtension[i]); } - this.updateSketchFeatures_(); + + // Duplicate last coordinate for sketch drawing + this.addToDrawing_(ending); + //this.addToDrawing_(coordinateExtension[coordinateExtension.length - 1]); } /**