liuyg
2022-03-16 e4be7a095f31b76d4f3d60c06eefe774ffd264fc
src/components/map/Draw.js
@@ -1,57 +1,97 @@
var __extends = (this && this.__extends) || (function() {
var __extends =
  (this && this.__extends) ||
  (function () {
    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] }
                instanceof Array && function(d, b) { d.__proto__ = b; }) ||
            function(d, b) { for (var p in b)
                    if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
      extendStatics =
        Object.setPrototypeOf ||
        ({
            __proto__: []
          }
          instanceof Array &&
          function (d, b) {
            d.__proto__ = b;
          }) ||
        function (d, b) {
          for (var p in b)
            if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
        };
        return extendStatics(d, b);
    };
    return function(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        throw new TypeError(
          "Class extends value " + String(b) + " is not a constructor or null"
        );
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      function __() {
        this.constructor = d;
      }
      d.prototype =
        b === null ?
        Object.create(b) :
        ((__.prototype = b.prototype), new __());
    };
})();
/**
 * @module ol/interaction/Draw
 */
import Circle from 'ol/geom/Circle.js';
import Event from 'ol/events/Event.js';
import EventType from 'ol/events/EventType.js';
import Feature from 'ol/Feature.js';
import GeometryType from 'ol/geom/GeometryType.js';
import InteractionProperty from 'ol/interaction/Property.js';
import LineString from 'ol/geom/LineString.js';
import MapBrowserEvent from 'ol/MapBrowserEvent.js';
import MapBrowserEventType from 'ol/MapBrowserEventType.js';
import MultiLineString from 'ol/geom/MultiLineString.js';
import MultiPoint from 'ol/geom/MultiPoint.js';
import MultiPolygon from 'ol/geom/MultiPolygon.js';
import Point from 'ol/geom/Point.js';
import PointerInteraction from 'ol/interaction/Pointer.js';
import Polygon, { fromCircle, makeRegular } from 'ol/geom/Polygon.js';
import VectorLayer from 'ol/layer/Vector.js';
import VectorSource from 'ol/source/Vector.js';
import { FALSE, TRUE } from 'ol/functions.js';
import { always, noModifierKeys, shiftKeyOnly } from 'ol/events/condition.js';
import { boundingExtent, getBottomLeft, getBottomRight, getTopLeft, getTopRight, } from 'ol/extent.js';
import { createEditingStyle } from 'ol/style/Style.js';
import { fromUserCoordinate, getUserProjection } from 'ol/proj.js';
import { squaredDistance as squaredCoordinateDistance } from 'ol/coordinate.js';
import Circle from "ol/geom/Circle.js";
import Event from "ol/events/Event.js";
import EventType from "ol/events/EventType.js";
import Feature from "ol/Feature.js";
import GeometryType from "ol/geom/GeometryType.js";
import InteractionProperty from "ol/interaction/Property.js";
import LineString from "ol/geom/LineString.js";
import MapBrowserEvent from "ol/MapBrowserEvent.js";
import MapBrowserEventType from "ol/MapBrowserEventType.js";
import MultiLineString from "ol/geom/MultiLineString.js";
import MultiPoint from "ol/geom/MultiPoint.js";
import MultiPolygon from "ol/geom/MultiPolygon.js";
import Point from "ol/geom/Point.js";
import PointerInteraction from "ol/interaction/Pointer.js";
import Polygon, {
  fromCircle,
  makeRegular
} from "ol/geom/Polygon.js";
import VectorLayer from "ol/layer/Vector.js";
import VectorSource from "ol/source/Vector.js";
import {
  FALSE,
  TRUE
} from "ol/functions.js";
import {
  always,
  noModifierKeys,
  shiftKeyOnly
} from "ol/events/condition.js";
import {
  boundingExtent,
  getBottomLeft,
  getBottomRight,
  getTopLeft,
  getTopRight,
} from "ol/extent.js";
import {
  createEditingStyle
} from "ol/style/Style.js";
import {
  fromUserCoordinate,
  getUserProjection
} from "ol/proj.js";
import {
  squaredDistance as squaredCoordinateDistance
} from "ol/coordinate.js";
/**
 * @typedef {Object} Options
 * @property {import("../geom/GeometryType.js").default} type Geometry type of
 * @property {import("ol/geom/GeometryType.js").default} type Geometry type of
 * the geometries being drawn with this instance.
 * @property {number} [clickTolerance=6] The maximum distance in pixels between
 * "down" and "up" for a "up" event to be considered a "click" event and
 * actually add a point/vertex to the geometry being drawn.  The default of `6`
 * was chosen for the draw interaction to behave correctly on mouse as well as
 * on touch devices.
 * @property {import("../Collection.js").default<Feature>} [features]
 * @property {import("ol/Collection.js").default<Feature>} [features]
 * Destination collection for the drawn features.
 * @property {VectorSource} [source] Destination source for
 * the drawn features.
@@ -67,17 +107,17 @@
 * @property {number} [minPoints] The number of points that must be drawn
 * before a polygon ring or line string can be finished. Default is `3` for
 * polygon rings and `2` for line strings.
 * @property {import("../events/condition.js").Condition} [finishCondition] A function
 * @property {import("ol/events/condition.js").Condition} [finishCondition] A function
 * that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
 * boolean to indicate whether the drawing can be finished. Not used when drawing
 * POINT or MULTI_POINT geometries.
 * @property {import("../style/Style.js").StyleLike} [style]
 * @property {import("ol/style/Style.js").StyleLike} [style]
 * Style for sketch features.
 * @property {GeometryFunction} [geometryFunction]
 * Function that is called when a geometry's coordinates are updated.
 * @property {string} [geometryName] Geometry name to use for features created
 * by the draw interaction.
 * @property {import("../events/condition.js").Condition} [condition] A function that
 * @property {import("ol/events/condition.js").Condition} [condition] A function that
 * takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
 * boolean to indicate whether that event should be handled.
 * By default {@link module:ol/events/condition.noModifierKeys}, i.e. a click,
@@ -85,7 +125,7 @@
 * @property {boolean} [freehand=false] Operate in freehand mode for lines,
 * polygons, and circles.  This makes the interaction always operate in freehand
 * mode and takes precedence over any `freehandCondition` option.
 * @property {import("../events/condition.js").Condition} [freehandCondition]
 * @property {import("ol/events/condition.js").Condition} [freehandCondition]
 * Condition that activates freehand drawing for lines and polygons. This
 * function takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and
 * returns a boolean to indicate whether that event should be handled. The
@@ -96,15 +136,15 @@
 */
