Use private function addToDrawing_ in appendCoordinates
This commit is contained in:
committed by
Olivier Guyot
parent
f43bc8d122
commit
bc79d59811
+15
-27
@@ -505,7 +505,7 @@ class Draw extends PointerInteraction {
|
|||||||
if (this.freehand_ &&
|
if (this.freehand_ &&
|
||||||
event.type === MapBrowserEventType.POINTERDRAG &&
|
event.type === MapBrowserEventType.POINTERDRAG &&
|
||||||
this.sketchFeature_ !== null) {
|
this.sketchFeature_ !== null) {
|
||||||
this.addToDrawing_(event);
|
this.addToDrawing_(event.coordinate);
|
||||||
pass = false;
|
pass = false;
|
||||||
} else if (this.freehand_ &&
|
} else if (this.freehand_ &&
|
||||||
event.type === MapBrowserEventType.POINTERDOWN) {
|
event.type === MapBrowserEventType.POINTERDOWN) {
|
||||||
@@ -580,7 +580,7 @@ class Draw extends PointerInteraction {
|
|||||||
this.finishDrawing();
|
this.finishDrawing();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.addToDrawing_(event);
|
this.addToDrawing_(event.coordinate);
|
||||||
}
|
}
|
||||||
pass = false;
|
pass = false;
|
||||||
} else if (this.freehand_) {
|
} else if (this.freehand_) {
|
||||||
@@ -764,11 +764,10 @@ class Draw extends PointerInteraction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new coordinate to the drawing.
|
* Add a new coordinate to the drawing.
|
||||||
* @param {import("../MapBrowserEvent.js").default} event Event.
|
* @param {!PointCoordType} coordinate Coordinate
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
addToDrawing_(event) {
|
addToDrawing_(coordinate) {
|
||||||
const coordinate = event.coordinate;
|
|
||||||
const geometry = this.sketchFeature_.getGeometry();
|
const geometry = this.sketchFeature_.getGeometry();
|
||||||
const projection = event.map.getView().getProjection();
|
const projection = event.map.getView().getProjection();
|
||||||
let done;
|
let done;
|
||||||
@@ -912,36 +911,25 @@ class Draw extends PointerInteraction {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
appendCoordinates(coordinateExtension) {
|
appendCoordinates(coordinateExtension) {
|
||||||
const ending = coordinateExtension[coordinateExtension.length - 1].slice();
|
|
||||||
const mode = this.mode_;
|
const mode = this.mode_;
|
||||||
|
|
||||||
let coordinates = [];
|
let coordinates = [];
|
||||||
if (mode === Mode.LINE_STRING) {
|
if (mode === Mode.LINE_STRING) {
|
||||||
coordinates = this.sketchCoords_;
|
coordinates = /** @type {LineCoordType} */ this.sketchCoords_;
|
||||||
} else if (mode === Mode.POLYGON) {
|
} else if (mode === Mode.POLYGON) {
|
||||||
coordinates = (this.sketchCoords_)[0];
|
coordinates = this.sketchCoords_ && this.sketchCoords_.length ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0] : [];
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// (1) Remove last coordinate, (2) append coordinate list and (3) clone last coordinate
|
// Remove last coordinate from sketch drawing (this coordinate follows cursor position)
|
||||||
coordinates.pop();
|
const ending = coordinates.pop();
|
||||||
Array.prototype.push.apply(coordinates, coordinateExtension);
|
|
||||||
coordinates.push(ending);
|
|
||||||
|
|
||||||
// Update geometry and sketch line
|
// Append coordinate list
|
||||||
this.geometryFunction_(this.sketchCoords_, this.sketchFeature_.getGeometry());
|
for (let i = 0; i < coordinateExtension.length; i++) {
|
||||||
|
this.addToDrawing_(coordinateExtension[i]);
|
||||||
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_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.updateSketchFeatures_();
|
|
||||||
|
// Duplicate last coordinate for sketch drawing
|
||||||
|
this.addToDrawing_(ending);
|
||||||
|
//this.addToDrawing_(coordinateExtension[coordinateExtension.length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user