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,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,94 @@
1
+ import type { Viewer } from 'deeptwins-cesium';
2
+ import type Drawer from '../drawer';
3
+ export declare const MEASURE_TYPE: {
4
+ readonly DISTANCE: "distance";
5
+ readonly AREA: "area";
6
+ };
7
+ export type MeasureType = (typeof MEASURE_TYPE)[keyof typeof MEASURE_TYPE];
8
+ export declare const AREA_SHAPE_TYPE: {
9
+ readonly POLYGON: "polygon";
10
+ readonly CIRCLE: "circle";
11
+ readonly REGULAR_POLYGON: "regularPolygon";
12
+ };
13
+ export type AreaShapeType = (typeof AREA_SHAPE_TYPE)[keyof typeof AREA_SHAPE_TYPE];
14
+ export declare const STATUS: {
15
+ readonly INIT: "INIT";
16
+ readonly START_DRAW: "START_DRAW";
17
+ readonly DRAWING: "DRAWING";
18
+ readonly END_DRAW: "END_DRAW";
19
+ readonly EDITING: "EDITING";
20
+ readonly END_EDIT: "END_EDIT";
21
+ };
22
+ export type Status = (typeof STATUS)[keyof typeof STATUS];
23
+ export type MeasurePosition = [number, number, number];
24
+ export interface DistanceMeasureCacheItem {
25
+ start: MeasurePosition;
26
+ end: MeasurePosition;
27
+ distance: number;
28
+ allDistance: number;
29
+ }
30
+ export interface DistancePreviewResult {
31
+ distance: number;
32
+ allDistance: number;
33
+ }
34
+ export interface AreaMeasureResult {
35
+ area: number;
36
+ }
37
+ export type DistanceMeasureResult = DistanceMeasureCacheItem[];
38
+ export type MeasureResult = DistanceMeasureResult | AreaMeasureResult;
39
+ export interface MeasureCallbackPayload {
40
+ layer: MeasureLayer;
41
+ positions: MeasurePosition[];
42
+ measure: MeasureResult;
43
+ }
44
+ export interface MeasureOptions extends Record<string, any> {
45
+ clampToGround: boolean;
46
+ splitNum: number;
47
+ onPointsChange?: (payload: MeasureCallbackPayload) => void;
48
+ onComplete?: (payload: MeasureCallbackPayload) => void;
49
+ }
50
+ export interface MeasureDrawConfig extends Partial<MeasureOptions> {
51
+ shapeType?: AreaShapeType;
52
+ segments?: number;
53
+ sides?: number;
54
+ [key: string]: any;
55
+ }
56
+ export interface ResolvedMeasureConfig extends MeasureDrawConfig {
57
+ clampToGround: boolean;
58
+ splitNum: number;
59
+ }
60
+ export interface MeasureLabelLayer {
61
+ setData(data: any): void;
62
+ setStyle(style: any): void;
63
+ destroy(): void;
64
+ }
65
+ export interface MeasureDragPoint {
66
+ labelLayer: {
67
+ setStyle(style: any): void;
68
+ };
69
+ }
70
+ export interface MeasureShapeLayer {
71
+ id: string;
72
+ dragPoints: MeasureDragPoint[];
73
+ destroy(): void;
74
+ }
75
+ export interface MeasureMap extends Viewer {
76
+ addGraphicLayer(data: any, options: any): MeasureLabelLayer;
77
+ }
78
+ export interface MeasureContext {
79
+ options: MeasureOptions;
80
+ getMap: () => MeasureMap;
81
+ drawer: Drawer;
82
+ setDrawerLayer: (id: string, value: MeasureLayer) => void;
83
+ _changeStatus: (status: Status) => void;
84
+ }
85
+ export interface MeasureLayer {
86
+ id: string;
87
+ _instance: MeasureShapeLayer | null;
88
+ drawing(positions: MeasurePosition[]): MeasureResult | DistancePreviewResult | Record<string, never> | void;
89
+ pointsChange(layer: MeasureShapeLayer, positions: MeasurePosition[]): MeasureResult;
90
+ drawEnd(positions?: MeasurePosition[]): MeasureResult;
91
+ startEdit(): void;
92
+ endEdit(positions?: MeasurePosition[]): MeasureResult;
93
+ destroy(): void;
94
+ }
@@ -0,0 +1,17 @@
1
+ export var MEASURE_TYPE = {
2
+ DISTANCE: 'distance',
3
+ AREA: 'area'
4
+ };
5
+ export var AREA_SHAPE_TYPE = {
6
+ POLYGON: 'polygon',
7
+ CIRCLE: 'circle',
8
+ REGULAR_POLYGON: 'regularPolygon'
9
+ };
10
+ export var STATUS = {
11
+ INIT: 'INIT',
12
+ START_DRAW: 'START_DRAW',
13
+ DRAWING: 'DRAWING',
14
+ END_DRAW: 'END_DRAW',
15
+ EDITING: 'EDITING',
16
+ END_EDIT: 'END_EDIT'
17
+ };
@@ -1,4 +1,4 @@
1
- import { Polygon } from '@turf/helpers';
1
+ import { MultiPolygon, Polygon } from '@turf/helpers';
2
2
  import { Cartesian2, Cartesian3, type Viewer } from 'deeptwins-cesium';