/**
 * Coordinate type when drawing points.
 * @typedef {import("../coordinate.js").Coordinate} PointCoordType
 * @typedef {import("ol/coordinate.js").Coordinate} PointCoordType
 */
/**
 * Coordinate type when drawing lines.
 * @typedef {Array<import("../coordinate.js").Coordinate>} LineCoordType
 * @typedef {Array<import("ol/coordinate.js").Coordinate>} LineCoordType
 */
/**
 * Coordinate type when drawing polygons.
 * @typedef {Array<Array<import("../coordinate.js").Coordinate>>} PolyCoordType
 * @typedef {Array<Array<import("ol/coordinate.js").Coordinate>>} PolyCoordType
 */
/**
 * Types used for drawing coordinates.
@@ -115,9 +155,9 @@
 * and a projection as arguments, and returns a geometry. The optional existing
 * geometry is the geometry that is returned when the function is called without
 * a second argument.
 * @typedef {function(!SketchCoordType, import("../geom/SimpleGeometry.js").default,
 *     import("../proj/Projection.js").default):
 *     import("../geom/SimpleGeometry.js").default} GeometryFunction
 * @typedef {function(!SketchCoordType, import("ol/geom/SimpleGeometry.js").default,
 *     import("ol/proj/Projection.js").default):
 *     import("ol/geom/SimpleGeometry.js").default} GeometryFunction
 */
/**
 * Draw mode.  This collapses multi-part geometry types with their single-part
@@ -125,10 +165,10 @@
 * @enum {string}
 */
