deeptwins-engine-3d 0.1.64 → 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 (169) hide show
  1. package/dist/esm/{plot/utils/Algorithm.js → drawer/algorithm.js} +1 -3
  2. package/dist/esm/drawer/common.d.ts +61 -0
  3. package/dist/esm/{plot/utils/PlotCommon.js → drawer/common.js} +104 -551
  4. package/dist/esm/drawer/index.d.ts +11 -18
  5. package/dist/esm/drawer/index.js +329 -80
  6. package/dist/esm/{plot/utils → drawer}/plotUtil.js +1 -3
  7. package/dist/esm/drawer/shape/Assemble.d.ts +34 -0
  8. package/dist/esm/drawer/shape/Assemble.js +415 -0
  9. package/dist/esm/drawer/shape/AttackArrow.d.ts +32 -0
  10. package/dist/esm/drawer/shape/AttackArrow.js +442 -0
  11. package/dist/esm/drawer/shape/BaseShape.d.ts +14 -4
  12. package/dist/esm/drawer/shape/BaseShape.js +175 -20
  13. package/dist/esm/drawer/shape/Bow.d.ts +31 -0
  14. package/dist/esm/drawer/shape/Bow.js +375 -0
  15. package/dist/esm/drawer/shape/Circle.d.ts +37 -0
  16. package/dist/esm/drawer/shape/Circle.js +461 -0
  17. package/dist/esm/drawer/shape/Curve.d.ts +29 -0
  18. package/dist/esm/drawer/shape/Curve.js +386 -0
  19. package/dist/esm/drawer/shape/DragPoint.d.ts +32 -0
  20. package/dist/esm/drawer/shape/DragPoint.js +211 -0
  21. package/dist/esm/drawer/shape/Elliptic.d.ts +38 -0
  22. package/dist/esm/drawer/shape/Elliptic.js +491 -0
  23. package/dist/esm/drawer/shape/Formation.d.ts +33 -0
  24. package/dist/esm/drawer/shape/Formation.js +395 -0
  25. package/dist/esm/drawer/shape/PincerArrow.d.ts +32 -0
  26. package/dist/esm/drawer/shape/PincerArrow.js +445 -0
  27. package/dist/esm/drawer/shape/Point.d.ts +2 -31
  28. package/dist/esm/drawer/shape/Point.js +7 -201
  29. package/dist/esm/drawer/shape/Polygon.d.ts +1 -1
  30. package/dist/esm/drawer/shape/Polygon.js +10 -81
  31. package/dist/esm/drawer/shape/Polyline.d.ts +1 -1
  32. package/dist/esm/drawer/shape/Polyline.js +10 -81
  33. package/dist/esm/drawer/shape/RegularPolygon.d.ts +37 -0
  34. package/dist/esm/drawer/shape/RegularPolygon.js +468 -0
  35. package/dist/esm/drawer/shape/RightAngleArrow.d.ts +34 -0
  36. package/dist/esm/drawer/shape/RightAngleArrow.js +423 -0
  37. package/dist/esm/drawer/shape/Sector.d.ts +37 -0
  38. package/dist/esm/drawer/shape/Sector.js +568 -0
  39. package/dist/esm/drawer/shape/StraightArrow.d.ts +34 -0
  40. package/dist/esm/drawer/shape/StraightArrow.js +422 -0
  41. package/dist/esm/drawer/shape/SwallowtailArrow.d.ts +36 -0
  42. package/dist/esm/drawer/shape/SwallowtailArrow.js +438 -0
  43. package/dist/esm/drawer/types.d.ts +23 -0
  44. package/dist/esm/drawer/types.js +11 -0
  45. package/dist/esm/drawer/utils.d.ts +14 -0
  46. package/dist/esm/drawer/utils.js +320 -2
  47. package/dist/esm/index.js +2 -2
  48. package/dist/esm/measure/Area.d.ts +17 -17
  49. package/dist/esm/measure/Area.js +95 -63
  50. package/dist/esm/measure/BaseDraw.d.ts +9 -4
  51. package/dist/esm/measure/BaseDraw.js +37 -2
  52. package/dist/esm/measure/Distance.d.ts +9 -9
  53. package/dist/esm/measure/Distance.js +52 -68
  54. package/dist/esm/measure/index.d.ts +16 -26
  55. package/dist/esm/measure/index.js +72 -84
  56. package/dist/esm/measure/types.d.ts +94 -0
  57. package/dist/esm/measure/types.js +17 -0
  58. package/dist/esm/measure/utils.d.ts +7 -7
  59. package/dist/esm/measure/utils.js +43 -24
  60. package/dist/esm/tool/utils.js +1 -1
  61. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  62. package/package.json +1 -1
  63. package/dist/esm/plot/create/CreateAssemble.d.ts +0 -2
  64. package/dist/esm/plot/create/CreateAssemble.js +0 -63
  65. package/dist/esm/plot/create/CreateAttackArrow.d.ts +0 -5
  66. package/dist/esm/plot/create/CreateAttackArrow.js +0 -75
  67. package/dist/esm/plot/create/CreateBillboard.d.ts +0 -2
  68. package/dist/esm/plot/create/CreateBillboard.js +0 -47
  69. package/dist/esm/plot/create/CreateBow.d.ts +0 -2
  70. package/dist/esm/plot/create/CreateBow.js +0 -63
  71. package/dist/esm/plot/create/CreateCircle.d.ts +0 -2
  72. package/dist/esm/plot/create/CreateCircle.js +0 -68
  73. package/dist/esm/plot/create/CreateCurve.d.ts +0 -2
  74. package/dist/esm/plot/create/CreateCurve.js +0 -76
  75. package/dist/esm/plot/create/CreateElliptic.d.ts +0 -2
  76. package/dist/esm/plot/create/CreateElliptic.js +0 -69
  77. package/dist/esm/plot/create/CreateFlag.d.ts +0 -2
  78. package/dist/esm/plot/create/CreateFlag.js +0 -80
  79. package/dist/esm/plot/create/CreateFormation.d.ts +0 -2
  80. package/dist/esm/plot/create/CreateFormation.js +0 -65
  81. package/dist/esm/plot/create/CreateFreeLine.d.ts +0 -2
  82. package/dist/esm/plot/create/CreateFreeLine.js +0 -69
  83. package/dist/esm/plot/create/CreateFreePolygon.d.ts +0 -2
  84. package/dist/esm/plot/create/CreateFreePolygon.js +0 -65
  85. package/dist/esm/plot/create/CreateLabel.d.ts +0 -2
  86. package/dist/esm/plot/create/CreateLabel.js +0 -55
  87. package/dist/esm/plot/create/CreateLineArrow.d.ts +0 -2
  88. package/dist/esm/plot/create/CreateLineArrow.js +0 -79
  89. package/dist/esm/plot/create/CreatePincerArrow.d.ts +0 -5
  90. package/dist/esm/plot/create/CreatePincerArrow.js +0 -73
  91. package/dist/esm/plot/create/CreatePoint.d.ts +0 -2
  92. package/dist/esm/plot/create/CreatePoint.js +0 -47
  93. package/dist/esm/plot/create/CreatePolygon.d.ts +0 -2
  94. package/dist/esm/plot/create/CreatePolygon.js +0 -80
  95. package/dist/esm/plot/create/CreatePolyline.d.ts +0 -2
  96. package/dist/esm/plot/create/CreatePolyline.js +0 -70
  97. package/dist/esm/plot/create/CreateRectangle.d.ts +0 -2
  98. package/dist/esm/plot/create/CreateRectangle.js +0 -60
  99. package/dist/esm/plot/create/CreateRegularPolygon.d.ts +0 -2
  100. package/dist/esm/plot/create/CreateRegularPolygon.js +0 -75
  101. package/dist/esm/plot/create/CreateRightAngleArrow.d.ts +0 -5
  102. package/dist/esm/plot/create/CreateRightAngleArrow.js +0 -73
  103. package/dist/esm/plot/create/CreateRoundRectangle.d.ts +0 -2
  104. package/dist/esm/plot/create/CreateRoundRectangle.js +0 -63
  105. package/dist/esm/plot/create/CreateSector.d.ts +0 -2
  106. package/dist/esm/plot/create/CreateSector.js +0 -65
  107. package/dist/esm/plot/create/CreateStraightArrow.d.ts +0 -5
  108. package/dist/esm/plot/create/CreateStraightArrow.js +0 -65
  109. package/dist/esm/plot/create/CreateSwallowtailArrow.d.ts +0 -5
  110. package/dist/esm/plot/create/CreateSwallowtailArrow.js +0 -67
  111. package/dist/esm/plot/create/index.d.ts +0 -25
  112. package/dist/esm/plot/create/index.js +0 -25
  113. package/dist/esm/plot/edit/EditAssemble.d.ts +0 -8
  114. package/dist/esm/plot/edit/EditAssemble.js +0 -120
  115. package/dist/esm/plot/edit/EditAttackArrow.d.ts +0 -8
  116. package/dist/esm/plot/edit/EditAttackArrow.js +0 -182
  117. package/dist/esm/plot/edit/EditBillboard.d.ts +0 -7
  118. package/dist/esm/plot/edit/EditBillboard.js +0 -70
  119. package/dist/esm/plot/edit/EditBow.d.ts +0 -8
  120. package/dist/esm/plot/edit/EditBow.js +0 -119
  121. package/dist/esm/plot/edit/EditCircle.d.ts +0 -8
  122. package/dist/esm/plot/edit/EditCircle.js +0 -133
  123. package/dist/esm/plot/edit/EditCurve.d.ts +0 -8
  124. package/dist/esm/plot/edit/EditCurve.js +0 -180
  125. package/dist/esm/plot/edit/EditElliptic.d.ts +0 -8
  126. package/dist/esm/plot/edit/EditElliptic.js +0 -144
  127. package/dist/esm/plot/edit/EditFlag.d.ts +0 -8
  128. package/dist/esm/plot/edit/EditFlag.js +0 -121
  129. package/dist/esm/plot/edit/EditFormation.d.ts +0 -8
  130. package/dist/esm/plot/edit/EditFormation.js +0 -120
  131. package/dist/esm/plot/edit/EditLabel.d.ts +0 -7
  132. package/dist/esm/plot/edit/EditLabel.js +0 -100
  133. package/dist/esm/plot/edit/EditLineArrow.d.ts +0 -8
  134. package/dist/esm/plot/edit/EditLineArrow.js +0 -180
  135. package/dist/esm/plot/edit/EditPincerArrow.d.ts +0 -8
  136. package/dist/esm/plot/edit/EditPincerArrow.js +0 -121
  137. package/dist/esm/plot/edit/EditPoint.d.ts +0 -7
  138. package/dist/esm/plot/edit/EditPoint.js +0 -70
  139. package/dist/esm/plot/edit/EditPolygon.d.ts +0 -8
  140. package/dist/esm/plot/edit/EditPolygon.js +0 -181
  141. package/dist/esm/plot/edit/EditPolyline.d.ts +0 -8
  142. package/dist/esm/plot/edit/EditPolyline.js +0 -179
  143. package/dist/esm/plot/edit/EditRectangle.d.ts +0 -8
  144. package/dist/esm/plot/edit/EditRectangle.js +0 -119
  145. package/dist/esm/plot/edit/EditRegularPolygon.d.ts +0 -8
  146. package/dist/esm/plot/edit/EditRegularPolygon.js +0 -170
  147. package/dist/esm/plot/edit/EditRightAngleArrow.d.ts +0 -8
  148. package/dist/esm/plot/edit/EditRightAngleArrow.js +0 -143
  149. package/dist/esm/plot/edit/EditRoundRectangle.d.ts +0 -8
  150. package/dist/esm/plot/edit/EditRoundRectangle.js +0 -119
  151. package/dist/esm/plot/edit/EditSector.d.ts +0 -8
  152. package/dist/esm/plot/edit/EditSector.js +0 -120
  153. package/dist/esm/plot/edit/EditStraightArrow.d.ts +0 -8
  154. package/dist/esm/plot/edit/EditStraightArrow.js +0 -120
  155. package/dist/esm/plot/edit/EditSwallowtailArrow.d.ts +0 -8
  156. package/dist/esm/plot/edit/EditSwallowtailArrow.js +0 -121
  157. package/dist/esm/plot/edit/index.d.ts +0 -23
  158. package/dist/esm/plot/edit/index.js +0 -23
  159. package/dist/esm/plot/utils/DomUtil.d.ts +0 -34
  160. package/dist/esm/plot/utils/DomUtil.js +0 -100
  161. package/dist/esm/plot/utils/PlotCommon.d.ts +0 -101
  162. package/dist/esm/plot/utils/ReminderTip.d.ts +0 -10
  163. package/dist/esm/plot/utils/ReminderTip.js +0 -67
  164. package/dist/esm/plot/utils/Tooltip.d.ts +0 -3
  165. package/dist/esm/plot/utils/Tooltip.js +0 -97
  166. /package/dist/esm/{plot/utils/Algorithm.d.ts → drawer/algorithm.d.ts} +0 -0
  167. /package/dist/esm/{plot/utils/Coordinate.d.ts → drawer/coordinate.d.ts} +0 -0
  168. /package/dist/esm/{plot/utils/Coordinate.js → drawer/coordinate.js} +0 -0
  169. /package/dist/esm/{plot/utils → drawer}/plotUtil.d.ts +0 -0
