deeptwins-engine-3d 0.1.63 → 0.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/assets/Build/DeepTwins/Workers/MvtVector.worker.js +1 -0
  2. package/dist/esm/{plot/utils/Algorithm.js → drawer/algorithm.js} +1 -3
  3. package/dist/esm/drawer/common.d.ts +61 -0
  4. package/dist/esm/{plot/utils/PlotCommon.js → drawer/common.js} +104 -551
  5. package/dist/esm/{plot/utils/Coordinate.d.ts → drawer/coordinate.d.ts} +1 -1
  6. package/dist/esm/drawer/index.d.ts +11 -18
  7. package/dist/esm/drawer/index.js +329 -80
  8. package/dist/esm/{plot/utils → drawer}/plotUtil.js +1 -3
  9. package/dist/esm/drawer/shape/Assemble.d.ts +34 -0
  10. package/dist/esm/drawer/shape/Assemble.js +415 -0
  11. package/dist/esm/drawer/shape/AttackArrow.d.ts +32 -0
  12. package/dist/esm/drawer/shape/AttackArrow.js +442 -0
  13. package/dist/esm/drawer/shape/BaseShape.d.ts +14 -4
  14. package/dist/esm/drawer/shape/BaseShape.js +175 -20
  15. package/dist/esm/drawer/shape/Bow.d.ts +31 -0
  16. package/dist/esm/drawer/shape/Bow.js +375 -0
  17. package/dist/esm/drawer/shape/Circle.d.ts +37 -0
  18. package/dist/esm/drawer/shape/Circle.js +461 -0
  19. package/dist/esm/drawer/shape/Curve.d.ts +29 -0
  20. package/dist/esm/drawer/shape/Curve.js +386 -0
  21. package/dist/esm/drawer/shape/DragPoint.d.ts +32 -0
  22. package/dist/esm/drawer/shape/DragPoint.js +211 -0
  23. package/dist/esm/drawer/shape/Elliptic.d.ts +38 -0
  24. package/dist/esm/drawer/shape/Elliptic.js +491 -0
  25. package/dist/esm/drawer/shape/Formation.d.ts +33 -0
  26. package/dist/esm/drawer/shape/Formation.js +395 -0
  27. package/dist/esm/drawer/shape/PincerArrow.d.ts +32 -0
  28. package/dist/esm/drawer/shape/PincerArrow.js +445 -0
  29. package/dist/esm/drawer/shape/Point.d.ts +2 -31
  30. package/dist/esm/drawer/shape/Point.js +7 -201
  31. package/dist/esm/drawer/shape/Polygon.d.ts +1 -1
  32. package/dist/esm/drawer/shape/Polygon.js +10 -81
  33. package/dist/esm/drawer/shape/Polyline.d.ts +1 -1
  34. package/dist/esm/drawer/shape/Polyline.js +10 -81
  35. package/dist/esm/drawer/shape/RegularPolygon.d.ts +37 -0
  36. package/dist/esm/drawer/shape/RegularPolygon.js +468 -0
  37. package/dist/esm/drawer/shape/RightAngleArrow.d.ts +34 -0
  38. package/dist/esm/drawer/shape/RightAngleArrow.js +423 -0
  39. package/dist/esm/drawer/shape/Sector.d.ts +37 -0
  40. package/dist/esm/drawer/shape/Sector.js +568 -0
  41. package/dist/esm/drawer/shape/StraightArrow.d.ts +34 -0
  42. package/dist/esm/drawer/shape/StraightArrow.js +422 -0
  43. package/dist/esm/drawer/shape/SwallowtailArrow.d.ts +36 -0
  44. package/dist/esm/drawer/shape/SwallowtailArrow.js +438 -0
  45. package/dist/esm/drawer/types.d.ts +23 -0
  46. package/dist/esm/drawer/types.js +11 -0
  47. package/dist/esm/drawer/utils.d.ts +14 -0
  48. package/dist/esm/drawer/utils.js +320 -2
  49. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  50. package/dist/esm/index.d.ts +1 -0
  51. package/dist/esm/index.js +5 -3
  52. package/dist/esm/measure/Area.d.ts +17 -17
  53. package/dist/esm/measure/Area.js +95 -63
  54. package/dist/esm/measure/BaseDraw.d.ts +9 -4
  55. package/dist/esm/measure/BaseDraw.js +37 -2
  56. package/dist/esm/measure/Distance.d.ts +9 -9
  57. package/dist/esm/measure/Distance.js +52 -68
  58. package/dist/esm/measure/index.d.ts +16 -26
  59. package/dist/esm/measure/index.js +72 -84
  60. package/dist/esm/measure/types.d.ts +94 -0
  61. package/dist/esm/measure/types.js +17 -0
  62. package/dist/esm/measure/utils.d.ts +7 -7
  63. package/dist/esm/measure/utils.js +43 -24
  64. package/dist/esm/tileLayer/MvtVectorLoad.d.ts +241 -0
  65. package/dist/esm/tileLayer/MvtVectorLoad.js +1353 -0
  66. package/dist/esm/tileLayer/MvtVectorWorkerClient.d.ts +25 -0
  67. package/dist/esm/tileLayer/MvtVectorWorkerClient.js +126 -0
  68. package/dist/esm/tool/utils.js +1 -1
  69. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  70. package/package.json +2 -1
  71. package/dist/assets/Build/DeepTwins/Image/compass/pointer-white.png +0 -0
  72. package/dist/esm/plot/create/CreateAssemble.d.ts +0 -2
  73. package/dist/esm/plot/create/CreateAssemble.js +0 -63
  74. package/dist/esm/plot/create/CreateAttackArrow.d.ts +0 -5
  75. package/dist/esm/plot/create/CreateAttackArrow.js +0 -75
  76. package/dist/esm/plot/create/CreateBillboard.d.ts +0 -2
  77. package/dist/esm/plot/create/CreateBillboard.js +0 -47
  78. package/dist/esm/plot/create/CreateBow.d.ts +0 -2
  79. package/dist/esm/plot/create/CreateBow.js +0 -63
  80. package/dist/esm/plot/create/CreateCircle.d.ts +0 -2
  81. package/dist/esm/plot/create/CreateCircle.js +0 -68
  82. package/dist/esm/plot/create/CreateCurve.d.ts +0 -2
  83. package/dist/esm/plot/create/CreateCurve.js +0 -76
  84. package/dist/esm/plot/create/CreateElliptic.d.ts +0 -2
  85. package/dist/esm/plot/create/CreateElliptic.js +0 -69
  86. package/dist/esm/plot/create/CreateFlag.d.ts +0 -2
  87. package/dist/esm/plot/create/CreateFlag.js +0 -80
  88. package/dist/esm/plot/create/CreateFormation.d.ts +0 -2
  89. package/dist/esm/plot/create/CreateFormation.js +0 -65
  90. package/dist/esm/plot/create/CreateFreeLine.d.ts +0 -2
  91. package/dist/esm/plot/create/CreateFreeLine.js +0 -69
  92. package/dist/esm/plot/create/CreateFreePolygon.d.ts +0 -2
  93. package/dist/esm/plot/create/CreateFreePolygon.js +0 -65
  94. package/dist/esm/plot/create/CreateLabel.d.ts +0 -2
  95. package/dist/esm/plot/create/CreateLabel.js +0 -55
  96. package/dist/esm/plot/create/CreateLineArrow.d.ts +0 -2
  97. package/dist/esm/plot/create/CreateLineArrow.js +0 -79
  98. package/dist/esm/plot/create/CreatePincerArrow.d.ts +0 -5
  99. package/dist/esm/plot/create/CreatePincerArrow.js +0 -73
  100. package/dist/esm/plot/create/CreatePoint.d.ts +0 -2
  101. package/dist/esm/plot/create/CreatePoint.js +0 -47
  102. package/dist/esm/plot/create/CreatePolygon.d.ts +0 -2
  103. package/dist/esm/plot/create/CreatePolygon.js +0 -80
  104. package/dist/esm/plot/create/CreatePolyline.d.ts +0 -2
  105. package/dist/esm/plot/create/CreatePolyline.js +0 -70
  106. package/dist/esm/plot/create/CreateRectangle.d.ts +0 -2
  107. package/dist/esm/plot/create/CreateRectangle.js +0 -60
  108. package/dist/esm/plot/create/CreateRegularPolygon.d.ts +0 -2
  109. package/dist/esm/plot/create/CreateRegularPolygon.js +0 -75
  110. package/dist/esm/plot/create/CreateRightAngleArrow.d.ts +0 -5
  111. package/dist/esm/plot/create/CreateRightAngleArrow.js +0 -73
  112. package/dist/esm/plot/create/CreateRoundRectangle.d.ts +0 -2
  113. package/dist/esm/plot/create/CreateRoundRectangle.js +0 -63
  114. package/dist/esm/plot/create/CreateSector.d.ts +0 -2
  115. package/dist/esm/plot/create/CreateSector.js +0 -65
  116. package/dist/esm/plot/create/CreateStraightArrow.d.ts +0 -5
  117. package/dist/esm/plot/create/CreateStraightArrow.js +0 -65
  118. package/dist/esm/plot/create/CreateSwallowtailArrow.d.ts +0 -5
  119. package/dist/esm/plot/create/CreateSwallowtailArrow.js +0 -67
  120. package/dist/esm/plot/create/index.d.ts +0 -25
  121. package/dist/esm/plot/create/index.js +0 -25
  122. package/dist/esm/plot/edit/EditAssemble.d.ts +0 -8
  123. package/dist/esm/plot/edit/EditAssemble.js +0 -120
  124. package/dist/esm/plot/edit/EditAttackArrow.d.ts +0 -8
  125. package/dist/esm/plot/edit/EditAttackArrow.js +0 -182
  126. package/dist/esm/plot/edit/EditBillboard.d.ts +0 -7
  127. package/dist/esm/plot/edit/EditBillboard.js +0 -70
  128. package/dist/esm/plot/edit/EditBow.d.ts +0 -8
  129. package/dist/esm/plot/edit/EditBow.js +0 -119
  130. package/dist/esm/plot/edit/EditCircle.d.ts +0 -8
  131. package/dist/esm/plot/edit/EditCircle.js +0 -133
  132. package/dist/esm/plot/edit/EditCurve.d.ts +0 -8
  133. package/dist/esm/plot/edit/EditCurve.js +0 -180
  134. package/dist/esm/plot/edit/EditElliptic.d.ts +0 -8
  135. package/dist/esm/plot/edit/EditElliptic.js +0 -144
  136. package/dist/esm/plot/edit/EditFlag.d.ts +0 -8
  137. package/dist/esm/plot/edit/EditFlag.js +0 -121
  138. package/dist/esm/plot/edit/EditFormation.d.ts +0 -8
  139. package/dist/esm/plot/edit/EditFormation.js +0 -120
  140. package/dist/esm/plot/edit/EditLabel.d.ts +0 -7
  141. package/dist/esm/plot/edit/EditLabel.js +0 -100
  142. package/dist/esm/plot/edit/EditLineArrow.d.ts +0 -8
  143. package/dist/esm/plot/edit/EditLineArrow.js +0 -180
  144. package/dist/esm/plot/edit/EditPincerArrow.d.ts +0 -8
  145. package/dist/esm/plot/edit/EditPincerArrow.js +0 -121
  146. package/dist/esm/plot/edit/EditPoint.d.ts +0 -7
  147. package/dist/esm/plot/edit/EditPoint.js +0 -70
  148. package/dist/esm/plot/edit/EditPolygon.d.ts +0 -8
  149. package/dist/esm/plot/edit/EditPolygon.js +0 -181
  150. package/dist/esm/plot/edit/EditPolyline.d.ts +0 -8
  151. package/dist/esm/plot/edit/EditPolyline.js +0 -179
  152. package/dist/esm/plot/edit/EditRectangle.d.ts +0 -8
  153. package/dist/esm/plot/edit/EditRectangle.js +0 -119
  154. package/dist/esm/plot/edit/EditRegularPolygon.d.ts +0 -8
  155. package/dist/esm/plot/edit/EditRegularPolygon.js +0 -170
  156. package/dist/esm/plot/edit/EditRightAngleArrow.d.ts +0 -8
  157. package/dist/esm/plot/edit/EditRightAngleArrow.js +0 -143
  158. package/dist/esm/plot/edit/EditRoundRectangle.d.ts +0 -8
  159. package/dist/esm/plot/edit/EditRoundRectangle.js +0 -119
  160. package/dist/esm/plot/edit/EditSector.d.ts +0 -8
  161. package/dist/esm/plot/edit/EditSector.js +0 -120
  162. package/dist/esm/plot/edit/EditStraightArrow.d.ts +0 -8
  163. package/dist/esm/plot/edit/EditStraightArrow.js +0 -120
  164. package/dist/esm/plot/edit/EditSwallowtailArrow.d.ts +0 -8
  165. package/dist/esm/plot/edit/EditSwallowtailArrow.js +0 -121
  166. package/dist/esm/plot/edit/index.d.ts +0 -23
  167. package/dist/esm/plot/edit/index.js +0 -23
  168. package/dist/esm/plot/utils/DomUtil.d.ts +0 -34
  169. package/dist/esm/plot/utils/DomUtil.js +0 -100
  170. package/dist/esm/plot/utils/PlotCommon.d.ts +0 -101
  171. package/dist/esm/plot/utils/ReminderTip.d.ts +0 -10
  172. package/dist/esm/plot/utils/ReminderTip.js +0 -67
  173. package/dist/esm/plot/utils/Tooltip.d.ts +0 -3
  174. package/dist/esm/plot/utils/Tooltip.js +0 -97
  175. /package/dist/esm/{plot/utils/Algorithm.d.ts → drawer/algorithm.d.ts} +0 -0
  176. /package/dist/esm/{plot/utils/Coordinate.js → drawer/coordinate.js} +0 -0
  177. /package/dist/esm/{plot/utils → drawer}/plotUtil.d.ts +0 -0
