deeptwins-engine-3d 0.1.64 → 0.1.66

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 (196) hide show
  1. package/dist/esm/constant.d.ts +1 -0
  2. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +1 -0
  3. package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.d.ts +1 -0
  4. package/dist/esm/{plot/utils/Algorithm.js → drawer/algorithm.js} +1 -3
  5. package/dist/esm/drawer/common.d.ts +62 -0
  6. package/dist/esm/{plot/utils/PlotCommon.js → drawer/common.js} +104 -551
  7. package/dist/esm/{plot/utils/Coordinate.d.ts → drawer/coordinate.d.ts} +1 -0
  8. package/dist/esm/drawer/index.d.ts +11 -18
  9. package/dist/esm/drawer/index.js +329 -80
  10. package/dist/esm/{plot/utils → drawer}/plotUtil.js +1 -3
  11. package/dist/esm/drawer/shape/Assemble.d.ts +34 -0
  12. package/dist/esm/drawer/shape/Assemble.js +415 -0
  13. package/dist/esm/drawer/shape/AttackArrow.d.ts +32 -0
  14. package/dist/esm/drawer/shape/AttackArrow.js +442 -0
  15. package/dist/esm/drawer/shape/BaseShape.d.ts +15 -4
  16. package/dist/esm/drawer/shape/BaseShape.js +175 -20
  17. package/dist/esm/drawer/shape/Bow.d.ts +31 -0
  18. package/dist/esm/drawer/shape/Bow.js +375 -0
  19. package/dist/esm/drawer/shape/Circle.d.ts +37 -0
  20. package/dist/esm/drawer/shape/Circle.js +461 -0
  21. package/dist/esm/drawer/shape/Curve.d.ts +29 -0
  22. package/dist/esm/drawer/shape/Curve.js +386 -0
  23. package/dist/esm/drawer/shape/DragPoint.d.ts +32 -0
  24. package/dist/esm/drawer/shape/DragPoint.js +211 -0
  25. package/dist/esm/drawer/shape/Elliptic.d.ts +38 -0
  26. package/dist/esm/drawer/shape/Elliptic.js +491 -0
  27. package/dist/esm/drawer/shape/Formation.d.ts +33 -0
  28. package/dist/esm/drawer/shape/Formation.js +395 -0
  29. package/dist/esm/drawer/shape/PincerArrow.d.ts +32 -0
  30. package/dist/esm/drawer/shape/PincerArrow.js +445 -0
  31. package/dist/esm/drawer/shape/Point.d.ts +2 -31
  32. package/dist/esm/drawer/shape/Point.js +7 -201
  33. package/dist/esm/drawer/shape/Polygon.d.ts +1 -1
  34. package/dist/esm/drawer/shape/Polygon.js +10 -81
  35. package/dist/esm/drawer/shape/Polyline.d.ts +1 -1
  36. package/dist/esm/drawer/shape/Polyline.js +10 -81
  37. package/dist/esm/drawer/shape/RegularPolygon.d.ts +37 -0
  38. package/dist/esm/drawer/shape/RegularPolygon.js +468 -0
  39. package/dist/esm/drawer/shape/RightAngleArrow.d.ts +34 -0
  40. package/dist/esm/drawer/shape/RightAngleArrow.js +423 -0
  41. package/dist/esm/drawer/shape/Sector.d.ts +37 -0
  42. package/dist/esm/drawer/shape/Sector.js +568 -0
  43. package/dist/esm/drawer/shape/StraightArrow.d.ts +34 -0
  44. package/dist/esm/drawer/shape/StraightArrow.js +422 -0
  45. package/dist/esm/drawer/shape/SwallowtailArrow.d.ts +36 -0
  46. package/dist/esm/drawer/shape/SwallowtailArrow.js +438 -0
  47. package/dist/esm/drawer/types.d.ts +23 -0
  48. package/dist/esm/drawer/types.js +11 -0
  49. package/dist/esm/drawer/utils.d.ts +14 -0
  50. package/dist/esm/drawer/utils.js +320 -2
  51. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  52. package/dist/esm/index.d.ts +2 -0
  53. package/dist/esm/index.js +6 -2
  54. package/dist/esm/map/Map.d.ts +9 -0
  55. package/dist/esm/map/Map.js +115 -2
  56. package/dist/esm/material/AtmosphericDispersion.d.ts +71 -0
  57. package/dist/esm/material/AtmosphericDispersion.js +485 -33
  58. package/dist/esm/material/GlobalVolumetricCloud.d.ts +117 -0
  59. package/dist/esm/material/GlobalVolumetricCloud.js +219 -223
  60. package/dist/esm/material/entity/ImageMaterialProperty.d.ts +1 -0
  61. package/dist/esm/material/shader/AtmosphericShader.glsl +244 -0
  62. package/dist/esm/measure/Area.d.ts +17 -17
  63. package/dist/esm/measure/Area.js +95 -63
  64. package/dist/esm/measure/BaseDraw.d.ts +10 -4
  65. package/dist/esm/measure/BaseDraw.js +37 -2
  66. package/dist/esm/measure/Distance.d.ts +9 -9
  67. package/dist/esm/measure/Distance.js +52 -68
  68. package/dist/esm/measure/index.d.ts +16 -26
  69. package/dist/esm/measure/index.js +72 -84
  70. package/dist/esm/measure/types.d.ts +95 -0
  71. package/dist/esm/measure/types.js +17 -0
  72. package/dist/esm/measure/utils.d.ts +8 -7
  73. package/dist/esm/measure/utils.js +43 -24
  74. package/dist/esm/sceneFusion/Airway.d.ts +0 -0
  75. package/dist/esm/sceneFusion/Airway.js +692 -0
  76. package/dist/esm/tileLayer/ArcGisLayer.d.ts +1 -0
  77. package/dist/esm/tileLayer/ImageryLayer.d.ts +1 -0
  78. package/dist/esm/tileLayer/MvtVectorLoad.d.ts +1 -0
  79. package/dist/esm/tool/common.d.ts +1 -0
  80. package/dist/esm/tool/utils.d.ts +1 -0
  81. package/dist/esm/tool/utils.js +1 -1
  82. package/dist/esm/typings.d.ts +8 -0
  83. package/dist/esm/visualization/BaseHeatmap.d.ts +5 -0
  84. package/dist/esm/visualization/BaseHeatmap.js +54 -12
  85. package/dist/esm/visualization/Heatmap2d.d.ts +1 -0
  86. package/dist/esm/visualization/Heatmap2d.js +17 -26
  87. package/dist/esm/visualization/Heatmap3d.d.ts +8 -2
  88. package/dist/esm/visualization/Heatmap3d.js +195 -59
  89. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  90. package/package.json +1 -1
  91. package/dist/esm/plot/create/CreateAssemble.d.ts +0 -2
  92. package/dist/esm/plot/create/CreateAssemble.js +0 -63
  93. package/dist/esm/plot/create/CreateAttackArrow.d.ts +0 -5
  94. package/dist/esm/plot/create/CreateAttackArrow.js +0 -75
  95. package/dist/esm/plot/create/CreateBillboard.d.ts +0 -2
  96. package/dist/esm/plot/create/CreateBillboard.js +0 -47
  97. package/dist/esm/plot/create/CreateBow.d.ts +0 -2
  98. package/dist/esm/plot/create/CreateBow.js +0 -63
  99. package/dist/esm/plot/create/CreateCircle.d.ts +0 -2
  100. package/dist/esm/plot/create/CreateCircle.js +0 -68
  101. package/dist/esm/plot/create/CreateCurve.d.ts +0 -2
  102. package/dist/esm/plot/create/CreateCurve.js +0 -76
  103. package/dist/esm/plot/create/CreateElliptic.d.ts +0 -2
  104. package/dist/esm/plot/create/CreateElliptic.js +0 -69
  105. package/dist/esm/plot/create/CreateFlag.d.ts +0 -2
  106. package/dist/esm/plot/create/CreateFlag.js +0 -80
  107. package/dist/esm/plot/create/CreateFormation.d.ts +0 -2
  108. package/dist/esm/plot/create/CreateFormation.js +0 -65
  109. package/dist/esm/plot/create/CreateFreeLine.d.ts +0 -2
  110. package/dist/esm/plot/create/CreateFreeLine.js +0 -69
  111. package/dist/esm/plot/create/CreateFreePolygon.d.ts +0 -2
  112. package/dist/esm/plot/create/CreateFreePolygon.js +0 -65
  113. package/dist/esm/plot/create/CreateLabel.d.ts +0 -2
  114. package/dist/esm/plot/create/CreateLabel.js +0 -55
  115. package/dist/esm/plot/create/CreateLineArrow.d.ts +0 -2
  116. package/dist/esm/plot/create/CreateLineArrow.js +0 -79
  117. package/dist/esm/plot/create/CreatePincerArrow.d.ts +0 -5
  118. package/dist/esm/plot/create/CreatePincerArrow.js +0 -73
  119. package/dist/esm/plot/create/CreatePoint.d.ts +0 -2
  120. package/dist/esm/plot/create/CreatePoint.js +0 -47
  121. package/dist/esm/plot/create/CreatePolygon.d.ts +0 -2
  122. package/dist/esm/plot/create/CreatePolygon.js +0 -80
  123. package/dist/esm/plot/create/CreatePolyline.d.ts +0 -2
  124. package/dist/esm/plot/create/CreatePolyline.js +0 -70
  125. package/dist/esm/plot/create/CreateRectangle.d.ts +0 -2
  126. package/dist/esm/plot/create/CreateRectangle.js +0 -60
  127. package/dist/esm/plot/create/CreateRegularPolygon.d.ts +0 -2
  128. package/dist/esm/plot/create/CreateRegularPolygon.js +0 -75
  129. package/dist/esm/plot/create/CreateRightAngleArrow.d.ts +0 -5
  130. package/dist/esm/plot/create/CreateRightAngleArrow.js +0 -73
  131. package/dist/esm/plot/create/CreateRoundRectangle.d.ts +0 -2
  132. package/dist/esm/plot/create/CreateRoundRectangle.js +0 -63
  133. package/dist/esm/plot/create/CreateSector.d.ts +0 -2
  134. package/dist/esm/plot/create/CreateSector.js +0 -65
  135. package/dist/esm/plot/create/CreateStraightArrow.d.ts +0 -5
  136. package/dist/esm/plot/create/CreateStraightArrow.js +0 -65
  137. package/dist/esm/plot/create/CreateSwallowtailArrow.d.ts +0 -5
  138. package/dist/esm/plot/create/CreateSwallowtailArrow.js +0 -67
  139. package/dist/esm/plot/create/index.d.ts +0 -25
  140. package/dist/esm/plot/create/index.js +0 -25
  141. package/dist/esm/plot/edit/EditAssemble.d.ts +0 -8
  142. package/dist/esm/plot/edit/EditAssemble.js +0 -120
  143. package/dist/esm/plot/edit/EditAttackArrow.d.ts +0 -8
  144. package/dist/esm/plot/edit/EditAttackArrow.js +0 -182
  145. package/dist/esm/plot/edit/EditBillboard.d.ts +0 -7
  146. package/dist/esm/plot/edit/EditBillboard.js +0 -70
  147. package/dist/esm/plot/edit/EditBow.d.ts +0 -8
  148. package/dist/esm/plot/edit/EditBow.js +0 -119
  149. package/dist/esm/plot/edit/EditCircle.d.ts +0 -8
  150. package/dist/esm/plot/edit/EditCircle.js +0 -133
  151. package/dist/esm/plot/edit/EditCurve.d.ts +0 -8
  152. package/dist/esm/plot/edit/EditCurve.js +0 -180
  153. package/dist/esm/plot/edit/EditElliptic.d.ts +0 -8
  154. package/dist/esm/plot/edit/EditElliptic.js +0 -144
  155. package/dist/esm/plot/edit/EditFlag.d.ts +0 -8
  156. package/dist/esm/plot/edit/EditFlag.js +0 -121
  157. package/dist/esm/plot/edit/EditFormation.d.ts +0 -8
  158. package/dist/esm/plot/edit/EditFormation.js +0 -120
  159. package/dist/esm/plot/edit/EditLabel.d.ts +0 -7
  160. package/dist/esm/plot/edit/EditLabel.js +0 -100
  161. package/dist/esm/plot/edit/EditLineArrow.d.ts +0 -8
  162. package/dist/esm/plot/edit/EditLineArrow.js +0 -180
  163. package/dist/esm/plot/edit/EditPincerArrow.d.ts +0 -8
  164. package/dist/esm/plot/edit/EditPincerArrow.js +0 -121
  165. package/dist/esm/plot/edit/EditPoint.d.ts +0 -7
  166. package/dist/esm/plot/edit/EditPoint.js +0 -70
  167. package/dist/esm/plot/edit/EditPolygon.d.ts +0 -8
  168. package/dist/esm/plot/edit/EditPolygon.js +0 -181
  169. package/dist/esm/plot/edit/EditPolyline.d.ts +0 -8
  170. package/dist/esm/plot/edit/EditPolyline.js +0 -179
  171. package/dist/esm/plot/edit/EditRectangle.d.ts +0 -8
  172. package/dist/esm/plot/edit/EditRectangle.js +0 -119
  173. package/dist/esm/plot/edit/EditRegularPolygon.d.ts +0 -8
  174. package/dist/esm/plot/edit/EditRegularPolygon.js +0 -170
  175. package/dist/esm/plot/edit/EditRightAngleArrow.d.ts +0 -8
  176. package/dist/esm/plot/edit/EditRightAngleArrow.js +0 -143
  177. package/dist/esm/plot/edit/EditRoundRectangle.d.ts +0 -8
  178. package/dist/esm/plot/edit/EditRoundRectangle.js +0 -119
  179. package/dist/esm/plot/edit/EditSector.d.ts +0 -8
  180. package/dist/esm/plot/edit/EditSector.js +0 -120
  181. package/dist/esm/plot/edit/EditStraightArrow.d.ts +0 -8
  182. package/dist/esm/plot/edit/EditStraightArrow.js +0 -120
  183. package/dist/esm/plot/edit/EditSwallowtailArrow.d.ts +0 -8
  184. package/dist/esm/plot/edit/EditSwallowtailArrow.js +0 -121
  185. package/dist/esm/plot/edit/index.d.ts +0 -23
  186. package/dist/esm/plot/edit/index.js +0 -23
  187. package/dist/esm/plot/utils/DomUtil.d.ts +0 -34
  188. package/dist/esm/plot/utils/DomUtil.js +0 -100
  189. package/dist/esm/plot/utils/PlotCommon.d.ts +0 -101
  190. package/dist/esm/plot/utils/ReminderTip.d.ts +0 -10
  191. package/dist/esm/plot/utils/ReminderTip.js +0 -67
  192. package/dist/esm/plot/utils/Tooltip.d.ts +0 -3
  193. package/dist/esm/plot/utils/Tooltip.js +0 -97
  194. /package/dist/esm/{plot/utils/Algorithm.d.ts → drawer/algorithm.d.ts} +0 -0
  195. /package/dist/esm/{plot/utils/Coordinate.js → drawer/coordinate.js} +0 -0
  196. /package/dist/esm/{plot/utils → drawer}/plotUtil.d.ts +0 -0