3
3
  /**
4
4
  * 从地图中拾取指定屏幕坐标对应的三维笛卡尔坐标
@@ -10,7 +10,7 @@ export declare function pickCartesian3(map: Viewer, position: Cartesian2): Carte
10
10
  /**
11
11
  * 计算给定点集合的边界范围
12
12
  * @param points - 二维笛卡尔坐标点数组
13
- * @returns 返回边界范围数组,格式为[left, top, right, bottom]
13
+ * @returns 返回边界范围数组,格式为[minX, minY, maxX, maxY]
14
14
  */
15
15
  export declare function getBounds(points: Cartesian2[]): number[];
16
16
  /**
@@ -88,16 +88,16 @@ export declare function Cartesian2turfPolygon(positions: Cartesian2[]): Polygon;
88
88
  * 计算两个多边形的交集区域
89
89
  * @param poly1 - 第一个多边形
90
90
  * @param poly2 - 第二个多边形
91
- * @returns 交集区域的顶点坐标数组,如果没有交集则返回空数组
91
+ * @returns 交集区域的顶点坐标数组集合,如果没有交集则返回空数组
92
92
  */
93
- export declare function getIntersect(poly1: Polygon, poly2: Polygon): Cartesian2[];
93
+ export declare function getIntersect(poly1: Polygon, poly2: Polygon): Cartesian2[][];
94
94
  /**
95
95
  * 将Turf.js的Polygon对象转换为Cesium的Cartesian2数组
96
96
  *
97
- * @param polygon - Turf.js的Polygon对象,包含经纬度坐标信息
98
- * @returns 返回一个Cartesian2数组,每个元素对应polygon外环坐标点的二维笛卡尔坐标
97
+ * @param polygonGeometry - Turf.js的Polygon或MultiPolygon对象,包含经纬度坐标信息
98
+ * @returns 返回Cartesian2数组集合,每个元素对应一个外环坐标点集合
99
99
  */
100
- export declare function turfPolygon2CartesianArr(polygon: Polygon): Cartesian2[];
100
+ export declare function turfPolygon2CartesianArr(polygonGeometry: Polygon | MultiPolygon): Cartesian2[][];
101
101
  /**
102
102
  * 计算地图上指定位置围成区域的表面积
103
103
  * @param map - 地图查看器实例
@@ -26,22 +26,22 @@ export function pickCartesian3(map, position) {
26
26
  /**
27
27
  * 计算给定点集合的边界范围
28
28
  * @param points - 二维笛卡尔坐标点数组
29
- * @returns 返回边界范围数组,格式为[left, top, right, bottom]
29
+ * @returns 返回边界范围数组,格式为[minX, minY, maxX, maxY]
30
30
  */
