| | |
| | | var extendStatics = function (d, b) { |
| | | extendStatics = |
| | | Object.setPrototypeOf || |
| | | ({ __proto__: [] } instanceof Array && |
| | | ({ |
| | | __proto__: [] |
| | | } |
| | | instanceof Array && |
| | | function (d, b) { |
| | | d.__proto__ = b; |
| | | }) || |
| | |
| | | "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 __()); |
| | | b === null ? |
| | | Object.create(b) : |
| | | ((__.prototype = b.prototype), new __()); |
| | | }; |
| | | })(); |
| | | /** |
| | |
| | | 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 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 { |
| | | FALSE, |
| | | TRUE |
| | | } from "ol/functions.js"; |
| | | import { |
| | | always, |
| | | noModifierKeys, |
| | | shiftKeyOnly |
| | | } from "ol/events/condition.js"; |
| | | import { |
| | | boundingExtent, |
| | | getBottomLeft, |
| | |
| | | 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 { |
| | | 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("ol/geom/GeometryType.js").default} type Geometry type of |
| | |
| | | } |
| | | return DrawEvent; |
| | | })(Event); |
| | | export { DrawEvent }; |
| | | export { |
| | | DrawEvent |
| | | }; |
| | | /*** |
| | | * @template Return |
| | | * @typedef {import("ol/Observable").OnSignature<import("ol/Observable").EventTypes, import("ol/events/Event.js").default, Return> & |
| | |
| | | */ |
| | | _this.coordinate = options.coordinate; |
| | | /*** |
| | | * 输出坐标 |
| | | * 输出坐标-自定义 |
| | | */ |
| | | _this.coordinateOver = options.coordinateOver; |
| | | /*** |
| | | * 结束绘画 |
| | | * 结束绘画-自定义 |
| | | */ |
| | | _this.overDraw = false; |
| | | /*** |
| | | * 控制结束绘画 |
| | | * 控制结束绘画-自定义 |
| | | */ |
| | | _this.isPoint = options.isPoint; |
| | | /*** |
| | | * 是否是点 |
| | | * 是否是点-自定义 |
| | | */ |
| | | _this.coordinateOverPoint = options.coordinateOverPoint; |
| | | /*** |
| | | * 输出点 |
| | | * 输出点-自定义 |
| | | */ |
| | | _this.on; |
| | | /*** |
| | |
| | | * @type {number} |
| | | * @private |
| | | */ |
| | | _this.minPoints_ = options.minPoints |
| | | ? options.minPoints |
| | | : _this.mode_ === Mode.POLYGON |
| | | ? 3 |
| | | : 2; |
| | | _this.minPoints_ = options.minPoints ? |
| | | options.minPoints : |
| | | _this.mode_ === Mode.POLYGON ? |
| | | 3 : |
| | | 2; |
| | | /** |
| | | * The number of points that can be drawn before a polygon ring or line string |
| | | * is finished. The default is no restriction. |
| | |
| | | * @private |
| | | */ |
| | | _this.maxPoints_ = |
| | | _this.mode_ === Mode.CIRCLE |
| | | ? 2 |
| | | : options.maxPoints |
| | | ? options.maxPoints |
| | | : Infinity; |
| | | _this.mode_ === Mode.CIRCLE ? |
| | | 2 : |
| | | options.maxPoints ? |
| | | options.maxPoints : |
| | | Infinity; |
| | | /** |
| | | * A function to decide if a potential finish coordinate is permissible |
| | | * @private |
| | | * @type {import("ol/events/condition.js").Condition} |
| | | */ |
| | | _this.finishCondition_ = options.finishCondition |
| | | ? options.finishCondition |
| | | : TRUE; |
| | | _this.finishCondition_ = options.finishCondition ? |
| | | options.finishCondition : |
| | | TRUE; |
| | | var geometryFunction = options.geometryFunction; |
| | | if (!geometryFunction) { |
| | | var mode_1 = _this.mode_; |
| | |
| | | * @return {import("ol/geom/SimpleGeometry.js").default} A geometry. |
| | | */ |
| | | geometryFunction = function (coordinates, geometry, projection) { |
| | | var circle = geometry |
| | | ? /** @type {Circle} */ (geometry) |
| | | : new Circle([NaN, NaN]); |
| | | var circle = geometry ? |
| | | /** @type {Circle} */ |
| | | (geometry) : |
| | | new Circle([NaN, NaN]); |
| | | var center = fromUserCoordinate(coordinates[0], projection); |
| | | var squaredLength = squaredCoordinateDistance( |
| | | center, |
| | |
| | | * @type {number} |
| | | * @private |
| | | */ |
| | | _this.squaredClickTolerance_ = options.clickTolerance |
| | | ? options.clickTolerance * options.clickTolerance |
| | | : 36; |
| | | _this.squaredClickTolerance_ = options.clickTolerance ? |
| | | options.clickTolerance * options.clickTolerance : |
| | | 36; |
| | | /** |
| | | * Draw overlay where our sketch features are drawn. |
| | | * @type {VectorLayer} |
| | |
| | | if (options.freehand) { |
| | | _this.freehandCondition_ = always; |
| | | } else { |
| | | _this.freehandCondition_ = options.freehandCondition |
| | | ? options.freehandCondition |
| | | : shiftKeyOnly; |
| | | _this.freehandCondition_ = options.freehandCondition ? |
| | | options.freehandCondition : |
| | | shiftKeyOnly; |
| | | } |
| | | _this.addChangeListener(InteractionProperty.ACTIVE, _this.updateState_); |
| | | return _this; |
| | |
| | | var dx = downPx[0] - clickPx[0]; |
| | | var dy = downPx[1] - clickPx[1]; |
| | | var squaredDistance = dx * dx + dy * dy; |
| | | this.shouldHandle_ = this.freehand_ |
| | | ? squaredDistance > this.squaredClickTolerance_ |
| | | : squaredDistance <= this.squaredClickTolerance_; |
| | | this.shouldHandle_ = this.freehand_ ? |
| | | squaredDistance > this.squaredClickTolerance_ : |
| | | squaredDistance <= this.squaredClickTolerance_; |
| | | if (!this.shouldHandle_) { |
| | | return; |
| | | } |
| | |
| | | if (this.mode_ === Mode.POINT) { |
| | | this.sketchCoords_ = start.slice(); |
| | | } else if (this.mode_ === Mode.POLYGON) { |
| | | this.sketchCoords_ = [[start.slice(), start.slice()]]; |
| | | this.sketchCoords_ = [ |
| | | [start.slice(), start.slice()] |
| | | ]; |
| | | this.sketchLineCoords_ = this.sketchCoords_[0]; |
| | | } else { |
| | | this.sketchCoords_ = [start.slice(), start.slice()]; |
| | |
| | | last[0] = coordinate[0]; |
| | | last[1] = coordinate[1]; |
| | | this.geometryFunction_( |
| | | /** @type {!LineCoordType} */ (this.sketchCoords_), |
| | | /** @type {!LineCoordType} */ |
| | | (this.sketchCoords_), |
| | | geometry, |
| | | projection |
| | | ); |
| | |
| | | geometry.getType() === GeometryType.POLYGON && |
| | | this.mode_ !== Mode.POLYGON |
| | | ) { |
| | | this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry)); |
| | | this.createOrUpdateCustomSketchLine_( /** @type {Polygon} */ (geometry)); |
| | | } else if (this.sketchLineCoords_) { |
| | | var sketchLineGeom = this.sketchLine_.getGeometry(); |
| | | sketchLineGeom.setCoordinates(this.sketchLineCoords_); |
| | |
| | | } |
| | | this.geometryFunction_(coordinates, geometry, projection); |
| | | if (geometry.getType() === GeometryType.POLYGON && this.sketchLine_) { |
| | | this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry)); |
| | | this.createOrUpdateCustomSketchLine_( /** @type {Polygon} */ (geometry)); |
| | | } |
| | | } else if (mode === Mode.POLYGON) { |
| | | coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; |
| | |
| | | this.geometryFunction_(coordinates, geometry, projection); |
| | | } else if (this.mode_ === Mode.POLYGON) { |
| | | // remove the redundant last point in ring |
| | | /** @type {PolyCoordType} */ (coordinates)[0].pop(); |
| | | /** @type {PolyCoordType} */ |
| | | (coordinates)[0].pop(); |
| | | this.geometryFunction_(coordinates, geometry, projection); |
| | | coordinates = geometry.getCoordinates(); |
| | | } |
| | | // cast multi-part geometries |
| | | if (this.type_ === GeometryType.MULTI_POINT) { |
| | | sketchFeature.setGeometry( |
| | | new MultiPoint([/** @type {PointCoordType} */ (coordinates)]) |
| | | new MultiPoint([ /** @type {PointCoordType} */ (coordinates)]) |
| | | ); |
| | | } else if (this.type_ === GeometryType.MULTI_LINE_STRING) { |
| | | sketchFeature.setGeometry( |
| | | new MultiLineString([/** @type {LineCoordType} */ (coordinates)]) |
| | | new MultiLineString([ /** @type {LineCoordType} */ (coordinates)]) |
| | | ); |
| | | } else if (this.type_ === GeometryType.MULTI_POLYGON) { |
| | | sketchFeature.setGeometry( |
| | | new MultiPolygon([/** @type {PolyCoordType} */ (coordinates)]) |
| | | new MultiPolygon([ /** @type {PolyCoordType} */ (coordinates)]) |
| | | ); |
| | | } |
| | | // First dispatch event to allow full set up of feature |
| | |
| | | sketchCoords = /** @type {LineCoordType} */ (this.sketchCoords_); |
| | | } else if (mode === Mode.POLYGON) { |
| | | sketchCoords = |
| | | this.sketchCoords_ && this.sketchCoords_.length |
| | | ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0] |
| | | : []; |
| | | this.sketchCoords_ && this.sketchCoords_.length ? |
| | | /** @type {PolyCoordType} */ |
| | | (this.sketchCoords_)[0] : []; |
| | | } else { |
| | | return; |
| | | } |
| | |
| | | export function createRegularPolygon(opt_sides, opt_angle) { |
| | | return function (coordinates, opt_geometry, projection) { |
| | | var center = fromUserCoordinate( |
| | | /** @type {LineCoordType} */ (coordinates)[0], |
| | | /** @type {LineCoordType} */ |
| | | (coordinates)[0], |
| | | projection |
| | | ); |
| | | var end = fromUserCoordinate( |
| | | /** @type {LineCoordType} */ (coordinates)[coordinates.length - 1], |
| | | /** @type {LineCoordType} */ |
| | | (coordinates)[coordinates.length - 1], |
| | | projection |
| | | ); |
| | | var radius = Math.sqrt(squaredCoordinateDistance(center, end)); |
| | | var geometry = opt_geometry |
| | | ? /** @type {Polygon} */ (opt_geometry) |
| | | : fromCircle(new Circle(center), opt_sides); |
| | | var geometry = opt_geometry ? |
| | | /** @type {Polygon} */ |
| | | (opt_geometry) : |
| | | fromCircle(new Circle(center), opt_sides); |
| | | var angle = opt_angle; |
| | | if (!opt_angle && opt_angle !== 0) { |
| | | var x = end[0] - center[0]; |
| | |
| | | export function createBox() { |
| | | return function (coordinates, opt_geometry, projection) { |
| | | var extent = boundingExtent( |
| | | /** @type {LineCoordType} */ ([ |
| | | /** @type {LineCoordType} */ |
| | | ([ |
| | | coordinates[0], |
| | | coordinates[coordinates.length - 1], |
| | | ]).map(function (coordinate) { |