Restore Mode.CIRCLE

This commit is contained in:
mike-000
2020-11-27 11:42:51 +00:00
committed by GitHub
parent 7b5f53753b
commit c0875e38e7
+18 -13
View File
@@ -123,6 +123,7 @@ const Mode = {
POINT: 'Point', POINT: 'Point',
LINE_STRING: 'LineString', LINE_STRING: 'LineString',
POLYGON: 'Polygon', POLYGON: 'Polygon',
CIRCLE: 'Circle',
}; };
/** /**
@@ -290,7 +291,7 @@ class Draw extends PointerInteraction {
* @private * @private
*/ */
this.maxPoints_ = this.maxPoints_ =
this.type_ === GeometryType.CIRCLE this.mode_ === Mode.CIRCLE
? 2 ? 2
: options.maxPoints : options.maxPoints
? options.maxPoints ? options.maxPoints
@@ -307,7 +308,8 @@ class Draw extends PointerInteraction {
let geometryFunction = options.geometryFunction; let geometryFunction = options.geometryFunction;
if (!geometryFunction) { if (!geometryFunction) {
if (this.type_ === GeometryType.CIRCLE) { const mode = this.mode_;
if (mode === Mode.CIRCLE) {
/** /**
* @param {!LineCoordType} coordinates The coordinates. * @param {!LineCoordType} coordinates The coordinates.
* @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry. * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
@@ -337,7 +339,6 @@ class Draw extends PointerInteraction {
}; };
} else { } else {
let Constructor; let Constructor;
const mode = this.mode_;
if (mode === Mode.POINT) { if (mode === Mode.POINT) {
Constructor = Point; Constructor = Point;
} else if (mode === Mode.LINE_STRING) { } else if (mode === Mode.LINE_STRING) {
@@ -697,9 +698,10 @@ class Draw extends PointerInteraction {
if (this.sketchFeature_) { if (this.sketchFeature_) {
let potentiallyDone = false; let potentiallyDone = false;
let potentiallyFinishCoordinates = [this.finishCoordinate_]; let potentiallyFinishCoordinates = [this.finishCoordinate_];
if (this.mode_ === Mode.LINE_STRING) { const mode = this.mode_;
if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) {
potentiallyDone = this.sketchCoords_.length > this.minPoints_; potentiallyDone = this.sketchCoords_.length > this.minPoints_;
} else if (this.mode_ === Mode.POLYGON) { } else if (mode === Mode.POLYGON) {
const sketchCoords = /** @type {PolyCoordType} */ (this.sketchCoords_); const sketchCoords = /** @type {PolyCoordType} */ (this.sketchCoords_);
potentiallyDone = sketchCoords[0].length > this.minPoints_; potentiallyDone = sketchCoords[0].length > this.minPoints_;
potentiallyFinishCoordinates = [ potentiallyFinishCoordinates = [
@@ -859,7 +861,8 @@ class Draw extends PointerInteraction {
const projection = this.getMap().getView().getProjection(); const projection = this.getMap().getView().getProjection();
let done; let done;
let coordinates; let coordinates;
if (this.mode_ === Mode.LINE_STRING) { const mode = this.mode_;
if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) {
this.finishCoordinate_ = coordinate.slice(); this.finishCoordinate_ = coordinate.slice();
coordinates = /** @type {LineCoordType} */ (this.sketchCoords_); coordinates = /** @type {LineCoordType} */ (this.sketchCoords_);
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
@@ -871,7 +874,7 @@ class Draw extends PointerInteraction {
} }
coordinates.push(coordinate.slice()); coordinates.push(coordinate.slice());
this.geometryFunction_(coordinates, geometry, projection); this.geometryFunction_(coordinates, geometry, projection);
} else if (this.mode_ === Mode.POLYGON) { } else if (mode === Mode.POLYGON) {
coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
if (this.freehand_) { if (this.freehand_) {
@@ -903,7 +906,8 @@ class Draw extends PointerInteraction {
const geometry = this.sketchFeature_.getGeometry(); const geometry = this.sketchFeature_.getGeometry();
const projection = this.getMap().getView().getProjection(); const projection = this.getMap().getView().getProjection();
let coordinates; let coordinates;
if (this.mode_ === Mode.LINE_STRING) { const mode = this.mode_;
if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) {
coordinates = /** @type {LineCoordType} */ (this.sketchCoords_); coordinates = /** @type {LineCoordType} */ (this.sketchCoords_);
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
if (coordinates.length >= 2) { if (coordinates.length >= 2) {
@@ -919,7 +923,7 @@ class Draw extends PointerInteraction {
if (geometry.getType() === GeometryType.POLYGON && this.sketchLine_) { if (geometry.getType() === GeometryType.POLYGON && this.sketchLine_) {
this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry)); this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
} }
} else if (this.mode_ === Mode.POLYGON) { } else if (mode === Mode.POLYGON) {
coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
const sketchLineGeom = this.sketchLine_.getGeometry(); const sketchLineGeom = this.sketchLine_.getGeometry();
@@ -954,7 +958,7 @@ class Draw extends PointerInteraction {
let coordinates = this.sketchCoords_; let coordinates = this.sketchCoords_;
const geometry = sketchFeature.getGeometry(); const geometry = sketchFeature.getGeometry();
const projection = this.getMap().getView().getProjection(); const projection = this.getMap().getView().getProjection();
if (this.mode_ === Mode.LINE_STRING && this.type_ !== GeometryType.CIRCLE) { if (this.mode_ === Mode.LINE_STRING) {
// remove the redundant last point // remove the redundant last point
coordinates.pop(); coordinates.pop();
this.geometryFunction_(coordinates, geometry, projection); this.geometryFunction_(coordinates, geometry, projection);
@@ -1030,7 +1034,7 @@ class Draw extends PointerInteraction {
appendCoordinates(coordinates) { appendCoordinates(coordinates) {
const mode = this.mode_; const mode = this.mode_;
let sketchCoords = []; let sketchCoords = [];
if (mode === Mode.LINE_STRING) { 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 =
@@ -1221,8 +1225,7 @@ function getMode(type) {
mode = Mode.POINT; mode = Mode.POINT;
} else if ( } else if (
type === GeometryType.LINE_STRING || type === GeometryType.LINE_STRING ||
type === GeometryType.MULTI_LINE_STRING || type === GeometryType.MULTI_LINE_STRING
type === GeometryType.CIRCLE
) { ) {
mode = Mode.LINE_STRING; mode = Mode.LINE_STRING;
} else if ( } else if (
@@ -1230,6 +1233,8 @@ function getMode(type) {
type === GeometryType.MULTI_POLYGON type === GeometryType.MULTI_POLYGON
) { ) {
mode = Mode.POLYGON; mode = Mode.POLYGON;
} else if (type === GeometryType.CIRCLE) {
mode = Mode.CIRCLE;
} }
return /** @type {!Mode} */ (mode); return /** @type {!Mode} */ (mode);
} }