@@ -1,12 +1,16 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
3
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
15
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -23,33 +27,45 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
23
27
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
24
28
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
29
  import { centerOfMass, point, polygon } from '@turf/turf';
26
- import { SceneTransforms } from 'deeptwins-cesium';
27
- import { STATUS } from "../drawer";
28
- import { lngLatAltToCartesian3 } from "../tool/utils";
29
30
  import BaseDraw from "./BaseDraw";
31
+ import { AREA_SHAPE_TYPE, STATUS } from "./types";
30
32
  import * as utils from "./utils";
31
33
  var Area = /*#__PURE__*/function (_BaseDraw) {
32
34
  _inherits(Area, _BaseDraw);
33
35
  var _super = _createSuper(Area);
34
- function Area(measureContext, config) {
36
+ function Area(measureContext) {
35
37
  var _this;
38
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
39
  _classCallCheck(this, Area);
37
40
  _this = _super.call(this, measureContext);
38
- _defineProperty(_assertThisInitialized(_this), "_type", 'area');
39
41
  _defineProperty(_assertThisInitialized(_this), "_config", void 0);
40
- // 线图层
41
- _defineProperty(_assertThisInitialized(_this), "_instance", void 0);
42
+ _defineProperty(_assertThisInitialized(_this), "_shapeType", void 0);
43
+ // 图形图层
44
+ _defineProperty(_assertThisInitialized(_this), "_instance", null);
42
45
  _defineProperty(_assertThisInitialized(_this), "_area", 0);
43
46
  // 鼠标移动的label
44
- _defineProperty(_assertThisInitialized(_this), "_areaLayer", void 0);
47
+ _defineProperty(_assertThisInitialized(_this), "_areaLayer", null);
45
48
  _this._config = config;
49
+ _this._shapeType = _this._resolveShapeType(config.shapeType);
46
50
  _this._init();
47
51
  return _this;
48
52
  }
49
53
  _createClass(Area, [{
50
54
  key: "_init",
51
55
  value: function _init() {
52
- this._instance = this._drawer.startDraw('polygon', this._config);
56
+ this._instance = this._drawer.startDraw(this._shapeType, this._getDrawerConfig());
57
+ }
58
+ }, {
59
+ key: "_resolveShapeType",
60
+ value: function _resolveShapeType(shapeType) {
61
+ return Object.values(AREA_SHAPE_TYPE).includes(shapeType) ? shapeType : AREA_SHAPE_TYPE.POLYGON;
62
+ }
63
+ }, {
64
+ key: "_getDrawerConfig",
65
+ value: function _getDrawerConfig() {
66
+ var drawerConfig = _objectSpread({}, this._config);
67
+ delete drawerConfig.shapeType;
68
+ return drawerConfig;
53
69
  }
54
70
 
55
71
  // 绘制
@@ -58,48 +74,30 @@ var Area = /*#__PURE__*/function (_BaseDraw) {
58
74
  value: function drawing(positions) {
59
75
  if (!this._canOperate()) return;
60
76
  this._measureContext._changeStatus(STATUS.DRAWING);
61
- if (positions.length < 3) {
62
- this._destroyAreaLabel();
63
- return;
64
- }
65
- var polygonPositions = [].concat(_toConsumableArray(positions), [positions[0]]);
66
- this._area = this._calculateArea(polygonPositions);
67
- var center = centerOfMass(polygon([polygonPositions]));
68
- this._createAreaLabel(center.geometry.coordinates, "\u9762\u79EF".concat(utils.formatArea(this._area)));
69
- return {
70
- area: this._area
71
- };
77
+ return this._updateArea(positions);
72
78
  }
73
79
 
74
80
  // 点位修改
75
81
  }, {
76
82
  key: "pointsChange",
77
- value: function pointsChange(layer, positions) {
78
- if (!this._canOperate()) return;
79
- if (positions.length < 3) {
80
- this._destroyAreaLabel();
81
- return {
82
- area: 0
83
- };
84
- }
85
- var polygonPositions = [].concat(_toConsumableArray(positions), [positions[0]]);
86
- this._area = this._calculateArea(polygonPositions);
87
- var center = centerOfMass(polygon([polygonPositions]));
88
- this._createAreaLabel(center.geometry.coordinates, "\u9762\u79EF".concat(utils.formatArea(this._area)));
89
- return {
90
- area: this._area
83
+ value: function pointsChange(_layer, positions) {
84
+ if (!this._canOperate()) return {
85
+ area: 0
91
86
  };
87
+ return this._updateArea(positions);
92
88
  }
93
89
 
94
90
  // 结束绘制
95
91
  }, {
96
92
  key: "drawEnd",
97
- value: function drawEnd(positions) {
98
- if (!this._canOperate()) return;
93
+ value: function drawEnd() {
94
+ var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
95
+ if (!this._canOperate()) return {
96
+ area: 0
97
+ };
99
98
  this._measureContext._changeStatus(STATUS.END_DRAW);
100
99
  this._measureContext.setDrawerLayer(this.id, this);
101
- var polygonPositions = [].concat(_toConsumableArray(positions), [positions[0]]);
102
- this._area = this._calculateArea(polygonPositions);
100
+ this._area = this._calculateArea(this._toPolygonPositions(positions));
103
101
  this.startEdit();
104
102
  return {
105
103
  area: this._area
@@ -117,10 +115,12 @@ var Area = /*#__PURE__*/function (_BaseDraw) {
117
115
  // 结束编辑
118
116
  }, {
119
117
  key: "endEdit",
120
- value: function endEdit(positions) {
121
- if (!this._canOperate()) return;
122
- var polygonPositions = [].concat(_toConsumableArray(positions), [positions[0]]);
123
- this._area = this._calculateArea(polygonPositions);
118
+ value: function endEdit() {
119
+ var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
120
+ if (!this._canOperate()) return {
121
+ area: 0
122
+ };
123
+ this._area = this._calculateArea(this._toPolygonPositions(positions));
124
124
  return {
125
125
  area: this._area
126
126
  };
@@ -131,21 +131,25 @@ var Area = /*#__PURE__*/function (_BaseDraw) {
131
131
  key: "_calculateArea",
132
132
  value: function _calculateArea(positions) {
133
133
  var _this2 = this;
134
- if (!this._canOperate()) return;
135
- if (positions.length < 4) return;
136
- var area = 0;
137
- var config = _objectSpread(_objectSpread({}, this._measureContext.options), this._config);
138
- var positionsC3 = positions.map(function (t) {
139
- return lngLatAltToCartesian3(t[0], t[1], t[2]);
134
+ if (positions.length < 4) {
135
+ return 0;
136
+ }
137
+ var config = this.getMeasureConfig(this._config);
138
+ var positionsC3 = positions.map(function (item) {
139
+ return _this2.toCartesian3(item);
140
140
  });
141
141
  if (config.clampToGround) {
142
- area = utils.calculateSurfaceArea(this.getMap(), positionsC3.map(function (item) {
143
- return SceneTransforms.worldToWindowCoordinates(_this2.getMap().scene, item);
144
- }));
145
- } else {
146
- area = utils.getArea(this.getMap(), positionsC3);
142
+ var windowPositions = positions.map(function (item) {
143
+ return _this2.toWindowPosition(item);
144
+ });
145
+ if (windowPositions.some(function (item) {
146
+ return !item;
147
+ })) {
148
+ return 0;
149
+ }
150
+ return utils.calculateSurfaceArea(this.getMap(), windowPositions, config.splitNum);
147
151
  }
148
- return area;
152
+ return utils.getArea(this.getMap(), positionsC3);
149
153
  }
150
154
 
151
155
  // 绘制area label
@@ -167,8 +171,36 @@ var Area = /*#__PURE__*/function (_BaseDraw) {
167
171
  }, {
168
172
  key: "_destroyAreaLabel",
169
173
  value: function _destroyAreaLabel() {
170
- this._areaLayer && this._areaLayer.destroy();
171
- this._areaLayer = null;
174
+ this._areaLayer = this.destroyLabelLayer(this._areaLayer);
175
+ }
176
+ }, {
177
+ key: "_updateArea",
178
+ value: function _updateArea(positions) {
179
+ if (positions.length < 3) {
180
+ this._area = 0;
181
+ this._destroyAreaLabel();
182
+ return {
183
+ area: 0
184
+ };
185
+ }
186
+ var polygonPositions = this._toPolygonPositions(positions);
187
+ this._area = this._calculateArea(polygonPositions);
188
+ var center = centerOfMass(polygon([polygonPositions]));
189
+ var _center$geometry$coor = _slicedToArray(center.geometry.coordinates, 2),
190
+ lng = _center$geometry$coor[0],
191
+ lat = _center$geometry$coor[1];
192
+ this._createAreaLabel([lng, lat, 0], "\u9762\u79EF".concat(utils.formatArea(this._area)));
193
+ return {
194
+ area: this._area
195
+ };
196
+ }
197
+ }, {
198
+ key: "_toPolygonPositions",
199
+ value: function _toPolygonPositions(positions) {
200
+ if (positions.length < 3) {
201
+ return [];
202
+ }
203
+ return [].concat(_toConsumableArray(positions), [positions[0]]);
172
204
  }
173
205
 
174
206
  // 销毁
@@ -176,11 +208,11 @@ var Area = /*#__PURE__*/function (_BaseDraw) {
176
208
  key: "destroy",
177
209
  value: function destroy() {
178
210
  if (!this._canOperate()) return;
179
- _get(_getPrototypeOf(Area.prototype), "destroy", this).call(this);
180
- this._drawer.removeDrawerLayer(this._instance);
211
+ var layer = this._instance;
212
+ this._destroyAreaLabel();
181
213
  this._instance = null;
182
- this._areaLayer && this._areaLayer.remove();
183
- this._areaLayer = null;
214
+ _get(_getPrototypeOf(Area.prototype), "destroy", this).call(this);
215
+ layer && this._drawer.removeDrawerLayer(layer);
184
216
  }
185
217
  }]);
186
218
  return Area;
@@ -1,13 +1,18 @@
1
- import { MeasureContext } from './index';
1
+ import { type Cartesian2, type Cartesian3 } from 'deeptwins-cesium';
2
+ import { MeasureContext, MeasureDrawConfig, MeasureLabelLayer, MeasureMap, MeasurePosition, ResolvedMeasureConfig } from './types';
2
3
  declare class BaseDraw {
3
4
  _measureContext: MeasureContext;
4
5
  id: string;
5
- _drawer: any;
6
+ _drawer: MeasureContext['drawer'];
6
7
  isDestroyed: boolean;
7
8
  constructor(measureContext: MeasureContext);
8
9
  _canOperate(): boolean;
9
- getMap(): any;
10
- createLabelLayer(position: any, text: string, style?: any): any;
10
+ getMap(): MeasureMap;
11
+ createLabelLayer(position: MeasurePosition, text: string, style?: Record<string, any>): MeasureLabelLayer;
12
+ protected getMeasureConfig(config?: MeasureDrawConfig): ResolvedMeasureConfig;
13
+ protected toCartesian3(position: MeasurePosition): Cartesian3;
14
+ protected toWindowPosition(position: MeasurePosition): Cartesian2 | undefined;
15
+ protected destroyLabelLayer<T extends MeasureLabelLayer | null | undefined>(layer: T): null;
11
16
  destroy(): void;
12
17
  }
13
18
  export default BaseDraw;
@@ -1,4 +1,10 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -9,9 +15,10 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
9
15
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
16
  import { point } from '@turf/turf';
11
17
  import * as Cesium from 'deeptwins-cesium';
18
+ import { SceneTransforms } from 'deeptwins-cesium';
12
19
  import { v4 as uuidV4 } from 'uuid';
13
20
  import PositionProperty from "../property/PositionProperty";
14
- import { error } from "../tool/utils";
21
+ import { error, lngLatAltToCartesian3 } from "../tool/utils";
15
22
  var BaseDraw = /*#__PURE__*/function () {
16
23
  function BaseDraw(measureContext) {
17
24
  _classCallCheck(this, BaseDraw);
@@ -37,7 +44,7 @@ var BaseDraw = /*#__PURE__*/function () {
37
44
  }, {
38
45
  key: "getMap",
39
46
  value: function getMap() {
40
- return this._measureContext && this._measureContext.getMap();
47
+ return this._measureContext.getMap();
41
48
  }
42
49
 
43
50
  // 创建label图层
@@ -58,6 +65,34 @@ var BaseDraw = /*#__PURE__*/function () {
58
65
  positionProperty: new PositionProperty()
59
66
  });
60
67
  }
68
+ }, {
69
+ key: "getMeasureConfig",
70
+ value: function getMeasureConfig() {
71
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
72
+ return _objectSpread(_objectSpread({}, this._measureContext.options), config);
73
+ }
74
+ }, {
75
+ key: "toCartesian3",
76
+ value: function toCartesian3(position) {
77
+ var _position = _slicedToArray(position, 3),
78
+ lng = _position[0],
79
+ lat = _position[1],
80
+ _position$ = _position[2],
81
+ alt = _position$ === void 0 ? 0 : _position$;
82
+ return lngLatAltToCartesian3(lng, lat, alt);
83
+ }
84
+ }, {
85
+ key: "toWindowPosition",
86
+ value: function toWindowPosition(position) {
87
+ var _SceneTransforms$worl;
88
+ return (_SceneTransforms$worl = SceneTransforms.worldToWindowCoordinates(this.getMap().scene, this.toCartesian3(position))) !== null && _SceneTransforms$worl !== void 0 ? _SceneTransforms$worl : undefined;
89
+ }
90
+ }, {
91
+ key: "destroyLabelLayer",
92
+ value: function destroyLabelLayer(layer) {
93
+ layer === null || layer === void 0 || layer.destroy();
94
+ return null;
95
+ }
61
96
  }, {
62
97
  key: "destroy",
63
98
  value: function destroy() {
@@ -1,22 +1,22 @@
1
1
  import BaseDraw from './BaseDraw';
2
- import { MeasureContext } from './index';
3
- declare class Distance extends BaseDraw {
4
- private readonly _type;
2
+ import { DistanceMeasureResult, MeasureContext, MeasureDrawConfig, MeasureLayer, MeasurePosition, MeasureShapeLayer } from './types';
3
+ declare class Distance extends BaseDraw implements MeasureLayer {
5
4
  private _config;
6
- private _instance;
5
+ _instance: MeasureShapeLayer | null;
7
6
  private _measureCache;
8
7
  private _mouseLabelLayer;
9
- constructor(measureContext: MeasureContext, config: any);
8
+ constructor(measureContext: MeasureContext, config?: MeasureDrawConfig);
10
9
  private _init;
11
- drawing(positions: any): any;
12
- pointsChange(layer: any, positions: any): any[] | undefined;
13
- drawEnd(): any[] | undefined;
10
+ drawing(positions: MeasurePosition[]): {} | undefined;
11
+ pointsChange(layer: MeasureShapeLayer, positions: MeasurePosition[]): DistanceMeasureResult;
12
+ drawEnd(): DistanceMeasureResult;
14
13
  startEdit(): void;
15
- endEdit(): any[] | undefined;
14
+ endEdit(): DistanceMeasureResult;
16
15
  private _createMouseMoveLabel;
17
16
  private _destroyMouseMoveLabel;
18
17
  private _calculateDistance;
19
18
  private _calculateMouseDistance;
19
+ private _calculateSegmentDistance;
20
20
  private _createMeasureCacheText;
21
21
  destroy(): void;
22
22
  }
@@ -1,6 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
2
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
3
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -18,26 +16,24 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
18
16
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
17
  import { point } from '@turf/turf';
20
18
  import * as Cesium from 'deeptwins-cesium';
21
- import { SceneTransforms } from 'deeptwins-cesium';
22
- import { STATUS } from "../drawer";
23
- import { lngLatAltToCartesian3 } from "../tool/utils";
24
19
  import BaseDraw from "./BaseDraw";
20
+ import { STATUS } from "./types";
25
21
  import * as utils from "./utils";
26
22
  var Distance = /*#__PURE__*/function (_BaseDraw) {
27
23
  _inherits(Distance, _BaseDraw);
28
24
  var _super = _createSuper(Distance);
29
- function Distance(measureContext, config) {
25
+ function Distance(measureContext) {
30
26
  var _this;
27
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
28
  _classCallCheck(this, Distance);
32
29
  _this = _super.call(this, measureContext);
33
- _defineProperty(_assertThisInitialized(_this), "_type", 'distance');
34
30
  _defineProperty(_assertThisInitialized(_this), "_config", void 0);
35
31
  // 线图层
36
- _defineProperty(_assertThisInitialized(_this), "_instance", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "_instance", null);
37
33
  // 测量缓存数据
38
34
  _defineProperty(_assertThisInitialized(_this), "_measureCache", []);
39
35
  // 鼠标移动的label
40
- _defineProperty(_assertThisInitialized(_this), "_mouseLabelLayer", void 0);
36
+ _defineProperty(_assertThisInitialized(_this), "_mouseLabelLayer", null);
41
37
  _this._config = config;
42
38
  _this._init();
43
39
  return _this;
@@ -54,9 +50,12 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
54
50
  value: function drawing(positions) {
55
51
  if (!this._canOperate()) return;
56
52
  this._measureContext._changeStatus(STATUS.DRAWING);
57
- if (positions.length < 2) return {};
53
+ if (positions.length < 2) {
54
+ this._destroyMouseMoveLabel();
55
+ return {};
56
+ }
58
57
  var mouseDistance = this._calculateMouseDistance(positions);
59
- this._createMouseMoveLabel(positions.slice(-1)[0], "\u603B\u8BA1".concat(utils.formatLength(mouseDistance.allDistance), "\n(+").concat(utils.formatLength(mouseDistance.distance), ")"));
58
+ this._createMouseMoveLabel(positions[positions.length - 1], "\u603B\u8BA1".concat(utils.formatLength(mouseDistance.allDistance), "\n(+").concat(utils.formatLength(mouseDistance.distance), ")"));
60
59
  return mouseDistance;
61
60
  }
62
61
 
@@ -64,26 +63,19 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
64
63
  }, {
65
64
  key: "pointsChange",
66
65
  value: function pointsChange(layer, positions) {
67
- if (!this._canOperate()) return;
68
- // 未返回点位 销毁随鼠标移动的label
69
- if (!positions.length) {
70
- this._destroyMouseMoveLabel();
71
- return [];
72
- }
73
- // 小于两个点时清除测量缓存数据
66
+ if (!this._canOperate()) return [];
74
67
  if (positions.length < 2) {
68
+ var _layer$dragPoints$;
75
69
  this._measureCache = [];
76
- } else {
77
- this._calculateDistance(positions);
78
- }
79
- if (!this._measureCache.length) {
80
- layer.dragPoints[0].labelLayer.setStyle({
70
+ this._destroyMouseMoveLabel();
71
+ (_layer$dragPoints$ = layer.dragPoints[0]) === null || _layer$dragPoints$ === void 0 || _layer$dragPoints$.labelLayer.setStyle({
81
72
  show: true,
82
73
  text: '起点'
83
74
  });
84
- } else {
85
- this._createMeasureCacheText(layer.dragPoints);
75
+ return this._measureCache;
86
76
  }
77
+ this._calculateDistance(positions);
78
+ this._createMeasureCacheText(layer.dragPoints);
87
79
  return this._measureCache;
88
80
  }
89
81
 
@@ -91,7 +83,7 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
91
83
  }, {
92
84
  key: "drawEnd",
93
85
  value: function drawEnd() {
94
- if (!this._canOperate()) return;
86
+ if (!this._canOperate()) return [];
95
87
  this._measureContext._changeStatus(STATUS.END_DRAW);
96
88
  this._measureContext.setDrawerLayer(this.id, this);
97
89
  this._destroyMouseMoveLabel();
@@ -111,7 +103,7 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
111
103
  }, {
112
104
  key: "endEdit",
113
105
  value: function endEdit() {
114
- if (!this._canOperate()) return;
106
+ if (!this._canOperate()) return [];
115
107
  return this._measureCache;
116
108
  }
117
109
 
@@ -139,40 +131,30 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
139
131
  }, {
140
132
  key: "_destroyMouseMoveLabel",
141
133
  value: function _destroyMouseMoveLabel() {
142
- this._mouseLabelLayer && this._mouseLabelLayer.destroy();
143
- this._mouseLabelLayer = null;
134
+ this._mouseLabelLayer = this.destroyLabelLayer(this._mouseLabelLayer);
144
135
  }
145
136
 
146
137
  // 计算距离
147
138
  }, {
148
139
  key: "_calculateDistance",
149
140
  value: function _calculateDistance(positions) {
150
- if (!this._canOperate()) return;
151
- if (positions.length < 2) return;
152
- var distanceList = [];
141
+ if (positions.length < 2) {
142
+ this._measureCache = [];
143
+ return;
144
+ }
145
+ var config = this.getMeasureConfig(this._config);
146
+ var allDistance = 0;
153
147
  this._measureCache = [];
154
- var config = _objectSpread(_objectSpread({}, this._measureContext.options), this._config);
155
148
  for (var i = 0; i < positions.length - 1; i++) {
156
149
  var start = positions[i];
157
150
  var end = positions[i + 1];
158
- var startC3 = lngLatAltToCartesian3(start[0], start[1], start[2]);
159
- var endC3 = lngLatAltToCartesian3(end[0], end[1], end[2]);
160
- var distance = 0;
161
- if (config.clampToGround) {
162
- var startC2 = SceneTransforms.worldToWindowCoordinates(this.getMap().scene, startC3);
163
- var endC2 = SceneTransforms.worldToWindowCoordinates(this.getMap().scene, endC3);
164
- distance = utils.calculateSurfaceDistance(this.getMap(), startC2, endC2, config.splitNum);
165
- } else {
166
- distance = utils.getDistance(startC3, endC3);
167
- }
168
- distanceList.push(distance);
151
+ var distance = this._calculateSegmentDistance(start, end, config);
152
+ allDistance += distance;
169
153
  this._measureCache.push({
170
154
  start: start,
171
155
  end: end,
172
156
  distance: distance,
173
- allDistance: distanceList.reduce(function (sum, distance) {
174
- return sum + distance;
175
- }, 0)
157
+ allDistance: allDistance
176
158
  });
177
159
  }
178
160
  }
@@ -181,21 +163,10 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
181
163
  }, {
182
164
  key: "_calculateMouseDistance",
183
165
  value: function _calculateMouseDistance(positions) {
184
- if (!this._canOperate()) return;
185
- if (positions.length < 2) return;
186
- var start = positions.slice(-2, -1)[0];
187
- var end = positions.slice(-1)[0];
188
- var startC3 = lngLatAltToCartesian3(start[0], start[1], start[2]);
189
- var endC3 = lngLatAltToCartesian3(end[0], end[1], end[2]);
190
- var distance = 0;
191
- var config = _objectSpread(_objectSpread({}, this._measureContext.options), this._config);
192
- if (config.clampToGround) {
193
- var startC2 = SceneTransforms.worldToWindowCoordinates(this.getMap().scene, startC3);
194
- var endC2 = SceneTransforms.worldToWindowCoordinates(this.getMap().scene, endC3);
195
- distance = utils.calculateSurfaceDistance(this.getMap(), startC2, endC2, config.splitNum);
196
- } else {
197
- distance = utils.getDistance(startC3, endC3);
198
- }
166
+ var start = positions[positions.length - 2];
167
+ var end = positions[positions.length - 1];
168
+ var config = this.getMeasureConfig(this._config);
169
+ var distance = this._calculateSegmentDistance(start, end, config);
199
170
  return {
200
171
  distance: distance,
201
172
  allDistance: this._measureCache.reduce(function (sum, item) {
@@ -203,6 +174,19 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
203
174
  }, distance)
204
175
  };
205
176
  }
177
+ }, {
178
+ key: "_calculateSegmentDistance",
179
+ value: function _calculateSegmentDistance(start, end, config) {
180
+ if (!config.clampToGround) {
181
+ return utils.getDistance(this.toCartesian3(start), this.toCartesian3(end));
182
+ }
183
+ var startC2 = this.toWindowPosition(start);
184
+ var endC2 = this.toWindowPosition(end);
185
+ if (!startC2 || !endC2) {
186
+ return 0;
187
+ }
188
+ return utils.calculateSurfaceDistance(this.getMap(), startC2, endC2, config.splitNum);
189
+ }
206
190
 
207
191
  // 根据缓存数据创建文字
208
192
  }, {
@@ -210,10 +194,11 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
210
194
  value: function _createMeasureCacheText(dragPoints) {
211
195
  if (!this._canOperate()) return;
212
196
  for (var i = 0; i < this._measureCache.length; i++) {
197
+ var _dragPoints;
213
198
  var _this$_measureCache$i = this._measureCache[i],
214
199
  distance = _this$_measureCache$i.distance,
215
200
  allDistance = _this$_measureCache$i.allDistance;
216
- dragPoints[i + 1].labelLayer.setStyle({
201
+ (_dragPoints = dragPoints[i + 1]) === null || _dragPoints === void 0 || _dragPoints.labelLayer.setStyle({
217
202
  show: true,
218
203
  text: "".concat(utils.formatLength(allDistance), "\n(+").concat(utils.formatLength(distance), ")")
219
204
  });
@@ -225,13 +210,12 @@ var Distance = /*#__PURE__*/function (_BaseDraw) {
225
210
  key: "destroy",
226
211
  value: function destroy() {
227
212
  if (!this._canOperate()) return;
228
- _get(_getPrototypeOf(Distance.prototype), "destroy", this).call(this);
229
- this._drawer.removeDrawerLayer(this._instance);
230
- this._instance = null;
231
- this._mouseLabelLayer && this._mouseLabelLayer.remove();
232
- this._mouseLabelLayer = null;
213
+ var layer = this._instance;
233
214
  this._measureCache = [];
234
215
  this._destroyMouseMoveLabel();
216
+ this._instance = null;
217
+ _get(_getPrototypeOf(Distance.prototype), "destroy", this).call(this);
218
+ layer && this._drawer.removeDrawerLayer(layer);
235
219
  }
236
220
  }]);
237
221
  return Distance;