@@ -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;
@@ -1,44 +1,34 @@
1
1
  import Drawer from '../drawer';
2
- export interface MeasureContext {
3
- options: any;
4
- getMap: any;
5
- drawer: any;
6
- setDrawerLayer: any;
7
- _changeStatus: any;
8
- }
9
- export declare const STATUS: {
10
- readonly INIT: "INIT";
11
- readonly START_DRAW: "START_DRAW";
12
- readonly DRAWING: "DRAWING";
13
- readonly END_DRAW: "END_DRAW";
14
- readonly EDITING: "EDITING";
15
- readonly END_EDIT: "END_EDIT";
16
- };
17
- export type Status = (typeof STATUS)[keyof typeof STATUS];
2
+ import { MapContext } from '../map/Map';
3
+ import { MeasureContext, MeasureDrawConfig, MeasureLayer, MeasureMap, MeasureOptions, MeasureType, Status } from './types';
18
4
  declare class Measure implements MeasureContext {
19
5
  private readonly _mapContext;
20
6
  private readonly _measureContext;
21
- options: any;
7
+ options: MeasureOptions;
22
8
  isDestroyed: boolean;
23
9
  private _status;
24
10
  drawer: Drawer;
25
11
  private _instance;
26
12
  private _measureDrawLayers;
27
- constructor(map: any, options?: any);
13
+ constructor(map: {
14
+ _mapContext: MapContext;
15
+ }, options?: MeasureDrawConfig);
28
16
  private _canOperate;
29
- getMap(): any;
30
- _changeStatus(status: any): void;
31
- startDraw(type: any, config?: any): any;
17
+ getMap(): MeasureMap;
18
+ _changeStatus(status: Status): void;
19
+ startDraw(type: MeasureType, config?: MeasureDrawConfig): MeasureLayer | undefined;
32
20
  private _stopDraw;
33
21
  endDraw(): void;
34
- startEdit(id: any): void;
22
+ startEdit(id: string | MeasureLayer): void;
35
23
  endEdit(): void;
36
- getDrawerLayer(id: any): any;
37
- setDrawerLayer(id: any, value: any): void;
38
- removeDrawerLayer(id: any): void;
39
- getAllDrawerLayers(): unknown[] | undefined;
24
+ getDrawerLayer(id: string | MeasureLayer): MeasureLayer | undefined;
25
+ setDrawerLayer(id: string, value: MeasureLayer): void;
26
+ removeDrawerLayer(id: string | MeasureLayer): void;
27
+ getAllDrawerLayers(): MeasureLayer[] | undefined;
40
28
  clearAllDrawerLayers(): void;
41
29
  clear(): void;
42
30
  destroy(): void;
31
+ private _emitCallback;
43
32
  }
