deeptwins-engine-3d 0.1.32 → 0.1.34

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 (178) hide show
  1. package/dist/assets/Build/DeepTwins/Image/f_point.png +0 -0
  2. package/dist/esm/analyze/SubmergenceAnalysis.d.ts +19 -0
  3. package/dist/esm/analyze/SubmergenceAnalysis.js +137 -0
  4. package/dist/esm/constant.d.ts +29 -0
  5. package/dist/esm/constant.js +47 -0
  6. package/dist/esm/drawer/index.d.ts +56 -59
  7. package/dist/esm/drawer/index.js +380 -292
  8. package/dist/esm/drawer/shape/BaseShape.d.ts +33 -0
  9. package/dist/esm/drawer/shape/BaseShape.js +228 -0
  10. package/dist/esm/drawer/shape/Point.d.ts +44 -11
  11. package/dist/esm/drawer/shape/Point.js +299 -35
  12. package/dist/esm/drawer/shape/Polygon.d.ts +43 -9
  13. package/dist/esm/drawer/shape/Polygon.js +408 -56
  14. package/dist/esm/drawer/shape/Polyline.d.ts +41 -10
  15. package/dist/esm/drawer/shape/Polyline.js +373 -31
  16. package/dist/esm/drawer/utils.d.ts +1 -0
  17. package/dist/esm/drawer/utils.js +63 -0
  18. package/dist/esm/graphicLayer/BaseLayer.d.ts +1 -0
  19. package/dist/esm/graphicLayer/BaseLayer.js +8 -3
  20. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  21. package/dist/esm/graphicLayer/BaseSource.js +13 -3
  22. package/dist/esm/graphicLayer/GraphicLayerCollection.d.ts +2 -0
  23. package/dist/esm/graphicLayer/GraphicLayerCollection.js +46 -4
  24. package/dist/esm/graphicLayer/HtmlEntity.js +1 -2
  25. package/dist/esm/index.d.ts +1 -1
  26. package/dist/esm/index.js +7 -4
  27. package/dist/esm/map/Map.d.ts +1 -0
  28. package/dist/esm/map/Map.js +10 -0
  29. package/dist/esm/measure/Area.d.ts +29 -0
  30. package/dist/esm/measure/{AreaMeasure.js → Area.js} +156 -65
  31. package/dist/esm/measure/BaseDraw.d.ts +13 -0
  32. package/dist/esm/measure/BaseDraw.js +70 -0
  33. package/dist/esm/measure/Distance.d.ts +23 -0
  34. package/dist/esm/measure/Distance.js +239 -0
  35. package/dist/esm/measure/index.d.ts +44 -5
  36. package/dist/esm/measure/index.js +278 -5
  37. package/dist/esm/measure/utils.d.ts +108 -14
  38. package/dist/esm/measure/utils.js +262 -20
  39. package/dist/esm/plot/create/CreateAssemble.d.ts +2 -0
  40. package/dist/esm/plot/create/CreateAssemble.js +63 -0
  41. package/dist/esm/plot/create/CreateAttackArrow.d.ts +5 -0
  42. package/dist/esm/plot/create/CreateAttackArrow.js +75 -0
  43. package/dist/esm/plot/create/CreateBillboard.d.ts +2 -0
  44. package/dist/esm/plot/create/CreateBillboard.js +47 -0
  45. package/dist/esm/plot/create/CreateBow.d.ts +2 -0
  46. package/dist/esm/plot/create/CreateBow.js +63 -0
  47. package/dist/esm/plot/create/CreateCircle.d.ts +2 -0
  48. package/dist/esm/plot/create/CreateCircle.js +68 -0
  49. package/dist/esm/plot/create/CreateCurve.d.ts +2 -0
  50. package/dist/esm/plot/create/CreateCurve.js +76 -0
  51. package/dist/esm/plot/create/CreateElliptic.d.ts +2 -0
  52. package/dist/esm/plot/create/CreateElliptic.js +69 -0
  53. package/dist/esm/plot/create/CreateFlag.d.ts +2 -0
  54. package/dist/esm/plot/create/CreateFlag.js +80 -0
  55. package/dist/esm/plot/create/CreateFormation.d.ts +2 -0
  56. package/dist/esm/plot/create/CreateFormation.js +65 -0
  57. package/dist/esm/plot/create/CreateFreeLine.d.ts +2 -0
  58. package/dist/esm/plot/create/CreateFreeLine.js +69 -0
  59. package/dist/esm/plot/create/CreateFreePolygon.d.ts +2 -0
  60. package/dist/esm/plot/create/CreateFreePolygon.js +65 -0
  61. package/dist/esm/plot/create/CreateLabel.d.ts +2 -0
  62. package/dist/esm/plot/create/CreateLabel.js +55 -0
  63. package/dist/esm/plot/create/CreateLineArrow.d.ts +2 -0
  64. package/dist/esm/plot/create/CreateLineArrow.js +79 -0
  65. package/dist/esm/plot/create/CreatePincerArrow.d.ts +5 -0
  66. package/dist/esm/plot/create/CreatePincerArrow.js +73 -0
  67. package/dist/esm/plot/create/CreatePoint.d.ts +2 -0
  68. package/dist/esm/plot/create/CreatePoint.js +47 -0
  69. package/dist/esm/plot/create/CreatePolygon.d.ts +2 -0
  70. package/dist/esm/plot/create/CreatePolygon.js +80 -0
  71. package/dist/esm/plot/create/CreatePolyline.d.ts +2 -0
  72. package/dist/esm/plot/create/CreatePolyline.js +70 -0
  73. package/dist/esm/plot/create/CreateRectangle.d.ts +2 -0
  74. package/dist/esm/plot/create/CreateRectangle.js +60 -0
  75. package/dist/esm/plot/create/CreateRegularPolygon.d.ts +2 -0
  76. package/dist/esm/plot/create/CreateRegularPolygon.js +75 -0
  77. package/dist/esm/plot/create/CreateRightAngleArrow.d.ts +5 -0
  78. package/dist/esm/plot/create/CreateRightAngleArrow.js +73 -0
  79. package/dist/esm/plot/create/CreateRoundRectangle.d.ts +2 -0
  80. package/dist/esm/plot/create/CreateRoundRectangle.js +63 -0
  81. package/dist/esm/plot/create/CreateSector.d.ts +2 -0
  82. package/dist/esm/plot/create/CreateSector.js +65 -0
  83. package/dist/esm/plot/create/CreateStraightArrow.d.ts +5 -0
  84. package/dist/esm/plot/create/CreateStraightArrow.js +65 -0
  85. package/dist/esm/plot/create/CreateSwallowtailArrow.d.ts +5 -0
  86. package/dist/esm/plot/create/CreateSwallowtailArrow.js +67 -0
  87. package/dist/esm/plot/create/index.d.ts +25 -0
  88. package/dist/esm/plot/create/index.js +25 -0
  89. package/dist/esm/plot/edit/EditAssemble.d.ts +8 -0
  90. package/dist/esm/plot/edit/EditAssemble.js +120 -0
  91. package/dist/esm/plot/edit/EditAttackArrow.d.ts +8 -0
  92. package/dist/esm/plot/edit/EditAttackArrow.js +182 -0
  93. package/dist/esm/plot/edit/EditBillboard.d.ts +7 -0
  94. package/dist/esm/plot/edit/EditBillboard.js +70 -0
  95. package/dist/esm/plot/edit/EditBow.d.ts +8 -0
  96. package/dist/esm/plot/edit/EditBow.js +119 -0
  97. package/dist/esm/plot/edit/EditCircle.d.ts +8 -0
  98. package/dist/esm/plot/edit/EditCircle.js +133 -0
  99. package/dist/esm/plot/edit/EditCurve.d.ts +8 -0
  100. package/dist/esm/plot/edit/EditCurve.js +180 -0
  101. package/dist/esm/plot/edit/EditElliptic.d.ts +8 -0
  102. package/dist/esm/plot/edit/EditElliptic.js +144 -0
  103. package/dist/esm/plot/edit/EditFlag.d.ts +8 -0
  104. package/dist/esm/plot/edit/EditFlag.js +121 -0
  105. package/dist/esm/plot/edit/EditFormation.d.ts +8 -0
  106. package/dist/esm/plot/edit/EditFormation.js +120 -0
  107. package/dist/esm/plot/edit/EditLabel.d.ts +7 -0
  108. package/dist/esm/plot/edit/EditLabel.js +100 -0
  109. package/dist/esm/plot/edit/EditLineArrow.d.ts +8 -0
  110. package/dist/esm/plot/edit/EditLineArrow.js +180 -0
  111. package/dist/esm/plot/edit/EditPincerArrow.d.ts +8 -0
  112. package/dist/esm/plot/edit/EditPincerArrow.js +121 -0
  113. package/dist/esm/plot/edit/EditPoint.d.ts +7 -0
  114. package/dist/esm/plot/edit/EditPoint.js +70 -0
  115. package/dist/esm/plot/edit/EditPolygon.d.ts +8 -0
  116. package/dist/esm/plot/edit/EditPolygon.js +181 -0
  117. package/dist/esm/plot/edit/EditPolyline.d.ts +8 -0
  118. package/dist/esm/plot/edit/EditPolyline.js +179 -0
  119. package/dist/esm/plot/edit/EditRectangle.d.ts +8 -0
  120. package/dist/esm/plot/edit/EditRectangle.js +119 -0
  121. package/dist/esm/plot/edit/EditRegularPolygon.d.ts +8 -0
  122. package/dist/esm/plot/edit/EditRegularPolygon.js +170 -0
  123. package/dist/esm/plot/edit/EditRightAngleArrow.d.ts +8 -0
  124. package/dist/esm/plot/edit/EditRightAngleArrow.js +143 -0
  125. package/dist/esm/plot/edit/EditRoundRectangle.d.ts +8 -0
  126. package/dist/esm/plot/edit/EditRoundRectangle.js +119 -0
  127. package/dist/esm/plot/edit/EditSector.d.ts +8 -0
  128. package/dist/esm/plot/edit/EditSector.js +120 -0
  129. package/dist/esm/plot/edit/EditStraightArrow.d.ts +8 -0
  130. package/dist/esm/plot/edit/EditStraightArrow.js +120 -0
  131. package/dist/esm/plot/edit/EditSwallowtailArrow.d.ts +8 -0
  132. package/dist/esm/plot/edit/EditSwallowtailArrow.js +121 -0
  133. package/dist/esm/plot/edit/index.d.ts +23 -0
  134. package/dist/esm/plot/edit/index.js +23 -0
  135. package/dist/esm/plot/utils/Algorithm.d.ts +2 -0
  136. package/dist/esm/plot/utils/Algorithm.js +316 -0
  137. package/dist/esm/plot/utils/Coordinate.d.ts +98 -0
  138. package/dist/esm/plot/utils/Coordinate.js +184 -0
  139. package/dist/esm/plot/utils/DomUtil.d.ts +34 -0
  140. package/dist/esm/plot/utils/DomUtil.js +100 -0
  141. package/dist/esm/plot/utils/PlotCommon.d.ts +101 -0
  142. package/dist/esm/plot/utils/PlotCommon.js +1412 -0
  143. package/dist/esm/plot/utils/ReminderTip.d.ts +10 -0
  144. package/dist/esm/plot/utils/ReminderTip.js +67 -0
  145. package/dist/esm/plot/utils/Tooltip.d.ts +3 -0
  146. package/dist/esm/plot/utils/Tooltip.js +97 -0
  147. package/dist/esm/plot/utils/plotUtil.d.ts +5 -0
  148. package/dist/esm/plot/utils/plotUtil.js +268 -0
  149. package/dist/esm/tool/utils.d.ts +8 -7
  150. package/dist/esm/tool/utils.js +20 -16
  151. package/dist/esm/toolTip/index.d.ts +2 -1
  152. package/dist/esm/toolTip/index.js +12 -6
  153. package/dist/esm/typings.d.ts +1 -0
  154. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  155. package/package.json +1 -1
  156. package/dist/esm/drawer/base.d.ts +0 -51
  157. package/dist/esm/drawer/base.js +0 -179
  158. package/dist/esm/drawer/painter.d.ts +0 -41
  159. package/dist/esm/drawer/painter.js +0 -115
  160. package/dist/esm/drawer/shape/Ellipse.d.ts +0 -10
  161. package/dist/esm/drawer/shape/Ellipse.js +0 -62
  162. package/dist/esm/drawer/shape/Rectangle.d.ts +0 -10
  163. package/dist/esm/drawer/shape/Rectangle.js +0 -85
  164. package/dist/esm/drawer/typings.d.ts +0 -106
  165. package/dist/esm/drawer/typings.js +0 -1
  166. package/dist/esm/measure/AreaMeasure.d.ts +0 -19
  167. package/dist/esm/measure/AreaSurfaceMeasure.d.ts +0 -30
  168. package/dist/esm/measure/AreaSurfaceMeasure.js +0 -151
  169. package/dist/esm/measure/DistanceMeasure.d.ts +0 -19
  170. package/dist/esm/measure/DistanceMeasure.js +0 -91
  171. package/dist/esm/measure/DistanceSurfaceMeasure.d.ts +0 -37
  172. package/dist/esm/measure/DistanceSurfaceMeasure.js +0 -122
  173. package/dist/esm/measure/Measure.d.ts +0 -111
  174. package/dist/esm/measure/Measure.js +0 -177
  175. package/dist/esm/tool/cesiumExtends/Subscriber/index.d.ts +0 -66
  176. package/dist/esm/tool/cesiumExtends/Subscriber/index.js +0 -246
  177. package/dist/esm/tool/kriging.d.ts +0 -10
  178. package/dist/esm/tool/kriging.js +0 -436