var Mode = {
    POINT: 'Point',
    LINE_STRING: 'LineString',
    POLYGON: 'Polygon',
    CIRCLE: 'Circle',
  POINT: "Point",
  LINE_STRING: "LineString",
  POLYGON: "Polygon",
  CIRCLE: "Circle",
};
/**
 * @enum {string}
@@ -139,19 +179,19 @@
     * @event DrawEvent#drawstart
     * @api
     */
    DRAWSTART: 'drawstart',
  DRAWSTART: "drawstart",
    /**
     * Triggered upon feature draw end
     * @event DrawEvent#drawend
     * @api
     */
    DRAWEND: 'drawend',
  DRAWEND: "drawend",
    /**
     * Triggered upon feature draw abortion
     * @event DrawEvent#drawabort
     * @api
     */
    DRAWABORT: 'drawabort',
  DRAWABORT: "drawabort",
};
/**
 * @classdesc
@@ -175,15 +215,17 @@
        return _this;
    }
    return DrawEvent;
}(Event));
export { DrawEvent };
})(Event);
export {
  DrawEvent
};
/***
 * @template Return
 * @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
 *   import("../Observable").OnSignature<import("../ObjectEventType").Types|
 *     'change:active', import("../Object").ObjectEvent, Return> &
 *   import("../Observable").OnSignature<'drawabort'|'drawend'|'drawstart', DrawEvent, Return> &
 *   import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("../ObjectEventType").Types|
 * @typedef {import("ol/Observable").OnSignature<import("ol/Observable").EventTypes, import("ol/events/Event.js").default, Return> &
 *   import("ol/Observable").OnSignature<import("ol/ObjectEventType").Types|
 *     'change:active', import("ol/Object").ObjectEvent, Return> &
 *   import("ol/Observable").OnSignature<'drawabort'|'drawend'|'drawstart', DrawEvent, Return> &
 *   import("ol/Observable").CombinedOnSignature<import("ol/Observable").EventTypes|import("ol/ObjectEventType").Types|
 *     'change:active'|'drawabort'|'drawend'|'drawstart', Return>} DrawOnSignature
 */