31
31
  export function getBounds(points) {
32
- var left = Math.min.apply(Math, _toConsumableArray(points.map(function (item) {
32
+ var minX = Math.min.apply(Math, _toConsumableArray(points.map(function (item) {
33
33
  return item.x;
34
34
  })));
35
- var right = Math.max.apply(Math, _toConsumableArray(points.map(function (item) {
35
+ var maxX = Math.max.apply(Math, _toConsumableArray(points.map(function (item) {
36
36
  return item.x;
37
37
  })));
38
- var top = Math.max.apply(Math, _toConsumableArray(points.map(function (item) {
38
+ var minY = Math.min.apply(Math, _toConsumableArray(points.map(function (item) {
39
39
  return item.y;
40
40
  })));
41
- var bottom = Math.min.apply(Math, _toConsumableArray(points.map(function (item) {
41
+ var maxY = Math.max.apply(Math, _toConsumableArray(points.map(function (item) {
42
42
  return item.y;
43
43
  })));
44
- return [left, top, right, bottom];
44
+ return [minX, minY, maxX, maxY];
45
45
  }
46
46
 
47
47
  /**
@@ -88,8 +88,8 @@ export function calculateSurfaceDistance(map, startPoint, endPoint) {
88
88
  var splitNum = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 20;
89
89
  var resultDistance = 0;
90
90
  var sampleWindowPoints = [startPoint];
91
- var interval = Math.sqrt(Math.pow(endPoint.x - startPoint.x, 2) + (endPoint.y - startPoint.y, 2)) / splitNum;
92
- for (var ii = 1; ii <= splitNum; ii += 1) {
91
+ var interval = Math.sqrt(Math.pow(endPoint.x - startPoint.x, 2) + Math.pow(endPoint.y - startPoint.y, 2)) / splitNum;
92
+ for (var ii = 1; ii < splitNum; ii += 1) {
93
93
  var tempPositon = findWindowPositionByPixelInterval(startPoint, endPoint, ii * interval);
94
94
  sampleWindowPoints.push(tempPositon);
95
95
  }
@@ -181,6 +181,9 @@ export function calculateDetailSurfaceLength(map, startPoint, endPoint) {
181
181
  */
182
182
  export function calculateSurfaceArea(map, positions) {
183
183
  var splitNum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 20;
184
+ if (positions.length < 3) {
185
+ return 0;
186
+ }
184
187
  var result = 0;
185
188
  // 获取边界范围
186
189
  var bounds = getBounds(positions);
@@ -194,10 +197,15 @@ export function calculateSurfaceArea(map, positions) {
194
197
  var voronoiPolygons = voronoi(points, {
195
198
  bbox: [bounds[0], bounds[1], bounds[2], bounds[3]]
196
199
  });
200
+ if (!voronoiPolygons) {
201
+ return 0;
202
+ }
197
203
  // 遍历Voronoi多边形计算相交区域的表面积
198
204
  voronoiPolygons.features.forEach(function (element) {
199
- var intersectPoints = getIntersect(mainPoly, element.geometry);
200
- result += calculateDetailSurfaceArea(map, intersectPoints);
205
+ var intersectPolygons = getIntersect(mainPoly, element.geometry);
206
+ intersectPolygons.forEach(function (intersectPoints) {
207
+ result += calculateDetailSurfaceArea(map, intersectPoints);
208
+ });
201
209
  });
202
210
  return result;
203
211
  }
@@ -221,26 +229,32 @@ export function Cartesian2turfPolygon(positions) {
221
229
  * 计算两个多边形的交集区域
222
230
  * @param poly1 - 第一个多边形
223
231
  * @param poly2 - 第二个多边形
224
- * @returns 交集区域的顶点坐标数组,如果没有交集则返回空数组
232
+ * @returns 交集区域的顶点坐标数组集合,如果没有交集则返回空数组
225
233
  */
226
234
  export function getIntersect(poly1, poly2) {
227
235
  var intersection = intersect(poly1, poly2);
228
- if ((intersection === null || intersection === void 0 ? void 0 : intersection.geometry) !== undefined) {
229
- return turfPolygon2CartesianArr(intersection === null || intersection === void 0 ? void 0 : intersection.geometry);
230
- } else {
236
+ if (!(intersection !== null && intersection !== void 0 && intersection.geometry)) {
231
237
  return [];
232
238
  }
239
+ return turfPolygon2CartesianArr(intersection.geometry);
233
240
  }
234
241
 
235
242
  /**
236
243
  * 将Turf.js的Polygon对象转换为Cesium的Cartesian2数组
237
244
  *
238
- * @param polygon - Turf.js的Polygon对象,包含经纬度坐标信息
239
- * @returns 返回一个Cartesian2数组,每个元素对应polygon外环坐标点的二维笛卡尔坐标
245
+ * @param polygonGeometry - Turf.js的Polygon或MultiPolygon对象,包含经纬度坐标信息
246
+ * @returns 返回Cartesian2数组集合,每个元素对应一个外环坐标点集合
240
247
  */
241
- export function turfPolygon2CartesianArr(polygon) {
242
- return polygon.coordinates[0].map(function (item) {
243
- return new Cartesian2(item[0], item[1]);
248
+ export function turfPolygon2CartesianArr(polygonGeometry) {
249
+ if (polygonGeometry.type === 'Polygon') {
250
+ return [polygonGeometry.coordinates[0].map(function (item) {
251
+ return new Cartesian2(item[0], item[1]);
252
+ })];
253
+ }
254
+ return polygonGeometry.coordinates.map(function (coordinates) {
255
+ return coordinates[0].map(function (item) {
256
+ return new Cartesian2(item[0], item[1]);
257
+ });
244
258
  });
245
259
  }
246
260
 
@@ -251,6 +265,9 @@ export function turfPolygon2CartesianArr(polygon) {
251
265
  * @returns 返回世界坐标系中围成区域的表面积
252
266
  */
253
267
  export function calculateDetailSurfaceArea(map, positions) {
268
+ if (positions.length < 3) {
269
+ return 0;
270
+ }
254
271
  var worldPositions = [];
255
272
  positions.forEach(function (element) {
256
273
  var pickResult = pickCartesian3(map, element);
@@ -269,10 +286,12 @@ export function calculateDetailSurfaceArea(map, positions) {
269
286
  * @returns 返回由输入点围成区域的近似面积(单位:平方米)。
270
287
  */
271
288
  export function getWorldPositionsArea(positions) {
289
+ if (positions.length < 3) {
290
+ return 0;
291
+ }
272
292
  var x = [0];
273
293
  var y = [0];
274
294
  var geodesic = new EllipsoidGeodesic();
275
- var radiansPerDegree = Math.PI / 180.0; //角度转化为弧度(rad)
276
295
  //数组x,y分别按顺序存储各点的横、纵坐标值
277
296
  for (var i = 0; i < positions.length - 1; i += 1) {
278
297
  var p1 = positions[i];
@@ -281,10 +300,10 @@ export function getWorldPositionsArea(positions) {
281
300
  var point2cartographic = Cartographic.fromCartesian(p2);
282
301
  geodesic.setEndPoints(point1cartographic, point2cartographic);
283
302
  var s = Math.sqrt(Math.pow(geodesic.surfaceDistance, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
284
- var lat1 = point2cartographic.latitude * radiansPerDegree;
285
- var lon1 = point2cartographic.longitude * radiansPerDegree;
286
- var lat2 = point1cartographic.latitude * radiansPerDegree;
287
- var lon2 = point1cartographic.longitude * radiansPerDegree;
303
+ var lat1 = point2cartographic.latitude;
304
+ var lon1 = point2cartographic.longitude;
305
+ var lat2 = point1cartographic.latitude;
306
+ var lon2 = point1cartographic.longitude;
288
307
  var angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2));
289
308
  if (angle < 0) {
290
309
  angle += Math.PI * 2.0;