@@ -1,5 +1,39 @@
1
- // 获取对应类型的数据处理方法
1
+ var _excluded = ["type", "featureTypeField", "featureConfigField", "config"];
2
+ 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); }
3
+ 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; }
4
+ 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; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
+ 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."); }
12
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
13
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
+ 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."); }
16
+ 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); }
17
+ 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; }
18
+ 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; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
20
  import { flattenEach } from '@turf/turf';
21
+ import * as Cesium from 'deeptwins-cesium';
22
+ import * as utils from "../tool/utils";
23
+ var DEFAULT_FEATURE_TYPE_FIELD = 'shapeType';
24
+ var DEFAULT_FEATURE_CONFIG_FIELD = 'shapeConfig';
25
+ var DRAWER_GEOMETRY_SHAPE_MAP = {
26
+ Point: 'point',
27
+ MultiPoint: 'point',
28
+ LineString: 'polyline',
29
+ MultiLineString: 'polyline',
30
+ Polygon: 'polygon',
31
+ MultiPolygon: 'polygon'
32
+ };
33
+ var DRAWER_POLYGON_BASED_SHAPES = new Set(['polygon', 'circle', 'regularPolygon', 'assemble', 'attackArrow', 'elliptic', 'pincerArrow', 'rightAngleArrow', 'sector', 'straightArrow', 'swallowtailArrow']);
34
+ var DRAWER_POLYLINE_BASED_SHAPES = new Set(['polyline', 'bow', 'curve', 'formation']);
35
+
36
+ // 获取对应类型的数据处理方法
3
37
  export var HANDLE_FEATURE_DATA_TYPE_FUN = {
4
38
  Point: handleFeaturePoint,
5
39
  MultiPoint: handleFeatureMultiPoint,
@@ -9,6 +43,290 @@ export var HANDLE_FEATURE_DATA_TYPE_FUN = {
9
43
  MultiPolygon: handleFeatureMultiPolygon
10
44
  };
11
45
 
46
+ // 去掉 GeoJSON Polygon 首尾重复的闭合点,避免编辑时生成重复控制点。
47
+ export function normalizePolygonPositions() {
48
+ var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
49
+ if (!Array.isArray(positions)) {
50
+ return [];
51
+ }
52
+ var normalizedPositions = positions.filter(function (position) {
53
+ return Array.isArray(position) && position.length >= 2;
54
+ }).map(function (position) {
55
+ var _position = _slicedToArray(position, 3),
56
+ lng = _position[0],
57
+ lat = _position[1],
58
+ _position$ = _position[2],
59
+ alt = _position$ === void 0 ? 0 : _position$;
60
+ return [lng, lat, alt];
61
+ });
62
+ if (normalizedPositions.length < 2) {
63
+ return normalizedPositions;
64
+ }
65
+ var first = normalizedPositions[0];
66
+ var last = normalizedPositions[normalizedPositions.length - 1];
67
+ var isClosedRing = first[0] === last[0] && first[1] === last[1] && first[2] === last[2];
68
+ return isClosedRing ? normalizedPositions.slice(0, normalizedPositions.length - 1) : normalizedPositions;
69
+ }
70
+
71
+ // 根据 polygon 顶点估算中心点,供 circle / regularPolygon 恢复双控制点模型。
72
+ export function getPolygonRestoreCenterPosition(positions) {
73
+ var normalizedPositions = normalizePolygonPositions(positions);
74
+ if (!normalizedPositions.length) {
75
+ return null;
76
+ }
77
+ var cartesianPositions = normalizedPositions.map(function (position) {
78
+ var _position2 = _slicedToArray(position, 3),
79
+ lng = _position2[0],
80
+ lat = _position2[1],
81
+ _position2$ = _position2[2],
82
+ alt = _position2$ === void 0 ? 0 : _position2$;
83
+ if (!Number.isFinite(lng) || !Number.isFinite(lat) || !Number.isFinite(alt)) {
84
+ return null;
85
+ }
86
+ return utils.lngLatAltToCartesian3(lng, lat, alt);
87
+ }).filter(function (position) {
88
+ return Boolean(position);
89
+ });
90
+ if (!cartesianPositions.length) {
91
+ return null;
92
+ }
93
+ var boundingSphere = Cesium.BoundingSphere.fromPoints(cartesianPositions);
94
+ var _utils$cartesian3ToLn = utils.cartesian3ToLngLatAlt(boundingSphere.center),
95
+ lng = _utils$cartesian3ToLn.lng,
96
+ lat = _utils$cartesian3ToLn.lat,
97
+ alt = _utils$cartesian3ToLn.alt;
98
+ return [lng, lat, alt];
99
+ }
100
+
101
+ // polygon 型特殊 shape 统一使用首个顶点作为半径/朝向控制点。
102
+ export function getPolygonRestoreHandlePosition(positions) {
103
+ var _normalizePolygonPosi = normalizePolygonPositions(positions),
104
+ _normalizePolygonPosi2 = _slicedToArray(_normalizePolygonPosi, 1),
105
+ firstPosition = _normalizePolygonPosi2[0];
106
+ if (!firstPosition) {
107
+ return null;
108
+ }
109
+ return _toConsumableArray(firstPosition);
110
+ }
111
+
112
+ // 检测恢复项
113
+ function isValidRestorePositionTuple(position) {
114
+ return Array.isArray(position) && position.length >= 3 && Number.isFinite(position[0]) && Number.isFinite(position[1]) && Number.isFinite(position[2]);
115
+ }
116
+
117
+ // 转换恢复项
118
+ function toCartesianRestorePositions(positions) {
119
+ var cartesianPositions = positions.map(function (position) {
120
+ var _position3 = _slicedToArray(position, 3),
121
+ lng = _position3[0],
122
+ lat = _position3[1],
123
+ _position3$ = _position3[2],
124
+ alt = _position3$ === void 0 ? 0 : _position3$;
125
+ if (!Number.isFinite(lng) || !Number.isFinite(lat) || !Number.isFinite(alt)) {
126
+ return null;
127
+ }
128
+ return utils.lngLatAltToCartesian3(lng, lat, alt);
129
+ }).filter(function (position) {
130
+ return Boolean(position);
131
+ });
132
+ return cartesianPositions.length === positions.length ? cartesianPositions : [];
133
+ }
134
+
135
+ // 获取中位值
136
+ function getMedianValue(values) {
137
+ var sortedValues = _toConsumableArray(values).sort(function (prev, next) {
138
+ return prev - next;
139
+ });
140
+ var middleIndex = Math.floor(sortedValues.length / 2);
141
+ if (sortedValues.length % 2 === 1) {
142
+ return sortedValues[middleIndex];
143
+ }
144
+ return (sortedValues[middleIndex - 1] + sortedValues[middleIndex]) / 2;
145
+ }
146
+
147
+ // 扇形的圆心到所有圆弧点距离基本一致,据此识别圆心顶点。
148
+ function getSectorRestoreCenterIndex(cartesianPositions) {
149
+ var bestIndex = -1;
150
+ var bestConsistency = -1;
151
+ var bestSpread = Number.POSITIVE_INFINITY;
152
+ var _loop = function _loop(index) {
153
+ var distances = cartesianPositions.map(function (position, currentIndex) {
154
+ if (currentIndex === index) {
155
+ return null;
156
+ }
157
+ var distance = Cesium.Cartesian3.distance(cartesianPositions[index], position);
158
+ return Number.isFinite(distance) && distance > 0 ? distance : null;
159
+ }).filter(function (distance) {
160
+ return Number.isFinite(distance);
161
+ });
162
+ if (distances.length < 2) {
163
+ return 0; // continue
164
+ }
165
+ var medianDistance = getMedianValue(distances);
166
+ if (!Number.isFinite(medianDistance) || medianDistance <= 0) {
167
+ return 0; // continue
168
+ }
169
+ var tolerance = Math.max(medianDistance * 0.02, 0.5);
170
+ var consistentDistances = distances.filter(function (distance) {
171
+ return Math.abs(distance - medianDistance) <= tolerance;
172
+ });
173
+ if (consistentDistances.length < 2) {
174
+ return 0; // continue
175
+ }
176
+ var consistency = consistentDistances.length / distances.length;
177
+ var spread = consistentDistances.length > 1 ? (Math.max.apply(Math, _toConsumableArray(consistentDistances)) - Math.min.apply(Math, _toConsumableArray(consistentDistances))) / medianDistance : 0;
178
+ if (consistency > bestConsistency || consistency === bestConsistency && spread < bestSpread) {
179
+ bestIndex = index;
180
+ bestConsistency = consistency;
181
+ bestSpread = spread;
182
+ }
183
+ },
184
+ _ret;
185
+ for (var index = 0; index < cartesianPositions.length; index += 1) {
186
+ _ret = _loop(index);
187
+ if (_ret === 0) continue;
188
+ }
189
+ return bestConsistency >= 0.8 ? bestIndex : -1;
190
+ }
191
+
192
+ // 扇形恢复时先识别圆心,再取圆心前后两个相邻顶点作为两个转角。
193
+ export function getSectorRestoreAnchors(positions) {
194
+ var normalizedPositions = normalizePolygonPositions(positions);
195
+ if (normalizedPositions.length < 3) {
196
+ return null;
197
+ }
198
+ var cartesianPositions = toCartesianRestorePositions(normalizedPositions);
199
+ if (cartesianPositions.length !== normalizedPositions.length) {
200
+ return null;
201
+ }
202
+ var centerIndex = getSectorRestoreCenterIndex(cartesianPositions);
203
+ if (centerIndex < 0) {
204
+ return null;
205
+ }
206
+ var previousIndex = (centerIndex - 1 + normalizedPositions.length) % normalizedPositions.length;
207
+ var nextIndex = (centerIndex + 1) % normalizedPositions.length;
208
+ var centerPosition = normalizedPositions[centerIndex];
209
+ var radiusPosition = normalizedPositions[nextIndex];
210
+ var anglePosition = normalizedPositions[previousIndex];
211
+ if (!isValidRestorePositionTuple(centerPosition) || !isValidRestorePositionTuple(radiusPosition) || !isValidRestorePositionTuple(anglePosition)) {
212
+ return null;
213
+ }
214
+ var radiusDistance = Cesium.Cartesian3.distance(cartesianPositions[centerIndex], cartesianPositions[nextIndex]);
215
+ var angleDistance = Cesium.Cartesian3.distance(cartesianPositions[centerIndex], cartesianPositions[previousIndex]);
216
+ var meanDistance = (radiusDistance + angleDistance) / 2;
217
+ if (!Number.isFinite(radiusDistance) || !Number.isFinite(angleDistance) || meanDistance <= 0 || Math.abs(radiusDistance - angleDistance) > Math.max(meanDistance * 0.05, 1)) {
218
+ return null;
219
+ }
220
+ return [_toConsumableArray(centerPosition), _toConsumableArray(radiusPosition), _toConsumableArray(anglePosition)];
221
+ }
222
+
223
+ // 规范化数据转换绘制选项
224
+ export function normalizeDataTransformDrawOptions() {
225
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
226
+ var type = options.type,
227
+ featureTypeField = options.featureTypeField,
228
+ featureConfigField = options.featureConfigField,
229
+ config = options.config,
230
+ shapeOptions = _objectWithoutProperties(options, _excluded);
231
+ return {
232
+ type: type,
233
+ shapeOptions: _objectSpread(_objectSpread({}, config && _typeof(config) === 'object' ? config : {}), shapeOptions),
234
+ featureTypeField: featureTypeField || DEFAULT_FEATURE_TYPE_FIELD,
235
+ featureConfigField: featureConfigField || DEFAULT_FEATURE_CONFIG_FIELD
236
+ };
237
+ }
238
+
239
+ // 获取默认绘制形状类型
240
+ export function getDefaultDrawerShapeType(geometryType) {
241
+ return DRAWER_GEOMETRY_SHAPE_MAP[geometryType];
242
+ }
243
+
244
+ // 绘制形状类型是否与几何类型兼容
245
+ export function isShapeTypeCompatible(shapeType, geometryType) {
246
+ if (!shapeType || !geometryType) {
247
+ return false;
248
+ }
249
+ var defaultShapeType = getDefaultDrawerShapeType(geometryType);
250
+ if (!defaultShapeType) {
251
+ return false;
252
+ }
253
+ if (DRAWER_POLYGON_BASED_SHAPES.has(shapeType)) {
254
+ return geometryType === 'Polygon' || geometryType === 'MultiPolygon';
255
+ }
256
+ if (DRAWER_POLYLINE_BASED_SHAPES.has(shapeType)) {
257
+ return geometryType === 'LineString' || geometryType === 'MultiLineString';
258
+ }
259
+ return shapeType === defaultShapeType;
260
+ }
261
+
262
+ // 获取绘制形状类型
263
+ function getDrawerFeatureShapeType(feature, geometryType, options) {
264
+ var _feature$properties;
265
+ var featureShapeType = feature === null || feature === void 0 || (_feature$properties = feature.properties) === null || _feature$properties === void 0 ? void 0 : _feature$properties[options.featureTypeField];
266
+ var shapeType = typeof options.type === 'string' ? options.type : featureShapeType;
267
+ if (typeof shapeType === 'string' && isShapeTypeCompatible(shapeType, geometryType)) {
268
+ return shapeType;
269
+ }
270
+ return getDefaultDrawerShapeType(geometryType);
271
+ }
272
+
273
+ // 获取绘制配置
274
+ function getDrawerFeatureConfig(feature, options) {
275
+ var _feature$properties2;
276
+ var featureConfig = feature === null || feature === void 0 || (_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2[options.featureConfigField];
277
+ if (!featureConfig || _typeof(featureConfig) !== 'object') {
278
+ return _objectSpread({}, options.shapeOptions);
279
+ }
280
+ return _objectSpread(_objectSpread({}, featureConfig), options.shapeOptions);
281
+ }
282
+
283
+ // 解析特征
284
+ function explodeFeature(feature) {
285
+ var _feature$geometry;
286
+ var geometryType = feature === null || feature === void 0 || (_feature$geometry = feature.geometry) === null || _feature$geometry === void 0 ? void 0 : _feature$geometry.type;
287
+ if (!geometryType) {
288
+ return [];
289
+ }
290
+ if (!geometryType.startsWith('Multi')) {
291
+ return [feature];
292
+ }
293
+ var features = [];
294
+ flattenEach(feature, function (currentFeature) {
295
+ features.push(_objectSpread(_objectSpread({}, currentFeature), {}, {
296
+ properties: _objectSpread(_objectSpread({}, (feature === null || feature === void 0 ? void 0 : feature.properties) || {}), (currentFeature === null || currentFeature === void 0 ? void 0 : currentFeature.properties) || {})
297
+ }));
298
+ });
299
+ return features;
300
+ }
301
+
302
+ // 获取恢复项
303
+ export function getDrawerRestoreItems(feature) {
304
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
305
+ var normalizedOptions = normalizeDataTransformDrawOptions(options);
306
+ return explodeFeature(feature).reduce(function (items, currentFeature) {
307
+ var _currentFeature$geome;
308
+ var geometryType = currentFeature === null || currentFeature === void 0 || (_currentFeature$geome = currentFeature.geometry) === null || _currentFeature$geome === void 0 ? void 0 : _currentFeature$geome.type;
309
+ if (!geometryType) {
310
+ return items;
311
+ }
312
+ var handle = HANDLE_FEATURE_DATA_TYPE_FUN[geometryType];
313
+ if (!handle) {
314
+ return items;
315
+ }
316
+ var handleFeature = handle(currentFeature);
317
+ if (!(handleFeature !== null && handleFeature !== void 0 && handleFeature.positions)) {
318
+ return items;
319
+ }
320
+ items.push({
321
+ shapeType: getDrawerFeatureShapeType(currentFeature, geometryType, normalizedOptions),
322
+ positions: handleFeature.positions,
323
+ config: getDrawerFeatureConfig(currentFeature, normalizedOptions),
324
+ geometryType: geometryType
325
+ });
326
+ return items;
327
+ }, []);
328
+ }
329
+
12
330
  // 处理点
13
331
  function handleFeaturePoint(feature) {
14
332
  return {
@@ -45,7 +363,7 @@ function handleFeatureMultiLineString(feature) {
45
363
  function handleFeaturePolygon(feature) {
46
364
  return {
47
365
  type: 'single',
48
- positions: feature.geometry.coordinates[0]
366
+ positions: normalizePolygonPositions(feature.geometry.coordinates[0])
49
367
  };
50
368
  }
51
369
 
package/dist/esm/index.js CHANGED
@@ -64,11 +64,11 @@ DEEP_TWINS_BASE_URL && (window.CESIUM_BASE_URL = DEEP_TWINS_BASE_URL);
64
64
  // 全局加载css
65
65
  loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
66
66
  // 打印版本信息
67
- console.log('DeepTwinsEngine3D Version:', "0.1.64");
67
+ console.log('DeepTwinsEngine3D Version:', "0.1.65");
68
68
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
69
69
  _classCallCheck(this, DeepTwinsEngine3D);
70
70
  });
71
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.64");
71
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.65");
72
72
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
73
73
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
74
74
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -1,29 +1,29 @@
1
1
  import BaseDraw from './BaseDraw';
2
- import { MeasureContext } from './index';
3
- declare class Area extends BaseDraw {
4
- private readonly _type;
2
+ import { AreaMeasureResult, MeasureContext, MeasureDrawConfig, MeasureLayer, MeasurePosition, MeasureShapeLayer } from './types';
3
+ declare class Area extends BaseDraw implements MeasureLayer {
5
4
  private _config;
6
- private _instance;
5
+ private readonly _shapeType;
6
+ _instance: MeasureShapeLayer | null;
7
7
  private _area;
8
8
  private _areaLayer;
9
- constructor(measureContext: MeasureContext, config: any);
9
+ constructor(measureContext: MeasureContext, config?: MeasureDrawConfig);
10
10
  private _init;
11
- drawing(positions: any): {
12
- area: any;
13
- } | undefined;
14
- pointsChange(layer: any, positions: any): {
15
- area: any;
16
- } | undefined;
17
- drawEnd(positions: any): {
18
- area: any;
19
- } | undefined;
11
+ private _resolveShapeType;
12
+ private _getDrawerConfig;
13
+ drawing(positions: MeasurePosition[]): AreaMeasureResult | undefined;
14
+ pointsChange(_layer: MeasureShapeLayer, positions: MeasurePosition[]): AreaMeasureResult;
15
+ drawEnd(positions?: MeasurePosition[]): {
16
+ area: number;
17
+ };
20
18
  startEdit(): void;
21
- endEdit(positions: any): {
22
- area: any;
23
- } | undefined;
19
+ endEdit(positions?: MeasurePosition[]): {
20
+ area: number;
21
+ };
24
22
  private _calculateArea;
25
23
  private _createAreaLabel;
26
24
  private _destroyAreaLabel;
25
+ private _updateArea;
26
+ private _toPolygonPositions;
27
27
  destroy(): void;
28
28
  }
29
29
  export default Area;
@@ -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;