33
+ export { AREA_SHAPE_TYPE, MEASURE_TYPE, STATUS, type AreaMeasureResult, type AreaShapeType, type DistanceMeasureCacheItem, type DistanceMeasureResult, type DistancePreviewResult, type MeasureCallbackPayload, type MeasureContext, type MeasureDrawConfig, type MeasureLayer, type MeasureOptions, type MeasurePosition, type MeasureResult, type Status, } from './types';
44
34
  export default Measure;
@@ -5,28 +5,14 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
5
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
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
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
- import { isString, merge } from 'lodash';
8
+ import { merge } from 'lodash';
9
9
  import { DEFAULT_MEASURE_STYLE } from "../constant";
10
10
  import Drawer from "../drawer";
11
11
  import { error } from "../tool/utils";
12
12
  import Area from "./Area";
13
13
  import Distance from "./Distance";
14
- var MEASURE_TYPE = {
15
- DISTANCE: 'distance',
16
- AREA: 'area'
17
- };
18
-
19
- // 状态表定义
20
- export var STATUS = {
21
- INIT: 'INIT',
22
- START_DRAW: 'START_DRAW',
23
- DRAWING: 'DRAWING',
24
- END_DRAW: 'END_DRAW',
25
- EDITING: 'EDITING',
26
- END_EDIT: 'END_EDIT'
27
- };
28
-
29
- // 从状态表推导类型
14
+ import { MEASURE_TYPE, STATUS } from "./types";
15
+ var MEASURE_CLASS_MAP = _defineProperty(_defineProperty({}, MEASURE_TYPE.DISTANCE, Distance), MEASURE_TYPE.AREA, Area);
30
16
  var Measure = /*#__PURE__*/function () {
31
17
  function Measure(map) {
32
18
  var _this = this;
@@ -39,7 +25,7 @@ var Measure = /*#__PURE__*/function () {
39
25
  _defineProperty(this, "_status", STATUS.INIT);
40
26
  _defineProperty(this, "drawer", void 0);
41
27
  // 绘制的实例
42
- _defineProperty(this, "_instance", void 0);
28
+ _defineProperty(this, "_instance", null);
43
29
  // 绘制完成的图层
44
30
  _defineProperty(this, "_measureDrawLayers", new Map());
45
31
  this._mapContext = map._mapContext;
@@ -52,33 +38,16 @@ var Measure = /*#__PURE__*/function () {
52
38
  },
53
39
  onPointsChange: function onPointsChange(e) {
54
40
  if (_this._instance) {
55
- var data = _this._instance.pointsChange(e.layer, e.positions);
56
- _this.options.onPointsChange && _this.options.onPointsChange({
57
- layer: _this._instance,
58
- positions: e.positions,
59
- measure: data
60
- });
41
+ var positions = e.positions;
42
+ var data = _this._instance.pointsChange(e.layer, positions);
43
+ _this._emitCallback('onPointsChange', positions, data);
61
44
  }
62
45
  },
63
46
  onComplete: function onComplete(e) {
64
47
  if (_this._instance) {
65
- var data = {};
66
- if (_this._status === 'END_DRAW' || _this._status === 'DRAWING') {
67
- data = _this._instance.drawEnd(e.positions);
68
- _this.options.onComplete && _this.options.onComplete({
69
- layer: _this._instance,
70
- positions: e.positions,
71
- measure: data
72
- });
73
- }
74
- if (_this._status === 'END_EDIT') {
75
- data = _this._instance.endEdit(e.positions);
76
- _this.options.onComplete && _this.options.onComplete({
77
- layer: _this._instance,
78
- positions: e.positions,
79
- measure: data
80
- });
81
- }
48
+ var positions = e.positions;
49
+ var data = _this._status === STATUS.END_EDIT ? _this._instance.endEdit(positions) : _this._instance.drawEnd(positions);
50
+ _this._emitCallback('onComplete', positions, data);
82
51
  }
83
52
  }
84
53
  });
@@ -104,7 +73,7 @@ var Measure = /*#__PURE__*/function () {
104
73
  }, {
105
74
  key: "getMap",
106
75
  value: function getMap() {
107
- return this._mapContext && this._mapContext.getMap();
76
+ return this._mapContext.getMap();
108
77
  }
109
78
 
110
79
  // 修改状态
@@ -120,17 +89,13 @@ var Measure = /*#__PURE__*/function () {
120
89
  value: function startDraw(type) {
121
90
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
122
91
  if (!this._canOperate()) return;
123
- if (!Object.values(MEASURE_TYPE).includes(type)) return;
92
+ var MeasureClass = MEASURE_CLASS_MAP[type];
93
+ if (!MeasureClass) return;
124
94
  if (this._instance) {
125
95
  this._stopDraw();
126
96
  }
127
97
  this._changeStatus(STATUS.START_DRAW);
128
- if (type === MEASURE_TYPE.DISTANCE) {
129
- this._instance = new Distance(this._measureContext, config);
130
- }
131
- if (type === MEASURE_TYPE.AREA) {
132
- this._instance = new Area(this._measureContext, config);
133
- }
98
+ this._instance = new MeasureClass(this._measureContext, config);
134
99
  return this._instance;
135
100
  }
136
101
 
@@ -140,24 +105,13 @@ var Measure = /*#__PURE__*/function () {
140
105
  value: function _stopDraw() {
141
106
  if (!this._canOperate()) return;
142
107
  if (!this._instance) return;
143
- if (this._status === STATUS.INIT || this._status === STATUS.START_DRAW || this._status === STATUS.END_EDIT) {
144
- var layer = this.getDrawerLayer(this._instance);
145
- // layer未存入
146
- if (!layer) {
147
- this._instance.destroy();
148
- }
149
- this._instance = null;
150
- return;
151
- }
152
- if (this._status === STATUS.DRAWING) {
153
- this.removeDrawerLayer(this._instance);
154
- this._instance = null;
155
- return;
156
- }
157
108
  if (this._status === STATUS.END_DRAW || this._status === STATUS.EDITING) {
158
109
  this.endEdit();
159
110
  return;
160
111
  }
112
+ this._instance.destroy();
113
+ this._instance = null;
114
+ this._changeStatus(STATUS.INIT);
161
115
  }
162
116
 
163
117
  // 结束绘制
@@ -174,15 +128,17 @@ var Measure = /*#__PURE__*/function () {
174
128
  if (!this._canOperate()) return;
175
129
  if (!id) return;
176
130
  if (this._instance) {
177
- this.drawer.endEdit();
178
- this.setDrawerLayer(this._instance.id, this._instance);
179
- this._instance = null;
131
+ if (this._status === STATUS.EDITING || this._status === STATUS.END_DRAW) {
132
+ this.endEdit();
133
+ } else {
134
+ this._stopDraw();
135
+ }
180
136
  }
137
+ var layer = this.getDrawerLayer(id);
138
+ if (!(layer !== null && layer !== void 0 && layer._instance)) return;
139
+ this._instance = layer;
181
140
  this._changeStatus(STATUS.EDITING);
182
- this._instance = this.getDrawerLayer(id);
183
- if (!this._instance) return;
184
- this._changeStatus(STATUS.EDITING);
185
- this.drawer.startEdit(this._instance._instance);
141
+ this.drawer.startEdit(layer._instance);
186
142
  }
187
143
 
188
144
  // 结束编辑
@@ -191,26 +147,35 @@ var Measure = /*#__PURE__*/function () {
191
147
  value: function endEdit() {
192
148
  if (!this._canOperate()) return;
193
149
  this._changeStatus(STATUS.END_EDIT);
194
- if (!this._instance) return;
150
+ if (!this._instance) {
151
+ this._changeStatus(STATUS.INIT);
152
+ return;
153
+ }
195
154
  this.drawer.endEdit();
196
155
  this.setDrawerLayer(this._instance.id, this._instance);
197
156
  this._instance = null;
157
+ this._changeStatus(STATUS.INIT);
198
158
  }
199
159
 
200
160
  // 获取绘制的图层
201
161
  }, {
202
162
  key: "getDrawerLayer",
203
163
  value: function getDrawerLayer(id) {
204
- if (!this._canOperate) return;
164
+ var _this$_measureDrawLay;
165
+ if (!this._canOperate()) return;
205
166
  if (!id) return;
206
- return isString(id) ? this._measureDrawLayers.get(id) : id;
167
+ if (typeof id === 'string') {
168
+ return this._measureDrawLayers.get(id);
169
+ }
170
+ return (_this$_measureDrawLay = this._measureDrawLayers.get(id.id)) !== null && _this$_measureDrawLay !== void 0 ? _this$_measureDrawLay : id;
207
171
  }
208
172
 
209
173
  // 添加完成绘制的图层
210
174
  }, {
211
175
  key: "setDrawerLayer",
212
176
  value: function setDrawerLayer(id, value) {
213
- if (!this._instance) return;
177
+ if (!this._canOperate()) return;
178
+ if (!id || !value) return;
214
179
  this._measureDrawLayers.set(id, value);
215
180
  }
216
181
 
@@ -218,7 +183,7 @@ var Measure = /*#__PURE__*/function () {
218
183
  }, {
219
184
  key: "removeDrawerLayer",
220
185
  value: function removeDrawerLayer(id) {
221
- if (!this._canOperate) return;
186
+ if (!this._canOperate()) return;
222
187
  var layer = this.getDrawerLayer(id);
223
188
  if (layer) {
224
189
  var _this$_instance;
@@ -228,7 +193,6 @@ var Measure = /*#__PURE__*/function () {
228
193
  }
229
194
  this._measureDrawLayers.delete(layer.id);
230
195
  layer.destroy();
231
- layer = null;
232
196
  }
233
197
  }
234
198
 
@@ -236,7 +200,7 @@ var Measure = /*#__PURE__*/function () {
236
200
  }, {
237
201
  key: "getAllDrawerLayers",
238
202
  value: function getAllDrawerLayers() {
239
- if (!this._canOperate) return;
203
+ if (!this._canOperate()) return;
240
204
  return Array.from(this._measureDrawLayers.values());
241
205
  }
242
206
 
@@ -244,21 +208,33 @@ var Measure = /*#__PURE__*/function () {
244
208
  }, {
245
209
  key: "clearAllDrawerLayers",
246
210
  value: function clearAllDrawerLayers() {
247
- if (!this._canOperate) return;
248
- this._measureDrawLayers.forEach(function (t) {
249
- return t.destroy();
250
- });
211
+ var _this2 = this;
212
+ if (!this._canOperate()) return;
213
+ var layers = Array.from(new Set(this._measureDrawLayers.values()));
251
214
  this._measureDrawLayers.clear();
215
+ layers.forEach(function (layer) {
216
+ return layer.destroy();
217
+ });
218
+ if (this._instance && layers.some(function (layer) {
219
+ var _this2$_instance;
220
+ return layer.id === ((_this2$_instance = _this2._instance) === null || _this2$_instance === void 0 ? void 0 : _this2$_instance.id);
221
+ })) {
222
+ this._instance = null;
223
+ this._changeStatus(STATUS.INIT);
224
+ }
252
225
  }
253
226
 
254
227
  // 清除
255
228
  }, {
256
229
  key: "clear",
257
230
  value: function clear() {
258
- if (!this._canOperate) return;
231
+ if (!this._canOperate()) return;
259
232
  this.getMap().canvas.style.cursor = 'default';
260
233
  this._changeStatus(STATUS.INIT);
261
- this._instance && this._instance.destroy();
234
+ if (this._instance) {
235
+ this._measureDrawLayers.delete(this._instance.id);
236
+ this._instance.destroy();
237
+ }
262
238
  this._instance = null;
263
239
  this.clearAllDrawerLayers();
264
240
  }
@@ -267,12 +243,24 @@ var Measure = /*#__PURE__*/function () {
267
243
  }, {
268
244
  key: "destroy",
269
245
  value: function destroy() {
270
- if (!this._canOperate) return;
246
+ if (!this._canOperate()) return;
271
247
  this.clear();
272
248
  this.drawer.destroy();
273
249
  this.isDestroyed = true;
274
250
  }
251
+ }, {
252
+ key: "_emitCallback",
253
+ value: function _emitCallback(callbackName, positions, measure) {
254
+ if (!this._instance) return;
255
+ var callback = this.options[callbackName];
256
+ callback === null || callback === void 0 || callback({
257
+ layer: this._instance,
258
+ positions: positions,
259
+ measure: measure
260
+ });
261
+ }
275
262
  }]);
276
263
  return Measure;
277
264
  }();
265
+ export { AREA_SHAPE_TYPE, MEASURE_TYPE, STATUS } from "./types";
278
266
  export default Measure;
@@ -0,0 +1,95 @@
1
+ /// <reference path="../typings.d.ts" />
2
+ import type { Viewer } from 'deeptwins-cesium';
3
+ import type Drawer from '../drawer';
4
+ export declare const MEASURE_TYPE: {
5
+ readonly DISTANCE: "distance";
6
+ readonly AREA: "area";
7
+ };
8
+ export type MeasureType = (typeof MEASURE_TYPE)[keyof typeof MEASURE_TYPE];
9
+ export declare const AREA_SHAPE_TYPE: {
10
+ readonly POLYGON: "polygon";
11
+ readonly CIRCLE: "circle";
12
+ readonly REGULAR_POLYGON: "regularPolygon";
13
+ };
14
+ export type AreaShapeType = (typeof AREA_SHAPE_TYPE)[keyof typeof AREA_SHAPE_TYPE];
15
+ export declare const STATUS: {
16
+ readonly INIT: "INIT";
17
+ readonly START_DRAW: "START_DRAW";
18
+ readonly DRAWING: "DRAWING";
19
+ readonly END_DRAW: "END_DRAW";
20
+ readonly EDITING: "EDITING";
21
+ readonly END_EDIT: "END_EDIT";
22
+ };
23
+ export type Status = (typeof STATUS)[keyof typeof STATUS];
24
+ export type MeasurePosition = [number, number, number];
25
+ export interface DistanceMeasureCacheItem {
26
+ start: MeasurePosition;
27
+ end: MeasurePosition;
28
+ distance: number;
29
+ allDistance: number;
30
+ }
31
+ export interface DistancePreviewResult {
32
+ distance: number;
33
+ allDistance: number;
34
+ }
35
+ export interface AreaMeasureResult {
36
+ area: number;
37
+ }
38
+ export type DistanceMeasureResult = DistanceMeasureCacheItem[];
39
+ export type MeasureResult = DistanceMeasureResult | AreaMeasureResult;
40
+ export interface MeasureCallbackPayload {
41
+ layer: MeasureLayer;
42
+ positions: MeasurePosition[];
43
+ measure: MeasureResult;
44
+ }
45
+ export interface MeasureOptions extends Record<string, any> {
46
+ clampToGround: boolean;
47
+ splitNum: number;
48
+ onPointsChange?: (payload: MeasureCallbackPayload) => void;
49
+ onComplete?: (payload: MeasureCallbackPayload) => void;
50
+ }
51
+ export interface MeasureDrawConfig extends Partial<MeasureOptions> {
52
+ shapeType?: AreaShapeType;
53
+ segments?: number;
54
+ sides?: number;
55
+ [key: string]: any;
56
+ }
57
+ export interface ResolvedMeasureConfig extends MeasureDrawConfig {
58
+ clampToGround: boolean;
59
+ splitNum: number;
60
+ }
61
+ export interface MeasureLabelLayer {
62
+ setData(data: any): void;
63
+ setStyle(style: any): void;
64
+ destroy(): void;
65
+ }
66
+ export interface MeasureDragPoint {
67
+ labelLayer: {
68
+ setStyle(style: any): void;
69
+ };
70
+ }
71
+ export interface MeasureShapeLayer {
72
+ id: string;
73
+ dragPoints: MeasureDragPoint[];
74
+ destroy(): void;
75
+ }
76
+ export interface MeasureMap extends Viewer {
77
+ addGraphicLayer(data: any, options: any): MeasureLabelLayer;
78
+ }
79
+ export interface MeasureContext {
80
+ options: MeasureOptions;
81
+ getMap: () => MeasureMap;
82
+ drawer: Drawer;
83
+ setDrawerLayer: (id: string, value: MeasureLayer) => void;
84
+ _changeStatus: (status: Status) => void;
85
+ }
86
+ export interface MeasureLayer {
87
+ id: string;
88
+ _instance: MeasureShapeLayer | null;
89
+ drawing(positions: MeasurePosition[]): MeasureResult | DistancePreviewResult | Record<string, never> | void;
90
+ pointsChange(layer: MeasureShapeLayer, positions: MeasurePosition[]): MeasureResult;
91
+ drawEnd(positions?: MeasurePosition[]): MeasureResult;
92
+ startEdit(): void;
93
+ endEdit(positions?: MeasurePosition[]): MeasureResult;
94
+ destroy(): void;
95
+ }