@@ -1,350 +1,438 @@
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; }
7
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; }
8
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
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); }
10
- import { Color, defaultValue, JulianDate } from 'deeptwins-cesium';
11
- import Subscriber from "../tool/cesiumExtends/Subscriber";
8
+ import { featureEach } from '@turf/turf';
9
+ import * as Cesium from 'deeptwins-cesium';
10
+ import { isString, merge } from 'lodash';
11
+ import { DEFAULT_DRAWER_OPTIONS, LAYER_EVENT_TYPE } from "../constant";
12
+ import BaseSource from "../graphicLayer/BaseSource";
13
+ import * as utils from "../tool/utils";
12
14
  import ToolTip from "../toolTip/index";
13
- import Painter from "./painter";
14
- import Ellipse from "./shape/Ellipse";
15
15
  import Point from "./shape/Point";
16
16
  import Polygon from "./shape/Polygon";
17
17
  import Polyline from "./shape/Polyline";
18
- import Rectangle from "./shape/Rectangle";
19
- import { cartesian3ToLngLatAlt } from "../tool/utils";
20
- export * from "./typings";
21
- export var defaultOptions = {
22
- terrain: false,
23
- model: false,
24
- operateType: {
25
- START: 'LEFT_CLICK',
26
- MOVING: 'MOUSE_MOVE',
27
- CANCEL: 'RIGHT_CLICK',
28
- END: 'LEFT_DOUBLE_CLICK'
29
- },
30
- /**
31
- * 图形勾画时的Entity样式
32
- */
33
- dynamicGraphicsOptions: {
34
- polyline: {
35
- clampToGround: true,
36
- width: 2,
37
- material: Color.BLUE
38
- },
39
- polygon: {
40
- outlineColor: Color.BLUE,
41
- outlineWidth: 2,
42
- material: Color.BLUE.withAlpha(0.5)
43
- },
44
- point: {
45
- // HeightReference: HeightReference.CLAMP_TO_GROUND,
46
- color: Color.BLUE,
47
- pixelSize: 8,
48
- outlineColor: Color.WHITE,
49
- outlineWidth: 1
50
- },
51
- rectangle: {
52
- material: Color.BLUE.withAlpha(0.5)
53
- },
54
- ellipse: {
55
- material: Color.BLUE.withAlpha(0.5),
56
- outline: true
57
- }
58
- },
59
- sameStyle: true,
60
- tips: {
61
- init: '点击绘制',
62
- start: '左键添加点,右键移除点,双击结束绘制',
63
- end: ''
64
- }
18
+ import { HANDLE_FEATURE_DATA_TYPE_FUN } from "./utils";
19
+
20
+ // 根据类型相应的实现类
21
+ var DYNAMIC_GRAPHICS_TYPE = {
22
+ point: Point,
23
+ polyline: Polyline,
24
+ polygon: Polygon
25
+ };
26
+
27
+ // 根据相应的geoJson类型获取相应的实现类
28
+ var dynamicGraphicsGeoJsonType = {
29
+ Point: Point,
30
+ MultiPoint: Point,
31
+ LineString: Polyline,
32
+ MultiLineString: Polyline,
33
+ Polygon: Polygon,
34
+ MultiPolygon: Polygon
35
+ };
36
+ // 状态表定义
37
+ export var STATUS = {
38
+ INIT: 'INIT',
39
+ START_DRAW: 'START_DRAW',
40
+ DRAWING: 'DRAWING',
41
+ END_DRAW: 'END_DRAW',
42
+ EDITING: 'EDITING',
43
+ END_EDIT: 'END_EDIT'
65
44
  };
45
+
46
+ // 从状态表推导类型
47
+
48
+ // 支持多点绘制的形状类型表
49
+ export var MULTI_POINT_SHAPE_TYPES = {
50
+ POLYLINE: 'polyline',
51
+ POLYGON: 'polygon'
52
+ };
53
+
54
+ // 支持多点绘制的形状类型数组
55
+ export var MULTI_POINT_SHAPES = Object.values(MULTI_POINT_SHAPE_TYPES);
66
56
  var Drawer = /*#__PURE__*/function () {
67
- function Drawer(viewer, options) {
68
- var _options$sameStyle;
57
+ function Drawer(map) {
58
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
69
59
  _classCallCheck(this, Drawer);
70
- _defineProperty(this, "_viewer", void 0);
71
- _defineProperty(this, "_type", void 0);
72
- _defineProperty(this, "_terrain", void 0);
73
- _defineProperty(this, "_model", void 0);
74
- _defineProperty(this, "_subscriber", void 0);
75
- _defineProperty(this, "_status", void 0);
76
- _defineProperty(this, "_painter", void 0);
77
- _defineProperty(this, "_events", []);
78
- _defineProperty(this, "_typeClass", void 0);
79
- _defineProperty(this, "_option", void 0);
80
- _defineProperty(this, "$Instance", void 0);
81
- _defineProperty(this, "$AddedInstance", []);
82
- _defineProperty(this, "_dropPoint", void 0);
83
- _defineProperty(this, "_moving", void 0);
84
- _defineProperty(this, "_cancel", void 0);
85
- _defineProperty(this, "_playOff", void 0);
86
- /**
87
- * @desc 操作方式
88
- */
89
- _defineProperty(this, "_operateType", void 0);
90
- _defineProperty(this, "_oneInstance", void 0);
91
- _defineProperty(this, "_once", void 0);
92
- /**
93
- * @desc 动作回调
94
- */
95
- _defineProperty(this, "_action", void 0);
96
- _defineProperty(this, "_sameStyle", void 0);
97
- _defineProperty(this, "mouseTooltip", void 0);
98
- _defineProperty(this, "_tips", void 0);
99
- this._option = defaultValue(options, {});
100
- if (!viewer) throw new Error('请输入Viewer对象!');
101
-
102
- // 设置操作方式
103
- this._operateType = _objectSpread(_objectSpread({}, defaultOptions.operateType), options === null || options === void 0 ? void 0 : options.operateType);
104
- this._viewer = viewer;
105
- this._terrain = defaultValue(this._option.terrain, defaultOptions.terrain);
106
- this._model = defaultValue(this._option.model, defaultOptions.model);
107
- this._action = this._option.action;
108
- this._sameStyle = (_options$sameStyle = options === null || options === void 0 ? void 0 : options.sameStyle) !== null && _options$sameStyle !== void 0 ? _options$sameStyle : true;
109
- this._tips = _objectSpread(_objectSpread({}, defaultOptions.tips), options === null || options === void 0 ? void 0 : options.tips);
110
- if (this._terrain && !this._viewer.scene.pickPositionSupported) {
111
- console.warn('浏览器不支持 pickPosition属性,无法在有地形的情况下正确选点');
112
- this._terrain = false;
113
- }
114
- this._subscriber = new Subscriber(this._viewer);
115
- this.mouseTooltip = new ToolTip(viewer);
116
- this.mouseTooltip.show(false);
117
- this._status = 'INIT';
118
- // 为了防止产生侵入性bug,请在使用前确认相关事件是否可用,不再默认移除原生事件
119
- // Object.keys(this._option.keyboard).forEach(key =>
120
- // Subscriber.removeNative(this._viewer, this._option.keyboard[key])
121
- // )
60
+ _defineProperty(this, "_mapContext", void 0);
61
+ _defineProperty(this, "_drawContext", void 0);
62
+ _defineProperty(this, "options", void 0);
63
+ _defineProperty(this, "tooltip", void 0);
64
+ _defineProperty(this, "isDestroyed", false);
65
+ _defineProperty(this, "_status", STATUS.INIT);
66
+ // 拖动中
67
+ _defineProperty(this, "_dragging", false);
68
+ _defineProperty(this, "_eventLeftDown", void 0);
69
+ _defineProperty(this, "_eventLeftUp", void 0);
70
+ _defineProperty(this, "_eventClick", void 0);
71
+ _defineProperty(this, "_eventMove", void 0);
72
+ _defineProperty(this, "_eventDoubleClick", void 0);
73
+ _defineProperty(this, "_eventRightClick", void 0);
74
+ // 绘制的图形实例
75
+ _defineProperty(this, "_instance", void 0);
76
+ // 绘制完成的图层
77
+ _defineProperty(this, "_drawLayers", new Map());
78
+ this._mapContext = map._mapContext;
79
+ this.options = merge(DEFAULT_DRAWER_OPTIONS(), options);
80
+ this.tooltip = new ToolTip(this.getMap());
81
+ this.tooltip.show(false);
82
+ this._destroyListeners();
83
+ this._createListeners();
84
+ this._drawContext = {
85
+ options: this.options,
86
+ getMap: this.getMap.bind(this),
87
+ setDrawerLayer: this.setDrawerLayer.bind(this),
88
+ _changeStatus: this._changeStatus.bind(this),
89
+ _updateTooltip: this._updateTooltip.bind(this)
90
+ };
122
91
  }
123
92
 
124
- /**
125
- * @param finalOptions
126
- * @param dynamicOptions
127
- */
93
+ // 是否能进行操作
128
94
  _createClass(Drawer, [{
129
- key: "status",
130
- get: function get() {
131
- return this._status;
95
+ key: "_canOperate",
96
+ value: function _canOperate() {
97
+ if (this.isDestroyed) {
98
+ utils.error('Drawer实例已销毁');
99
+ return false;
100
+ }
101
+ return true;
132
102
  }
133
103
  }, {
134
- key: "operateType",
135
- get: function get() {
136
- return this._operateType;
104
+ key: "getMap",
105
+ value: function getMap() {
106
+ return this._mapContext && this._mapContext.getMap();
137
107
  }
108
+
109
+ // 是否是拖拽点
138
110
  }, {
139
- key: "isDestroyed",
140
- get: function get() {
141
- return this._status === 'DESTROY';
111
+ key: "_isDragPoint",
112
+ value: function _isDragPoint(e) {
113
+ var _this$_instance$dragP, _this$_instance$edges;
114
+ // 拖拽点图层
115
+ var dragPoint = (_this$_instance$dragP = this._instance.dragPoints) === null || _this$_instance$dragP === void 0 ? void 0 : _this$_instance$dragP.find(function (point) {
116
+ var _e$pickedObject;
117
+ return point.layer.layers[0].id === (e === null || e === void 0 || (_e$pickedObject = e.pickedObject) === null || _e$pickedObject === void 0 || (_e$pickedObject = _e$pickedObject.id) === null || _e$pickedObject === void 0 ? void 0 : _e$pickedObject.id);
118
+ });
119
+ // 中间点图层
120
+ var middlePoint = (_this$_instance$edges = this._instance.edges.find(function (t) {
121
+ var _t$middlePoint, _e$pickedObject2;
122
+ return (t === null || t === void 0 || (_t$middlePoint = t.middlePoint) === null || _t$middlePoint === void 0 || (_t$middlePoint = _t$middlePoint.layer) === null || _t$middlePoint === void 0 || (_t$middlePoint = _t$middlePoint.layers) === null || _t$middlePoint === void 0 || (_t$middlePoint = _t$middlePoint[0]) === null || _t$middlePoint === void 0 ? void 0 : _t$middlePoint.id) === (e === null || e === void 0 || (_e$pickedObject2 = e.pickedObject) === null || _e$pickedObject2 === void 0 || (_e$pickedObject2 = _e$pickedObject2.id) === null || _e$pickedObject2 === void 0 ? void 0 : _e$pickedObject2.id);
123
+ })) === null || _this$_instance$edges === void 0 ? void 0 : _this$_instance$edges.middlePoint;
124
+ return dragPoint || middlePoint;
142
125
  }
126
+
127
+ // 创建监听事件
143
128
  }, {
144
- key: "_initPainter",
145
- value: function _initPainter(options) {
146
- var painterOptions = {
147
- viewer: this._viewer,
148
- type: this._type,
149
- terrain: this._terrain,
150
- model: this._model
151
- };
152
- this._painter = new Painter(painterOptions);
153
- if (this._type === 'polygon') {
154
- this._typeClass = new Polygon(this._painter, options);
155
- } else if (this._type === 'polyline') {
156
- this._typeClass = new Polyline(this._painter, options);
157
- } else if (this._type === 'point') {
158
- this._typeClass = new Point(this._painter, options);
159
- } else if (this._type === 'ellipse') {
160
- this._typeClass = new Ellipse(this._painter, options);
161
- } else if (this._type === 'rectangle') {
162
- this._typeClass = new Rectangle(this._painter, options);
163
- }
164
- this._dropPoint = this._typeClass.dropPoint.bind(this._typeClass);
165
- this._moving = this._typeClass.moving.bind(this._typeClass);
166
- this._cancel = this._typeClass.cancel.bind(this._typeClass);
167
- this._playOff = this._typeClass.playOff.bind(this._typeClass);
129
+ key: "_createListeners",
130
+ value: function _createListeners() {
131
+ var _this = this;
132
+ // 鼠标按下
133
+ this._eventLeftDown = this.getMap().on(Cesium.ScreenSpaceEventType.LEFT_DOWN, function (e) {
134
+ if (!_this._instance) return;
135
+ if (_this._status !== STATUS.EDITING) return;
136
+ var dragPoint = _this._isDragPoint(e);
137
+ if (dragPoint) {
138
+ _this._dragging = true;
139
+ _this._instance.mouseDragStart(e.position, dragPoint);
140
+ // 禁用相机拖拽(避免和点拖拽冲突)
141
+ _this.getMap().scene.screenSpaceCameraController.enableRotate = false;
142
+ }
143
+ });
144
+ // 鼠标抬起
145
+ this._eventLeftUp = this.getMap().on(LAYER_EVENT_TYPE.LEFT_UP, function (e) {
146
+ if (!_this._instance) return;
147
+ if (_this._dragging) {
148
+ _this._dragging = false;
149
+ _this._instance.mouseDragEnd(e.position);
150
+ _this.getMap().scene.screenSpaceCameraController.enableRotate = true;
151
+ }
152
+ });
153
+ // 鼠标点击
154
+ this._eventClick = this.getMap().on(Cesium.ScreenSpaceEventType.LEFT_CLICK, function (e) {
155
+ if (!_this._instance) return;
156
+ if (_this._status !== STATUS.START_DRAW && _this._status !== STATUS.DRAWING) return;
157
+ // 添加点
158
+ _this._instance.addPoint(e.position);
159
+ });
160
+ // 鼠标移动
161
+ this._eventMove = this.getMap().on(Cesium.ScreenSpaceEventType.MOUSE_MOVE, function (e) {
162
+ if (!_this._instance) return;
163
+ // 绘制
164
+ if (_this._status === STATUS.START_DRAW || _this._status === STATUS.DRAWING) {
165
+ if (MULTI_POINT_SHAPES.includes(_this._instance.type)) {
166
+ _this._instance.updateTempPosition(e.position);
167
+ }
168
+ }
169
+ // 编辑
170
+ if (_this._status === STATUS.EDITING) {
171
+ var dragPoint = _this._isDragPoint(e);
172
+ if (dragPoint) {
173
+ _this.getMap().canvas.style.cursor = 'pointer';
174
+ } else {
175
+ _this.getMap().canvas.style.cursor = 'default';
176
+ }
177
+ if (_this._dragging) {
178
+ _this._instance.mouseDragChange(e.position, dragPoint);
179
+ }
180
+ }
181
+ });
182
+ // 鼠标双击
183
+ this._eventDoubleClick = this.getMap().on(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, function () {
184
+ if (!_this._instance) return;
185
+ if (_this._status !== STATUS.START_DRAW && _this._status !== STATUS.DRAWING) return;
186
+ if (MULTI_POINT_SHAPES.includes(_this._instance.type)) {
187
+ _this._instance.endDraw();
188
+ }
189
+ });
190
+ // 鼠标右键
191
+ this._eventRightClick = this.getMap().on(Cesium.ScreenSpaceEventType.RIGHT_CLICK, function () {
192
+ if (!_this._instance) return;
193
+ if (_this._status !== STATUS.START_DRAW && _this._status !== STATUS.DRAWING) return;
194
+ if (MULTI_POINT_SHAPES.includes(_this._instance.type)) {
195
+ _this._instance.removePrev();
196
+ }
197
+ });
168
198
  }
199
+
200
+ // 销毁监听事件
169
201
  }, {
170
- key: "_updateTips",
171
- value: function _updateTips() {
172
- if (!this._painter) return;
173
- if (this._status === 'INIT' || this._status === 'DESTROY') {
174
- this.mouseTooltip.show(false);
175
- return;
176
- }
177
- if (this._status === 'PAUSE') {
178
- this.mouseTooltip.setOptions({
179
- text: this._tips.end
202
+ key: "_destroyListeners",
203
+ value: function _destroyListeners() {
204
+ this._eventLeftDown && this._eventLeftDown.off();
205
+ this._eventLeftDown = null;
206
+ this._eventLeftUp && this._eventLeftUp.off();
207
+ this._eventLeftUp = null;
208
+ this._eventClick && this._eventClick.off();
209
+ this._eventClick = null;
210
+ this._eventMove && this._eventMove.off();
211
+ this._eventMove = null;
212
+ this._eventDoubleClick && this._eventDoubleClick.off();
213
+ this._eventDoubleClick = null;
214
+ this._eventRightClick && this._eventRightClick.off();
215
+ this._eventRightClick = null;
216
+ }
217
+
218
+ // 更新提示
219
+ }, {
220
+ key: "_updateTooltip",
221
+ value: function _updateTooltip() {
222
+ if (!this._canOperate()) return;
223
+ if (this._status === STATUS.START_DRAW) {
224
+ this.tooltip.setOptions({
225
+ text: '点击开始绘制'
180
226
  });
181
- if (this._once) this.mouseTooltip.show(false);
182
- return;
183
- }
184
- if (this._painter._breakPointEntities.length === 0) {
185
- this.mouseTooltip.setOptions({
186
- text: this._tips.init
227
+ this.tooltip.show(true);
228
+ } else if (this._status === STATUS.DRAWING) {
229
+ this.tooltip.setOptions({
230
+ text: '左键添加点,右键移除点,双击结束绘制'
187
231
  });
188
- this.mouseTooltip.show(true);
189
232
  } else {
190
- this.mouseTooltip.setOptions({
191
- text: this._tips.start
192
- });
193
- this.mouseTooltip.show(true);
233
+ this.tooltip.show(false);
194
234
  }
195
235
  }
196
236
 
197
- /**
198
- * @desc 绘制函数,
199
- * @param config 绘制配置,可以通过定义options直接改写结果而不再填第二个参数
200
- * @param overrideFunc Entity 重写函数,用于重写绘制结果,如果 overrideFunc返回一个Entity,则将该Entity添加到Viewer中,否则结束函数无操作
201
- * @returns
202
- */
237
+ // 修改状态
203
238
  }, {
204
- key: "start",
205
- value: function start(config) {
206
- var _this = this;
207
- var overrideFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (action, entity) {
208
- return entity;
209
- };
210
- config = defaultValue(config, {});
211
- this._once = defaultValue(config.once, true);
212
- this._oneInstance = defaultValue(config.oneInstance, false);
213
- if (!this._isSupport(config.type)) {
214
- throw new Error("the type '".concat(config.type, "' is not support"));
215
- }
216
- this._type = config.type;
217
- var defaultOpts = defaultOptions.dynamicGraphicsOptions[this._type];
218
- this._initPainter({
219
- finalOptions: _objectSpread(_objectSpread({}, defaultOpts), config.finalOptions),
220
- dynamicOptions: _objectSpread(_objectSpread({}, defaultOpts), config.dynamicOptions),
221
- sameStyle: this._sameStyle,
222
- complete: config.complete,
223
- onPointsChange: config.onPointsChange
224
- });
225
- if (this._status === 'START') return;
226
- this._status = 'START';
227
- this._viewer.canvas.style.cursor = 'crosshair';
228
- this._updateTips();
229
-
230
- /**
231
- * @desc 是否开始绘制
232
- */
233
- var isStartDraw = false;
234
-
235
- // 开始事件
236
- var startId = this._subscriber.addExternal(function (move) {
237
- if (_this._oneInstance && _this.$Instance) {
238
- _this._viewer.entities.remove(_this.$Instance);
239
- _this.$AddedInstance = [];
240
- }
241
- _this._dropPoint(move);
242
- if (_this._action) _this._action(_this._operateType.START, move);
239
+ key: "_changeStatus",
240
+ value: function _changeStatus(status) {
241
+ this._status = status;
242
+ }
243
243
 
244
- // 如果是点,则此时执行点的结束绘制操作
245
- if (_this._type === 'point') {
246
- var _this$$Instance;
247
- _this._typeClass.result = _this._viewer.addCustomSourceToGraphicLayer(_this._typeClass.result.position, {
248
- type: _this._type,
249
- id: _this._typeClass.result.id,
250
- entity: _this._typeClass.result
251
- });
252
- _this._complete(overrideFunc);
253
- isStartDraw = false;
254
- var positions = (_this$$Instance = _this.$Instance) === null || _this$$Instance === void 0 || (_this$$Instance = _this$$Instance.position) === null || _this$$Instance === void 0 ? void 0 : _this$$Instance.getValue(new JulianDate());
255
- if (config.complete && _this.$Instance && positions) {
256
- var point = cartesian3ToLngLatAlt(positions);
257
- config.complete(_this.$Instance, positions, [point]);
244
+ // 转化为绘制类型
245
+ }, {
246
+ key: "dataTransformDraw",
247
+ value: function dataTransformDraw(data) {
248
+ var _this2 = this;
249
+ var dataType = BaseSource.analysisSourceType(data);
250
+ var transformGeoJson;
251
+ if (dataType === 'wkt') {
252
+ transformGeoJson = BaseSource.wktToGeoJon(data);
253
+ } else if (dataType === 'geoJson') {
254
+ transformGeoJson = data;
255
+ }
256
+ if (!transformGeoJson) return;
257
+ var layers = [];
258
+ featureEach(transformGeoJson, function (feature) {
259
+ var handle = HANDLE_FEATURE_DATA_TYPE_FUN[feature.geometry.type];
260
+ var shapeClass = dynamicGraphicsGeoJsonType[feature.geometry.type];
261
+ if (!shapeClass) return;
262
+ if (handle) {
263
+ var handleFeature = handle(feature);
264
+ if (handleFeature.type === 'single') {
265
+ var layer = new shapeClass(_this2._drawContext);
266
+ layer.transformData(handleFeature.positions);
267
+ layers.push(layer);
268
+ }
269
+ if (handleFeature.type === 'multi') {
270
+ handleFeature.positions.forEach(function (position) {
271
+ var layer = new shapeClass(_this2._drawContext);
272
+ layer.transformData(position);
273
+ layers.push(layer);
274
+ });
258
275
  }
259
276
  }
260
- _this._updateTips();
261
- // 100ms后才能继续,避免热键冲突
262
- setTimeout(function () {
263
- isStartDraw = true;
264
- }, 100);
265
- }, this._operateType.START);
266
-
267
- // 移动事件
268
- var moveId = this._subscriber.addExternal(function (move) {
269
- _this._viewer.canvas.style.cursor = 'crosshair';
270
- if (!isStartDraw) return;
271
- _this._moving(move);
277
+ });
278
+ return layers;
279
+ }
272
280
 
273
- // ActionCallback
274
- if (_this._action) _this._action(_this._operateType.MOVING, move);
275
- }, this._operateType.MOVING);
281
+ // 开始绘制
282
+ }, {
283
+ key: "startDraw",
284
+ value: function startDraw(type) {
285
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
286
+ if (!this._canOperate()) return;
287
+ if (this._instance) {
288
+ this._stopDraw();
289
+ }
290
+ this._changeStatus(STATUS.START_DRAW);
291
+ this.getMap().canvas.style.cursor = 'crosshair';
292
+ this._updateTooltip();
293
+ var shapeClass = DYNAMIC_GRAPHICS_TYPE[type];
294
+ if (!shapeClass) return;
295
+ this._instance = new shapeClass(this._drawContext, config);
296
+ return this._instance;
297
+ }
276
298
 
277
- // Redraw the shape so it's not dynamic and remove the dynamic shape.
278
- var cancelId = this._subscriber.addExternal(function (move) {
279
- if (!isStartDraw) return;
280
- _this._cancel(move);
281
- _this._updateTips();
299
+ // 中止当前绘制
300
+ }, {
301
+ key: "_stopDraw",
302
+ value: function _stopDraw() {
303
+ if (!this._canOperate()) return;
304
+ if (!this._instance) return;
305
+ if (this._status === STATUS.INIT || this._status === STATUS.START_DRAW || this._status === STATUS.END_EDIT) {
306
+ var layer = this.getDrawerLayer(this._instance);
307
+ // layer未存入
308
+ if (!layer) {
309
+ this._instance.destroy();
310
+ }
311
+ this._instance = null;
312
+ return;
313
+ }
314
+ if (this._status === STATUS.DRAWING) {
315
+ this.removeDrawerLayer(this._instance);
316
+ this._instance = null;
317
+ return;
318
+ }
319
+ if (this._status === STATUS.END_DRAW || this._status === STATUS.EDITING) {
320
+ this.endEdit();
321
+ return;
322
+ }
323
+ }
282
324
 
283
- // ActionCallback
284
- if (_this._action) _this._action(_this._operateType.CANCEL, move);
285
- }, this._operateType.CANCEL);
325
+ // 开始编辑
326
+ }, {
327
+ key: "startEdit",
328
+ value: function startEdit(id) {
329
+ if (!this._canOperate()) return;
330
+ if (!id) return;
331
+ if (this._instance) {
332
+ this._instance.endEdit(this._instance);
333
+ this.setDrawerLayer(this._instance.id, this._instance);
334
+ this._instance = null;
335
+ }
336
+ this._changeStatus(STATUS.EDITING);
337
+ this._instance = this.getDrawerLayer(id);
338
+ if (!this._instance) return;
339
+ this._instance.startEdit();
340
+ }
286
341
 
287
- // Redraw the shape so it's not dynamic and remove the dynamic shape.
288
- var endId = this._subscriber.addExternal(function (move) {
289
- if (!isStartDraw) return;
342
+ // 结束编辑
343
+ }, {
344
+ key: "endEdit",
345
+ value: function endEdit() {
346
+ if (!this._canOperate()) return;
347
+ this._changeStatus(STATUS.END_EDIT);
348
+ this._updateTooltip();
349
+ if (!this._instance) return;
350
+ this._instance.endEdit(this._instance);
351
+ this.setDrawerLayer(this._instance.id, this._instance);
352
+ this._instance = null;
353
+ }
290
354
 
291
- // 结束绘制,确定实体
292
- _this._playOff(move);
355
+ // 获取绘制的图层
356
+ }, {
357
+ key: "getDrawerLayer",
358
+ value: function getDrawerLayer(id) {
359
+ if (!this._canOperate) return;
360
+ if (!id) return;
361
+ return isString(id) ? this._drawLayers.get(id) : id;
362
+ }
293
363
 
294
- // ActionCallback
295
- if (_this._action) _this._action(_this._operateType.END, move);
296
- if (_this._type === 'point') return;
297
- _this._complete(overrideFunc);
298
- _this._updateTips();
299
- isStartDraw = false;
300
- }, this._operateType.END);
301
- this._events = [startId, moveId, cancelId, endId];
364
+ // 添加完成绘制的图层
365
+ }, {
366
+ key: "setDrawerLayer",
367
+ value: function setDrawerLayer(id, value) {
368
+ if (!this._instance) return;
369
+ this._drawLayers.set(id, value);
302
370
  }
371
+
372
+ // 移除绘制的图层
303
373
  }, {
304
- key: "_complete",
305
- value: function _complete(override) {
306
- // 如果是线和面,则此时将实例添加到Viewer中
307
- if (this._once) this.pause();
308
- this.$Instance = override.call(this, this._operateType.END, this._typeClass.result);
309
- this.$AddedInstance.push(this.$Instance);
310
- this._viewer.canvas.style.cursor = 'default';
374
+ key: "removeDrawerLayer",
375
+ value: function removeDrawerLayer(id) {
376
+ if (!this._canOperate) return;
377
+ var layer = this.getDrawerLayer(id);
378
+ if (layer) {
379
+ var _this$_instance;
380
+ if (layer.id === (this === null || this === void 0 || (_this$_instance = this._instance) === null || _this$_instance === void 0 ? void 0 : _this$_instance.id)) {
381
+ this._instance = null;
382
+ this._status = STATUS.INIT;
383
+ this.getMap().canvas.style.cursor = 'default';
384
+ this._updateTooltip();
385
+ }
386
+ this._drawLayers.delete(layer.id);
387
+ layer.destroy();
388
+ layer = null;
389
+ }
311
390
  }
391
+
392
+ // 获取所有绘制的图层
312
393
  }, {
313
- key: "_isSupport",
314
- value: function _isSupport(type) {
315
- return ['polygon', 'polyline', 'point', 'ellipse', 'rectangle'].includes(type);
394
+ key: "getAllDrawerLayers",
395
+ value: function getAllDrawerLayers() {
396
+ if (!this._canOperate) return;
397
+ return Array.from(this._drawLayers.values());
316
398
  }
399
+
400
+ // 清除所有绘制的图层
317
401
  }, {
318
- key: "reset",
319
- value: function reset() {
320
- var _this$_painter;
321
- this.pause();
322
- this._status = 'INIT';
323
- (_this$_painter = this._painter) === null || _this$_painter === void 0 || _this$_painter.clear();
324
- this.$AddedInstance.map(function (layer) {
325
- layer.remove();
402
+ key: "clearAllDrawerLayers",
403
+ value: function clearAllDrawerLayers() {
404
+ if (!this._canOperate) return;
405
+ this._drawLayers.forEach(function (t) {
406
+ return t.destroy();
326
407
  });
327
- this.$AddedInstance = [];
328
- this._viewer.scene.requestRender();
408
+ this._drawLayers.clear();
329
409
  }
410
+
411
+ // 清除
330
412
  }, {
331
- key: "pause",
332
- value: function pause() {
333
- this._status = 'PAUSE';
334
- this._updateTips();
335
- this._subscriber.removeExternal(this._events);
336
- this._events = [];
337
- this._viewer.canvas.style.cursor = 'default';
413
+ key: "clear",
414
+ value: function clear() {
415
+ if (!this._canOperate) return;
416
+ this.getMap().canvas.style.cursor = 'default';
417
+ this._changeStatus(STATUS.INIT);
418
+ this._updateTooltip();
419
+ this._instance && this._instance.destroy();
420
+ this._instance = null;
421
+ this.clearAllDrawerLayers();
338
422
  }
423
+
424
+ // 销毁
339
425
  }, {
340
426
  key: "destroy",
341
427
  value: function destroy() {
342
- this.reset();
343
- this.mouseTooltip.destroy();
344
- this._subscriber.destroy();
345
- this._status = 'DESTROY';
428
+ if (!this._canOperate) return;
429
+ this._destroyListeners();
430
+ this.clear();
431
+ this.tooltip.destroy();
432
+ this.tooltip = null;
433
+ this.isDestroyed = true;
346
434
  }
347
435
  }]);
348
436
  return Drawer;
349
437
  }();
350
- export { Drawer as default };
438
+ export default Drawer;