/**
@@ -200,25 +242,39 @@
     */
    function Draw(options) {
        var _this = this;
        var pointerOptions = /** @type {import("./Pointer.js").Options} */ (options);
    var pointerOptions = /** @type {import("./Pointer.js").Options} */ (
      options
    );
        if (!pointerOptions.stopDown) {
            pointerOptions.stopDown = FALSE;
        }
        _this = _super.call(this, pointerOptions) || this;
        /***
         * 自定义输入
     * @type {DrawOnSignature<import("ol/events").EventsKey>}
         */
        _this._coordinate = options.coordinate || function() { return false };
    _this.coordinate = options.coordinate;
        /***
         * 自定义输出
     * 输出坐标
         */
        _this._coordinateOver = options.coordinateOver || function() { return false };
    _this.coordinateOver = options.coordinateOver;
        /***
         * @type {DrawOnSignature<import("../Observable").OnReturn>}
     * 结束绘画
     */
    _this.overDraw = false;
    /***
     * 控制结束绘画
     */
    _this.isPoint = options.isPoint;
    /***
     * 是否是点
     */
    _this.coordinateOverPoint = options.coordinateOverPoint;
    /***
     * 输出点
         */
        _this.on;
        /***
         * @type {DrawOnSignature<import("../Observable").OnReturn>}
     * @type {DrawOnSignature<import("ol/events").EventsKey>}
         */
        _this.once;
        /***
@@ -231,7 +287,7 @@
         */
        _this.shouldHandle_ = false;
        /**
         * @type {import("../pixel.js").Pixel}
     * @type {import("ol/pixel.js").Pixel}
         * @private
         */
        _this.downPx_ = null;
@@ -264,7 +320,7 @@
        _this.source_ = options.source ? options.source : null;
        /**
         * Target collection for drawn features.
         * @type {import("../Collection.js").default<Feature>}
     * @type {import("ol/Collection.js").default<Feature>}
         * @private
         */
        _this.features_ = options.features ? options.features : null;
@@ -276,10 +332,12 @@
        _this.snapTolerance_ = options.snapTolerance ? options.snapTolerance : 12;
        /**
         * Geometry type.
         * @type {import("../geom/GeometryType.js").default}
     * @type {import("ol/geom/GeometryType.js").default}
         * @private
         */
        _this.type_ = /** @type {import("../geom/GeometryType.js").default} */ (options.type);
    _this.type_ = /** @type {import("ol/geom/GeometryType.js").default} */ (
      options.type
    );
        /**
         * Drawing mode (derived from geometry type.
         * @type {Mode}
@@ -320,7 +378,7 @@
        /**
         * A function to decide if a potential finish coordinate is permissible
         * @private
         * @type {import("../events/condition.js").Condition}
     * @type {import("ol/events/condition.js").Condition}
         */
        _this.finishCondition_ = options.finishCondition ?
            options.finishCondition :
@@ -331,16 +389,20 @@
            if (mode_1 === Mode.CIRCLE) {
                /**
                 * @param {!LineCoordType} coordinates The coordinates.
                 * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
                 * @param {import("../proj/Projection.js").default} projection The view projection.
                 * @return {import("../geom/SimpleGeometry.js").default} A geometry.
         * @param {import("ol/geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
         * @param {import("ol/proj/Projection.js").default} projection The view projection.
         * @return {import("ol/geom/SimpleGeometry.js").default} A geometry.
                 */
                geometryFunction = function(coordinates, geometry, projection) {
                    var circle = geometry ?
                        /** @type {Circle} */ (geometry) :
            /** @type {Circle} */
            (geometry) :
                        new Circle([NaN, NaN]);
                    var center = fromUserCoordinate(coordinates[0], projection);
                    var squaredLength = squaredCoordinateDistance(center, fromUserCoordinate(coordinates[coordinates.length - 1], projection));
          var squaredLength = squaredCoordinateDistance(
            center,
            fromUserCoordinate(coordinates[coordinates.length - 1], projection)
          );
                    circle.setCenterAndRadius(center, Math.sqrt(squaredLength));
                    var userProjection = getUserProjection();
                    if (userProjection) {
@@ -359,9 +421,9 @@
                }
                /**
                 * @param {!LineCoordType} coordinates The coordinates.
                 * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
                 * @param {import("../proj/Projection.js").default} projection The view projection.
                 * @return {import("../geom/SimpleGeometry.js").default} A geometry.
         * @param {import("ol/geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
         * @param {import("ol/proj/Projection.js").default} projection The view projection.
         * @return {import("ol/geom/SimpleGeometry.js").default} A geometry.
                 */
                geometryFunction = function(coordinates, geometry, projection) {
                    if (geometry) {
@@ -398,7 +460,7 @@
        /**
         * Finish coordinate for the feature (first point for polygons, last point for
         * linestrings).
         * @type {import("../coordinate.js").Coordinate}
     * @type {import("ol/coordinate.js").Coordinate}
         * @private
         */
        _this.finishCoordinate_ = null;
@@ -463,12 +525,12 @@
        _this.geometryName_ = options.geometryName;
        /**
         * @private
         * @type {import("../events/condition.js").Condition}
     * @type {import("ol/events/condition.js").Condition}
         */
        _this.condition_ = options.condition ? options.condition : noModifierKeys;
        /**
         * @private
         * @type {import("../events/condition.js").Condition}
     * @type {import("ol/events/condition.js").Condition}
         */
        _this.freehandCondition_;
        if (options.freehand) {
@@ -485,7 +547,7 @@
     * Remove the interaction from its current map and attach it to the new map.
     * Subclasses may set up event handlers to get notified about changes to
     * the map here.
     * @param {import("../PluggableMap.js").default} map Map.
   * @param {import("ol/PluggableMap.js").default} map Map.
     */
    Draw.prototype.setMap = function(map) {
        _super.prototype.setMap.call(this, map);
@@ -501,10 +563,14 @@
    };
    /**
     * Handles the {@link module:ol/MapBrowserEvent map browser event} and may actually draw or finish the drawing.
     * @param {import("../MapBrowserEvent.js").default} event Map browser event.
   * @param {import("ol/MapBrowserEvent.js").default} event Map browser event.
     * @return {boolean} `false` to stop event propagation.
     * @api
     */
  Draw.prototype.controlDrawing = function (val) {
    this.overDraw = val;
  };
    Draw.prototype.handleEvent = function(event) {
        if (event.originalEvent.type === EventType.CONTEXTMENU) {
            // Avoid context menu for long taps when drawing on mobile
@@ -514,9 +580,11 @@
            this.mode_ !== Mode.POINT && this.freehandCondition_(event);
        var move = event.type === MapBrowserEventType.POINTERMOVE;
        var pass = true;
        if (!this.freehand_ &&
    if (
      !this.freehand_ &&
            this.lastDragTime_ &&
            event.type === MapBrowserEventType.POINTERDRAG) {
      event.type === MapBrowserEventType.POINTERDRAG
    ) {
            var now = Date.now();
            if (now - this.lastDragTime_ >= this.dragVertexDelay_) {
                this.downPx_ = event.pixel;
@@ -530,25 +598,40 @@
                this.downTimeout_ = undefined;
            }
        }
        if (this.freehand_ &&
    if (
      this.freehand_ &&
            event.type === MapBrowserEventType.POINTERDRAG &&
            this.sketchFeature_ !== null) {
      this.sketchFeature_ !== null
    ) {
      if (this.overDraw) {
        return;
      }
            this.addToDrawing_(event.coordinate);
            pass = false;
        } else if (this.freehand_ &&
            event.type === MapBrowserEventType.POINTERDOWN) {
    } else if (
      this.freehand_ &&
      event.type === MapBrowserEventType.POINTERDOWN
    ) {
            pass = false;
        } else if (move && this.getPointerCount() < 2) {
            pass = event.type === MapBrowserEventType.POINTERMOVE;
            if (pass && this.freehand_) {
        if (this.overDraw) {
          return;
        }
                this.handlePointerMove_(event);
                if (this.shouldHandle_) {
                    // Avoid page scrolling when freehand drawing on mobile
                    event.originalEvent.preventDefault();
                }
            } else if (event.originalEvent.pointerType === 'mouse' ||
      } else if (
        event.originalEvent.pointerType === "mouse" ||
                (event.type === MapBrowserEventType.POINTERDRAG &&
                    this.downTimeout_ === undefined)) {
          this.downTimeout_ === undefined)
      ) {
        if (this.overDraw) {
          return;
        }
                this.handlePointerMove_(event);
            }
        } else if (event.type === MapBrowserEventType.DBLCLICK) {
@@ -558,10 +641,11 @@
    };
    /**
     * Handle pointer down events.
     * @param {import("../MapBrowserEvent.js").default} event Event.
   * @param {import("ol/MapBrowserEvent.js").default} event Event.
     * @return {boolean} If the event was consumed.
     */
    Draw.prototype.handleDownEvent = function(event) {
    // console.log(event.coordinate_, 'handleDownEvent')
        this.shouldHandle_ = !this.freehand_;
        if (this.freehand_) {
            this.downPx_ = event.pixel;
@@ -571,9 +655,20 @@
            return true;
        } else if (this.condition_(event)) {
            this.lastDragTime_ = Date.now();
            this.downTimeout_ = setTimeout(function() {
                this.handlePointerMove_(new MapBrowserEvent(MapBrowserEventType.POINTERMOVE, event.map, event.originalEvent, false, event.frameState));
            }.bind(this), this.dragVertexDelay_);
      this.downTimeout_ = setTimeout(
        function () {
          this.handlePointerMove_(
            new MapBrowserEvent(
              MapBrowserEventType.POINTERMOVE,
              event.map,
              event.originalEvent,
              false,
              event.frameState
            )
          );
        }.bind(this),
        this.dragVertexDelay_
      );
            this.downPx_ = event.pixel;
            return true;
        } else {
@@ -583,10 +678,16 @@
    };
    /**
     * Handle pointer up events.
     * @param {import("../MapBrowserEvent.js").default} event Event.
   * @param {import("ol/MapBrowserEvent.js").default} event Event.
     * @return {boolean} If the event was consumed.
     */
    Draw.prototype.handleUpEvent = function(event) {
    // console.log(event.coordinate_, 'handleUpEvent')//获取坐标点
    if (this.isPoint) {
      this.coordinateOverPoint(event);
      this.finishDrawing();
      return;
    }
        var pass = true;
        if (this.getPointerCount() === 0) {
            if (this.downTimeout_) {
@@ -597,17 +698,28 @@
            if (this.shouldHandle_) {
                var startingToDraw = !this.finishCoordinate_;
                if (startingToDraw) {
          //开始后抬起
          // this.coordinateOverPoint(event);
          // console.log(1)
          this.coordinate(event);
                    this.startDrawing_(event.coordinate);
                }
                if (!startingToDraw && this.freehand_) {
                    this.finishDrawing();
                } else if (!this.freehand_ &&
                    (!startingToDraw || this.mode_ === Mode.POINT)) {
        } else if (
          !this.freehand_ &&
          (!startingToDraw || this.mode_ === Mode.POINT)
        ) {
          //选择后抬起
          this.coordinate(event);
                    if (this.atFinish_(event.pixel)) {
            //结束绘画
            this.coordinateOver("结束");
                        if (this.finishCondition_(event)) {
                            this.finishDrawing();
                        }
                    } else {
            // console.log(28888888888)
                        this.addToDrawing_(event.coordinate);
                    }
                }
@@ -621,16 +733,22 @@
        }
        return pass;
    };
  // Draw.prototype.getCoordinate = function (fn) {
  //     this.coordinate = fn;
  //     console.log(this.coordinate)
  // }
    /**
     * Handle move events.
     * @param {import("../MapBrowserEvent.js").default} event A move event.
   * @param {import("ol/MapBrowserEvent.js").default} event A move event.
     * @private
     */
    Draw.prototype.handlePointerMove_ = function(event) {
        this.pointerType_ = event.originalEvent.pointerType;
        if (this.downPx_ &&
    if (
      this.downPx_ &&
            ((!this.freehand_ && this.shouldHandle_) ||
                (this.freehand_ && !this.shouldHandle_))) {
        (this.freehand_ && !this.shouldHandle_))
    ) {
            var downPx = this.downPx_;
            var clickPx = event.pixel;
            var dx = downPx[0] - clickPx[0];
@@ -651,11 +769,12 @@
    };
    /**
     * Determine if an event is within the snapping tolerance of the start coord.
     * @param {import("../pixel.js").Pixel} pixel Pixel.
   * @param {import("ol/pixel.js").Pixel} pixel Pixel.
     * @return {boolean} The event is within the snapping tolerance of the start.
     * @private
     */
    Draw.prototype.atFinish_ = function(pixel) {
    // console.log(pixel, 879789)
        var at = false;
        if (this.sketchFeature_) {
            var potentiallyDone = false;
@@ -694,7 +813,7 @@
        return at;
    };
    /**
     * @param {import("../coordinate").Coordinate} coordinates Coordinate.
   * @param {import("ol/coordinate").Coordinate} coordinates Coordinate.
     * @private
     */
    Draw.prototype.createOrUpdateSketchPoint_ = function(coordinates) {
@@ -707,7 +826,7 @@
        }
    };
    /**
     * @param {import("../geom/Polygon.js").default} geometry Polygon geometry.
   * @param {import("ol/geom/Polygon.js").default} geometry Polygon geometry.
     * @private
     */
    Draw.prototype.createOrUpdateCustomSketchLine_ = function(geometry) {
@@ -717,22 +836,30 @@
        var ring = geometry.getLinearRing(0);
        var sketchLineGeom = this.sketchLine_.getGeometry();
        if (!sketchLineGeom) {
            sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
      sketchLineGeom = new LineString(
        ring.getFlatCoordinates(),
        ring.getLayout()
      );
            this.sketchLine_.setGeometry(sketchLineGeom);
        } else {
            sketchLineGeom.setFlatCoordinates(ring.getLayout(), ring.getFlatCoordinates());
      sketchLineGeom.setFlatCoordinates(
        ring.getLayout(),
        ring.getFlatCoordinates()
      );
            sketchLineGeom.changed();
        }
    };
    /**
     * Start the drawing.
     * @param {import("../coordinate.js").Coordinate} start Start coordinate.
   * @param {import("ol/coordinate.js").Coordinate} start Start coordinate.
     * @private
     */
    Draw.prototype.startDrawing_ = function(start) {
    if (this.overDraw) {
      return;
    }
        var projection = this.getMap().getView().getProjection();
        this.finishCoordinate_ = start;
        this._coordinate(this.finishCoordinate_)
        if (this.mode_ === Mode.POINT) {
            this.sketchCoords_ = start.slice();
        } else if (this.mode_ === Mode.POLYGON) {
@@ -746,18 +873,24 @@
        if (this.sketchLineCoords_) {
            this.sketchLine_ = new Feature(new LineString(this.sketchLineCoords_));
        }
        var geometry = this.geometryFunction_(this.sketchCoords_, undefined, projection);
    var geometry = this.geometryFunction_(
      this.sketchCoords_,
      undefined,
      projection
    );
        this.sketchFeature_ = new Feature();
        if (this.geometryName_) {
            this.sketchFeature_.setGeometryName(this.geometryName_);
        }
        this.sketchFeature_.setGeometry(geometry);
        this.updateSketchFeatures_();
        this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_));
    this.dispatchEvent(
      new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_)
    );
    };
    /**
     * Modify the drawing.
     * @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
   * @param {import("ol/coordinate.js").Coordinate} coordinate Coordinate.
     * @private
     */
    Draw.prototype.modifyDrawing_ = function(coordinate) {
@@ -782,13 +915,18 @@
        last[1] = coordinate[1];
        this.geometryFunction_(
            /** @type {!LineCoordType} */
            (this.sketchCoords_), geometry, projection);
      (this.sketchCoords_),
      geometry,
      projection
    );
        if (this.sketchPoint_) {
            var sketchPointGeom = this.sketchPoint_.getGeometry();
            sketchPointGeom.setCoordinates(coordinate);
        }
        if (geometry.getType() === GeometryType.POLYGON &&
            this.mode_ !== Mode.POLYGON) {
    if (
      geometry.getType() === GeometryType.POLYGON &&
      this.mode_ !== Mode.POLYGON
    ) {
            this.createOrUpdateCustomSketchLine_( /** @type {Polygon} */ (geometry));
        } else if (this.sketchLineCoords_) {
            var sketchLineGeom = this.sketchLine_.getGeometry();
@@ -818,7 +956,6 @@
                }
            }
            coordinates.push(coordinate.slice());
            this._coordinate(coordinate.slice())
            this.geometryFunction_(coordinates, geometry, projection);
        } else if (mode === Mode.POLYGON) {
            coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
@@ -891,6 +1028,7 @@
     * @api
     */
    Draw.prototype.finishDrawing = function() {
    // console.log("finishDrawing")
        var sketchFeature = this.abortDrawing_();
        if (!sketchFeature) {
            return;
@@ -911,11 +1049,17 @@
        }
        // cast multi-part geometries
        if (this.type_ === GeometryType.MULTI_POINT) {
            sketchFeature.setGeometry(new MultiPoint([ /** @type {PointCoordType} */ (coordinates)]));
      sketchFeature.setGeometry(
        new MultiPoint([ /** @type {PointCoordType} */ (coordinates)])
      );
        } else if (this.type_ === GeometryType.MULTI_LINE_STRING) {
            sketchFeature.setGeometry(new MultiLineString([ /** @type {LineCoordType} */ (coordinates)]));
      sketchFeature.setGeometry(
        new MultiLineString([ /** @type {LineCoordType} */ (coordinates)])
      );
        } else if (this.type_ === GeometryType.MULTI_POLYGON) {
            sketchFeature.setGeometry(new MultiPolygon([ /** @type {PolyCoordType} */ (coordinates)]));
      sketchFeature.setGeometry(
        new MultiPolygon([ /** @type {PolyCoordType} */ (coordinates)])
      );
        }
        // First dispatch event to allow full set up of feature
        this.dispatchEvent(new DrawEvent(DrawEventType.DRAWEND, sketchFeature));
@@ -926,7 +1070,6 @@
        if (this.source_) {
            this.source_.addFeature(sketchFeature);
        }
        this._coordinateOver();
    };
    /**
     * Stop drawing without adding the sketch feature to the target layer.
@@ -974,8 +1117,8 @@
        } else if (mode === Mode.POLYGON) {
            sketchCoords =
                this.sketchCoords_ && this.sketchCoords_.length ?
                /** @type {PolyCoordType} */ (this.sketchCoords_)[0] :
                [];
        /** @type {PolyCoordType} */
        (this.sketchCoords_)[0] : [];
        } else {
            return;
        }
@@ -1015,7 +1158,9 @@
        this.sketchCoords_.push(last.slice());
        this.sketchPoint_ = new Feature(new Point(last));
        this.updateSketchFeatures_();
        this.dispatchEvent(new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_));
    this.dispatchEvent(
      new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_)
    );
    };
    /**
     * Redraw the sketch features.
@@ -1048,9 +1193,9 @@
        this.overlay_.setMap(active ? map : null);
    };
    return Draw;
}(PointerInteraction));
})(PointerInteraction);
/**
 * @return {import("../style/Style.js").StyleFunction} Styles.
 * @return {import("ol/style/Style.js").StyleFunction} Styles.
 */
function getDefaultStyleFunction() {
    var styles = createEditingStyle();
@@ -1061,7 +1206,7 @@
/**
 * Create a `geometryFunction` for `type: 'Circle'` that will create a regular
 * polygon with a user specified number of sides and start angle instead of a
 * `import("../geom/Circle.js").Circle` geometry.
 * `import("ol/geom/Circle.js").Circle` geometry.
 * @param {number} [opt_sides] Number of sides of the regular polygon.
 *     Default is 32.
 * @param {number} [opt_angle] Angle of the first point in counter-clockwise
@@ -1075,13 +1220,18 @@
    return function(coordinates, opt_geometry, projection) {
        var center = fromUserCoordinate(
            /** @type {LineCoordType} */
            (coordinates)[0], projection);
      (coordinates)[0],
      projection
    );
        var end = fromUserCoordinate(
            /** @type {LineCoordType} */
            (coordinates)[coordinates.length - 1], projection);
      (coordinates)[coordinates.length - 1],
      projection
    );
        var radius = Math.sqrt(squaredCoordinateDistance(center, end));
        var geometry = opt_geometry ?
            /** @type {Polygon} */ (opt_geometry) :
      /** @type {Polygon} */
      (opt_geometry) :
            fromCircle(new Circle(center), opt_sides);
        var angle = opt_angle;
        if (!opt_angle && opt_angle !== 0) {
@@ -1113,7 +1263,8 @@
                coordinates[coordinates.length - 1],
            ]).map(function(coordinate) {
                return fromUserCoordinate(coordinate, projection);
            }));
      })
    );
        var boxCoordinates = [
            [
                getBottomLeft(extent),
@@ -1137,9 +1288,9 @@
    };
}
/**
 * Get the drawing mode.  The mode for mult-part geometries is the same as for
 * Get the drawing mode.  The mode for multi-part geometries is the same as for
 * their single-part cousins.
 * @param {import("../geom/GeometryType.js").default} type Geometry type.
 * @param {import("ol/geom/GeometryType.js").default} type Geometry type.
 * @return {Mode} Drawing mode.
 */
function getMode(type) {
@@ -1156,7 +1307,7 @@
        case GeometryType.CIRCLE:
            return Mode.CIRCLE;
        default:
            throw new Error('Invalid type: ' + type);
      throw new Error("Invalid type: " + type);
    }
}
export default Draw;