From e8ed1c487ea1f9bc19694bc60a0328a7fc76134a Mon Sep 17 00:00:00 2001
From: liuyg <liuyg@qq.com>
Date: Thu, 31 Mar 2022 11:40:00 +0800
Subject: [PATCH] +注释

---
 src/components/map/Draw.js |  148 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 90 insertions(+), 58 deletions(-)

diff --git a/src/components/map/Draw.js b/src/components/map/Draw.js
index ea28ce3..81a73b6 100644
--- a/src/components/map/Draw.js
+++ b/src/components/map/Draw.js
@@ -4,7 +4,10 @@
     var extendStatics = function (d, b) {
       extendStatics =
         Object.setPrototypeOf ||
-        ({ __proto__: [] } instanceof Array &&
+        ({
+            __proto__: []
+          }
+          instanceof Array &&
           function (d, b) {
             d.__proto__ = b;
           }) ||
@@ -20,13 +23,14 @@
           "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 __());
     };
   })();
 /**
@@ -46,11 +50,21 @@
 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,
@@ -58,9 +72,16 @@
   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
@@ -195,7 +216,9 @@
   }
   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> &
@@ -231,23 +254,23 @@
      */
     _this.coordinate = options.coordinate;
     /***
-     * 输出坐标
+     * 输出坐标-自定义
      */
     _this.coordinateOver = options.coordinateOver;
     /***
-     * 结束绘画
+     * 结束绘画-自定义
      */
     _this.overDraw = false;
     /***
-     * 控制结束绘画
+     * 控制结束绘画-自定义
      */
     _this.isPoint = options.isPoint;
     /***
-     * 是否是点
+     * 是否是点-自定义
      */
     _this.coordinateOverPoint = options.coordinateOverPoint;
     /***
-     * 输出点
+     * 输出点-自定义
      */
     _this.on;
     /***
@@ -335,11 +358,11 @@
      * @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.
@@ -347,19 +370,19 @@
      * @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_;
@@ -371,9 +394,10 @@
          * @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,
@@ -477,9 +501,9 @@
      * @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}
@@ -512,9 +536,9 @@
     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;
@@ -728,9 +752,9 @@
       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;
       }
@@ -837,7 +861,9 @@
     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()];
@@ -886,7 +912,8 @@
     last[0] = coordinate[0];
     last[1] = coordinate[1];
     this.geometryFunction_(
-      /** @type {!LineCoordType} */ (this.sketchCoords_),
+      /** @type {!LineCoordType} */
+      (this.sketchCoords_),
       geometry,
       projection
     );
@@ -898,7 +925,7 @@
       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_);
@@ -973,7 +1000,7 @@
       }
       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];
@@ -1013,22 +1040,23 @@
       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
@@ -1086,9 +1114,9 @@
       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;
     }
@@ -1189,17 +1217,20 @@
 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];
@@ -1224,7 +1255,8 @@
 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) {

--
Gitblit v1.9.3