deeptwins-engine-3d 0.1.8 → 0.1.11

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 (97) hide show
  1. package/dist/esm/cameraControl/ModelRoamHistory.d.ts +2 -1
  2. package/dist/esm/cameraControl/ModelRoamHistory.js +33 -29
  3. package/dist/esm/cameraControl/ModelRoamRealTime.d.ts +4 -3
  4. package/dist/esm/cameraControl/ModelRoamRealTime.js +26 -22
  5. package/dist/esm/cameraControl/Roam.d.ts +3 -1
  6. package/dist/esm/cameraControl/Roam.js +17 -13
  7. package/dist/esm/cameraControl/Rotate.d.ts +3 -1
  8. package/dist/esm/cameraControl/Rotate.js +29 -25
  9. package/dist/esm/cameraControl/RotateInPlace.d.ts +3 -1
  10. package/dist/esm/cameraControl/RotateInPlace.js +22 -19
  11. package/dist/esm/constant.d.ts +12 -0
  12. package/dist/esm/constant.js +16 -0
  13. package/dist/esm/graphicLayer/BaseEntity.d.ts +0 -1
  14. package/dist/esm/graphicLayer/BaseEntity.js +0 -1
  15. package/dist/esm/graphicLayer/BaseLayer.d.ts +3 -2
  16. package/dist/esm/graphicLayer/BaseLayer.js +73 -41
  17. package/dist/esm/graphicLayer/BasePointPrimitive.d.ts +4 -2
  18. package/dist/esm/graphicLayer/BasePointPrimitive.js +14 -10
  19. package/dist/esm/graphicLayer/BasePrimitive.d.ts +3 -5
  20. package/dist/esm/graphicLayer/BasePrimitive.js +4 -18
  21. package/dist/esm/graphicLayer/BasePrimitiveInstance.d.ts +1 -2
  22. package/dist/esm/graphicLayer/BasePrimitiveInstance.js +0 -1
  23. package/dist/esm/graphicLayer/BaseSource.d.ts +4 -3
  24. package/dist/esm/graphicLayer/BaseSource.js +28 -11
  25. package/dist/esm/graphicLayer/BillboardEntity.js +3 -6
  26. package/dist/esm/graphicLayer/BillboardPrimitive.d.ts +2 -0
  27. package/dist/esm/graphicLayer/BillboardPrimitive.js +29 -5
  28. package/dist/esm/graphicLayer/BoxEntity.js +2 -5
  29. package/dist/esm/graphicLayer/BoxPrimitive.d.ts +2 -2
  30. package/dist/esm/graphicLayer/BoxPrimitive.js +11 -6
  31. package/dist/esm/graphicLayer/BoxPrimitiveInstance.js +4 -6
  32. package/dist/esm/graphicLayer/EllipseEntity.js +2 -5
  33. package/dist/esm/graphicLayer/EllipsePrimitive.d.ts +1 -1
  34. package/dist/esm/graphicLayer/EllipsePrimitive.js +9 -4
  35. package/dist/esm/graphicLayer/EllipsePrimitiveInstance.js +4 -7
  36. package/dist/esm/graphicLayer/EllipsoidEntity.js +2 -5
  37. package/dist/esm/graphicLayer/EllipsoidPrimitive.d.ts +1 -1
  38. package/dist/esm/graphicLayer/EllipsoidPrimitive.js +9 -4
  39. package/dist/esm/graphicLayer/EllipsoidPrimitiveInstance.js +3 -3
  40. package/dist/esm/graphicLayer/GraphicLayerCollection.d.ts +9 -7
  41. package/dist/esm/graphicLayer/GraphicLayerCollection.js +118 -42
  42. package/dist/esm/graphicLayer/HtmlEntity.js +20 -9
  43. package/dist/esm/graphicLayer/LabelEntity.js +2 -5
  44. package/dist/esm/graphicLayer/LabelPrimitive.d.ts +2 -0
  45. package/dist/esm/graphicLayer/LabelPrimitive.js +31 -8
  46. package/dist/esm/graphicLayer/ModelEntity.js +2 -5
  47. package/dist/esm/graphicLayer/ModelPrimitive.d.ts +1 -1
  48. package/dist/esm/graphicLayer/ModelPrimitive.js +2 -1
  49. package/dist/esm/graphicLayer/ModelPrimitiveInstance.js +4 -7
  50. package/dist/esm/graphicLayer/PointEntity.js +2 -5
  51. package/dist/esm/graphicLayer/PointPrimitive.d.ts +2 -0
  52. package/dist/esm/graphicLayer/PointPrimitive.js +29 -5
  53. package/dist/esm/graphicLayer/PolygonEntity.js +4 -7
  54. package/dist/esm/graphicLayer/PolygonPrimitive.d.ts +2 -2
  55. package/dist/esm/graphicLayer/PolygonPrimitive.js +11 -6
  56. package/dist/esm/graphicLayer/PolygonPrimitiveInstance.js +4 -7
  57. package/dist/esm/graphicLayer/PolylineEntity.js +4 -7
  58. package/dist/esm/graphicLayer/PolylinePrimitive.d.ts +1 -1
  59. package/dist/esm/graphicLayer/PolylinePrimitive.js +9 -4
  60. package/dist/esm/graphicLayer/PolylinePrimitiveInstance.js +3 -3
  61. package/dist/esm/graphicLayer/PolylineVolumeEntity.js +3 -5
  62. package/dist/esm/graphicLayer/PolylineVolumePrimitive.d.ts +1 -1
  63. package/dist/esm/graphicLayer/PolylineVolumePrimitive.js +9 -4
  64. package/dist/esm/graphicLayer/PolylineVolumePrimitiveInstance.js +4 -7
  65. package/dist/esm/graphicLayer/WallEntity.js +4 -7
  66. package/dist/esm/graphicLayer/WallPrimitive.d.ts +1 -1
  67. package/dist/esm/graphicLayer/WallPrimitive.js +9 -4
  68. package/dist/esm/graphicLayer/WallPrimitiveInstance.js +4 -7
  69. package/dist/esm/index.js +1 -1
  70. package/dist/esm/map/Event.d.ts +4 -2
  71. package/dist/esm/map/Event.js +57 -32
  72. package/dist/esm/map/Map.d.ts +6 -1
  73. package/dist/esm/map/Map.js +14 -4
  74. package/dist/esm/material/WeatherEffects.d.ts +3 -1
  75. package/dist/esm/material/WeatherEffects.js +11 -6
  76. package/dist/esm/tool/common.d.ts +3 -1
  77. package/dist/esm/tool/common.js +13 -8
  78. package/dist/esm/tool/utils.d.ts +2 -0
  79. package/dist/esm/tool/utils.js +10 -0
  80. package/dist/esm/videoFusion/BaseVideo.d.ts +6 -2
  81. package/dist/esm/videoFusion/BaseVideo.js +48 -19
  82. package/dist/esm/videoFusion/VideoProject.js +16 -10
  83. package/dist/esm/videoFusion/VideoTexture.js +4 -2
  84. package/dist/esm/visualization/Airspace.d.ts +3 -1
  85. package/dist/esm/visualization/Airspace.js +27 -12
  86. package/dist/esm/visualization/BaseFrustum.d.ts +3 -1
  87. package/dist/esm/visualization/BaseFrustum.js +23 -9
  88. package/dist/esm/visualization/BaseHeatmap.d.ts +4 -2
  89. package/dist/esm/visualization/BaseHeatmap.js +22 -12
  90. package/dist/esm/visualization/Frustum.js +6 -6
  91. package/dist/esm/visualization/FrustumWithCamera.js +9 -9
  92. package/dist/esm/visualization/Heatmap2d.js +31 -5
  93. package/dist/esm/visualization/Heatmap3d.js +21 -4
  94. package/dist/esm/visualization/PointCluster.d.ts +3 -1
  95. package/dist/esm/visualization/PointCluster.js +26 -14
  96. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  97. package/package.json +1 -2
@@ -1,7 +1,9 @@
1
+ import { MapContext } from '../map/Map';
1
2
  export default class Event {
2
- private _map;
3
+ private readonly _mapContext;
3
4
  private _eventSubscriptions;
4
- constructor(map: any);
5
+ constructor(mapContext: MapContext);
6
+ getMap(): any;
5
7
  private _getPosition;
6
8
  private _getPickedObject;
7
9
  private _notifySubscribers;
@@ -1,4 +1,6 @@
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; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
5
  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); } }
4
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -8,6 +10,9 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
10
  import * as Cesium from 'deeptwins-cesium';
9
11
  import * as utils from "../tool/utils";
10
12
 
13
+ // 单机延迟
14
+ var CLICK_DELAY = 200;
15
+
11
16
  // 根据事件类型进行处理
12
17
  function dealWithMapType(type, event) {
13
18
  var _obj;
@@ -47,21 +52,26 @@ function dealWithMapType(type, event) {
47
52
  var Event = /*#__PURE__*/function () {
48
53
  // 存储所有事件订阅者
49
54
 
50
- function Event(map) {
55
+ function Event(mapContext) {
51
56
  _classCallCheck(this, Event);
52
- _defineProperty(this, "_map", void 0);
57
+ _defineProperty(this, "_mapContext", void 0);
53
58
  _defineProperty(this, "_eventSubscriptions", new Map());
54
- this._map = map;
59
+ this._mapContext = mapContext;
55
60
  }
56
-
57
- // 获取经纬度位置
58
61
  _createClass(Event, [{
62
+ key: "getMap",
63
+ value: function getMap() {
64
+ return this._mapContext && this._mapContext.getMap();
65
+ }
66
+
67
+ // 获取经纬度位置
68
+ }, {
59
69
  key: "_getPosition",
60
70
  value: function _getPosition(position) {
61
71
  if (!position) return null;
62
72
  try {
63
- var ray = this._map.camera.getPickRay(position);
64
- var cartesian = this._map.scene.globe.pick(ray, this._map.scene);
73
+ var ray = this.getMap().camera.getPickRay(position);
74
+ var cartesian = this.getMap().scene.globe.pick(ray, this.getMap().scene);
65
75
  var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
66
76
  var lng = utils.toDegrees(cartographic.longitude); //经度
67
77
  var lat = utils.toDegrees(cartographic.latitude); //纬度
@@ -81,7 +91,7 @@ var Event = /*#__PURE__*/function () {
81
91
  key: "_getPickedObject",
82
92
  value: function _getPickedObject(position) {
83
93
  if (!position) return null;
84
- var picked = this._map.scene.pick(position);
94
+ var picked = this.getMap().scene.pick(position);
85
95
  var pickedObject = null;
86
96
  if (Cesium.defined(picked)) {
87
97
  pickedObject = picked;
@@ -109,40 +119,55 @@ var Event = /*#__PURE__*/function () {
109
119
  value: function _subscribe(type, callback) {
110
120
  var _this = this;
111
121
  var self = this;
122
+ // 订阅器
123
+ var subscriber;
112
124
  // 如果没有注册过该类型的事件处理器,则创建一个
113
125
  if (!this._eventSubscriptions.has(type)) {
114
126
  // 注册事件
115
- var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
116
- handler.setInputAction(function (e) {
117
- // 发布订阅
118
- _this._notifySubscribers(type, e);
119
- }, type);
127
+ var handler = new Cesium.ScreenSpaceEventHandler(this.getMap().scene.canvas);
128
+ // 单击特殊处理
129
+ if (type === Cesium.ScreenSpaceEventType.LEFT_CLICK) {
130
+ var lastClickTime = 0;
131
+ handler.setInputAction(function (e) {
132
+ var now = performance.now();
133
+ if (now - lastClickTime >= CLICK_DELAY) {
134
+ _this._notifySubscribers(type, e);
135
+ lastClickTime = now;
136
+ }
137
+ }, type);
138
+ } else {
139
+ handler.setInputAction(function (e) {
140
+ // 发布订阅
141
+ _this._notifySubscribers(type, e);
142
+ }, type);
143
+ }
120
144
  handler.__proto__.off = function () {
121
145
  handler.removeInputAction(type);
122
146
  };
123
147
  // 订阅器
124
- var subscriber = {
148
+ subscriber = {
125
149
  handler: handler,
126
150
  callbacks: new Set([callback])
127
151
  };
128
- subscriber.off = function () {
129
- subscriber.callbacks.delete(callback);
130
- // 如果没有订阅者了,移除处理器
131
- if (subscriber.callbacks.size === 0) {
132
- var _subscriber$handler;
133
- (_subscriber$handler = subscriber.handler) === null || _subscriber$handler === void 0 || _subscriber$handler.off();
134
- self._eventSubscriptions.delete(type);
135
- }
136
- };
137
152
  this._eventSubscriptions.set(type, subscriber);
138
- return subscriber;
139
153
  } else {
140
154
  // 订阅器
141
- var _subscriber = this._eventSubscriptions.get(type);
155
+ subscriber = this._eventSubscriptions.get(type);
142
156
  // 订阅列表
143
- _subscriber.callbacks.add(callback);
144
- return _subscriber;
157
+ subscriber.callbacks.add(callback);
145
158
  }
159
+ var off = function off() {
160
+ subscriber.callbacks.delete(callback);
161
+ if (subscriber.callbacks.size === 0) {
162
+ var _subscriber$handler;
163
+ // 如果没有订阅者了,移除处理器
164
+ (_subscriber$handler = subscriber.handler) === null || _subscriber$handler === void 0 || _subscriber$handler.off();
165
+ self._eventSubscriptions.delete(type);
166
+ }
167
+ };
168
+ return _objectSpread(_objectSpread({}, subscriber), {}, {
169
+ off: off
170
+ });
146
171
  }
147
172
 
148
173
  // 监听地图事件
@@ -170,12 +195,12 @@ var Event = /*#__PURE__*/function () {
170
195
  var handler = function handler(e) {
171
196
  event({
172
197
  original: e,
173
- position: _this3._map.getCameraView()
198
+ position: _this3.getMap().getCameraView()
174
199
  });
175
200
  };
176
- this._map.camera[type].addEventListener(handler);
201
+ this.getMap().camera[type].addEventListener(handler);
177
202
  handler.__proto__.off = function () {
178
- self._map.camera[type].removeEventListener(this);
203
+ self.getMap().camera[type].removeEventListener(this);
179
204
  };
180
205
  return handler;
181
206
  }
@@ -188,9 +213,9 @@ var Event = /*#__PURE__*/function () {
188
213
  var handler = function handler(e) {
189
214
  event(e);
190
215
  };
191
- this._map.scene[type].addEventListener(handler);
216
+ this.getMap().scene[type].addEventListener(handler);
192
217
  handler.__proto__.off = function () {
193
- self._map.scene[type].removeEventListener(this);
218
+ self.getMap().scene[type].removeEventListener(this);
194
219
  };
195
220
  return handler;
196
221
  }
@@ -1,5 +1,9 @@
1
1
  import * as Cesium from 'deeptwins-cesium';
2
- export default class Map extends Cesium.Viewer {
2
+ export interface MapContext {
3
+ getMap: any;
4
+ }
5
+ export default class Map extends Cesium.Viewer implements MapContext {
6
+ private readonly _mapContext;
3
7
  configOptions: any;
4
8
  graphicLayerCollection: any;
5
9
  showGroundSkyBox: boolean;
@@ -9,6 +13,7 @@ export default class Map extends Cesium.Viewer {
9
13
  private _event;
10
14
  private _eventTrick;
11
15
  constructor(container: any, options: any);
16
+ getMap(): this;
12
17
  private _createHtmlContainer;
13
18
  private _createHeatMapContainer;
14
19
  private _createVideoContainer;
@@ -60,6 +60,8 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
60
60
  }
61
61
  Cesium.Ion.defaultAccessToken = constant.DEFAULT_ION;
62
62
  _this = _super.call(this, container, currOptions);
63
+ // 创建一个符合 MapContext 接口的对象
64
+ _defineProperty(_assertThisInitialized(_this), "_mapContext", void 0);
63
65
  // 配置
64
66
  _defineProperty(_assertThisInitialized(_this), "configOptions", null);
65
67
  // 绘制Graphic的集合
@@ -82,6 +84,9 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
82
84
  common.removeYjIcon();
83
85
  return _this._yunjing;
84
86
  });
87
+ _this._mapContext = {
88
+ getMap: _this.getMap.bind(_assertThisInitialized(_this))
89
+ };
85
90
  _this.configOptions = merge(constant.DEFAULT_VIEW_CONFIG(), options);
86
91
  _this.setConfig(_this.configOptions);
87
92
  if (deepTwins) {
@@ -95,9 +100,9 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
95
100
  _this.setCameraView(camera, {
96
101
  duration: 0
97
102
  });
98
- _this.graphicLayerCollection = new GraphicLayerCollection(_assertThisInitialized(_this));
103
+ _this.graphicLayerCollection = new GraphicLayerCollection(_this._mapContext);
99
104
  // 初始化事件
100
- _this._event = new Event(_assertThisInitialized(_this));
105
+ _this._event = new Event(_this._mapContext);
101
106
  // 添加position
102
107
  if (utils.getElCss(_this.container, 'position') === 'static') {
103
108
  _this.container.style.position = 'relative';
@@ -112,9 +117,14 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
112
117
  _this._onDefaultEvents();
113
118
  return _this;
114
119
  }
115
-
116
- // 创建html的容器
117
120
  _createClass(Map, [{
121
+ key: "getMap",
122
+ value: function getMap() {
123
+ return this;
124
+ }
125
+
126
+ // 创建html的容器
127
+ }, {
118
128
  key: "_createHtmlContainer",
119
129
  value: function _createHtmlContainer() {
120
130
  var el = document.createElement('div');
@@ -1,9 +1,11 @@
1
+ import { MapContext } from '../map/Map';
1
2
  export default class WeatherEffects {
3
+ _mapContext: MapContext | undefined;
2
4
  type: string;
3
5
  options: any;
4
6
  stage: any;
5
- private _map;
6
7
  constructor(type: string, options?: any);
8
+ getMap(): any;
7
9
  remove(): void;
8
10
  addToMap(map: any): void;
9
11
  setEffect(options: any): void;
@@ -19,10 +19,10 @@ var WeatherEffects = /*#__PURE__*/function () {
19
19
  function WeatherEffects(type) {
20
20
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21
21
  _classCallCheck(this, WeatherEffects);
22
+ _defineProperty(this, "_mapContext", void 0);
22
23
  _defineProperty(this, "type", void 0);
23
24
  _defineProperty(this, "options", void 0);
24
25
  _defineProperty(this, "stage", void 0);
25
- _defineProperty(this, "_map", void 0);
26
26
  this.type = type;
27
27
  this.options = options;
28
28
  switch (this.type) {
@@ -37,20 +37,25 @@ var WeatherEffects = /*#__PURE__*/function () {
37
37
  break;
38
38
  }
39
39
  }
40
-
41
- // 移除
42
40
  _createClass(WeatherEffects, [{
41
+ key: "getMap",
42
+ value: function getMap() {
43
+ return this._mapContext && this._mapContext.getMap();
44
+ }
45
+
46
+ // 移除
47
+ }, {
43
48
  key: "remove",
44
49
  value: function remove() {
45
- if (!this._map) return;
46
- this._map.scene.postProcessStages.remove(this.stage);
50
+ if (!this.getMap()) return;
51
+ this.getMap().scene.postProcessStages.remove(this.stage);
47
52
  }
48
53
 
49
54
  // 添加到地图
50
55
  }, {
51
56
  key: "addToMap",
52
57
  value: function addToMap(map) {
53
- this._map = map;
58
+ this._mapContext = map._mapContext;
54
59
  map.scene.postProcessStages.add(this.stage);
55
60
  }
56
61
 
@@ -1,5 +1,6 @@
1
1
  import * as Cesium from 'deeptwins-cesium';
2
2
  import { Cartesian2, Cartesian3 } from 'deeptwins-cesium';
3
+ import { MapContext } from '../map/Map';
3
4
  export declare const removeYjIcon: () => void;
4
5
  export declare const lineClampToGroundSplit: ({ map, pos1, pos2, splitNum, }: {
5
6
  map: any;
@@ -21,8 +22,9 @@ export declare class ShapeSection {
21
22
  static triangleSection(base: number, height: number): Cesium.Cartesian2[];
22
23
  }
23
24
  export declare class ClampToGround {
24
- private _map;
25
+ _mapContext: MapContext | undefined;
25
26
  constructor(map: any);
27
+ getMap(): any;
26
28
  private _cartesianToCartographic;
27
29
  private _cartographicToCartesian;
28
30
  private _cartographicToDegrees;
@@ -123,13 +123,18 @@ export var ShapeSection = /*#__PURE__*/function () {
123
123
  export var ClampToGround = /*#__PURE__*/function () {
124
124
  function ClampToGround(map) {
125
125
  _classCallCheck(this, ClampToGround);
126
- _defineProperty(this, "_map", void 0);
127
- this._map = map;
126
+ _defineProperty(this, "_mapContext", void 0);
127
+ this._mapContext = map._mapContext;
128
128
  }
129
129
  _createClass(ClampToGround, [{
130
+ key: "getMap",
131
+ value: function getMap() {
132
+ return this._mapContext && this._mapContext.getMap();
133
+ }
134
+ }, {
130
135
  key: "_cartesianToCartographic",
131
136
  value: function _cartesianToCartographic(cartesian3) {
132
- var ellipsoid = this._map.scene.globe.ellipsoid;
137
+ var ellipsoid = this.getMap().scene.globe.ellipsoid;
133
138
  try {
134
139
  return ellipsoid.cartesianToCartographic(cartesian3);
135
140
  } catch (e) {
@@ -175,7 +180,7 @@ export var ClampToGround = /*#__PURE__*/function () {
175
180
  while (1) switch (_context.prev = _context.next) {
176
181
  case 0:
177
182
  try {
178
- promise = _this._map.scene.clampToHeightMostDetailed(data);
183
+ promise = _this.getMap().scene.clampToHeightMostDetailed(data);
179
184
  promise.then(function (res) {
180
185
  return resolve(res);
181
186
  });
@@ -199,7 +204,7 @@ export var ClampToGround = /*#__PURE__*/function () {
199
204
  var cartographic = _this._cartesianToCartographic(cartesian);
200
205
  cartographic && positions.push(cartographic);
201
206
  });
202
- var terrain = this._map.terrainProvider;
207
+ var terrain = this.getMap().terrainProvider;
203
208
  return new Promise( /*#__PURE__*/function () {
204
209
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
205
210
  var promise;
@@ -264,7 +269,7 @@ export var ClampToGround = /*#__PURE__*/function () {
264
269
  while (1) switch (_context3.prev = _context3.next) {
265
270
  case 0:
266
271
  try {
267
- promise = _this2._map.scene.clampToHeightMostDetailed(data);
272
+ promise = _this2.getMap().scene.clampToHeightMostDetailed(data);
268
273
  promise.then(function (res) {
269
274
  resolve({
270
275
  positions: res,
@@ -297,7 +302,7 @@ export var ClampToGround = /*#__PURE__*/function () {
297
302
  var cartographic = _this2._cartesianToCartographic(cartesian);
298
303
  cartographic && positions.push(cartographic);
299
304
  });
300
- var terrain = this._map.terrainProvider;
305
+ var terrain = this.getMap().terrainProvider;
301
306
  return new Promise( /*#__PURE__*/function () {
302
307
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(resolve) {
303
308
  var promise;
@@ -365,7 +370,7 @@ export var ClampToGround = /*#__PURE__*/function () {
365
370
  case 0:
366
371
  geoJson = this._translateSource(JSON.parse(JSON.stringify(data)));
367
372
  _context5.next = 3;
368
- return BaseSource.geoJsonToClampCartesian3Array(geoJson, type, this._map);
373
+ return BaseSource.geoJsonToClampCartesian3Array(geoJson, type, this.getMap());
369
374
  case 3:
370
375
  _context5.t0 = _context5.sent;
371
376
  return _context5.abrupt("return", {
@@ -44,3 +44,5 @@ export declare const getHeightCompensatedScale: (map: Cesium.Viewer, entityHeigh
44
44
  transitionHeight?: number;
45
45
  }) => number;
46
46
  export declare function calculateLength(positions: any[]): number;
47
+ export declare function warn(message: string): void;
48
+ export declare function error(message: string): void;
@@ -321,4 +321,14 @@ export function calculateLength(positions) {
321
321
  length += Cesium.Cartesian3.distance(positions[i - 1], positions[i]);
322
322
  }
323
323
  return length;
324
+ }
325
+
326
+ // 警告
327
+ export function warn(message) {
328
+ console.warn("[DeepTwinsEngine3d warn]: ".concat(message));
329
+ }
330
+
331
+ // 异常
332
+ export function error(message) {
333
+ console.error("[DeepTwinsEngine3d error]: ".concat(message));
324
334
  }
@@ -1,5 +1,6 @@
1
+ import { MapContext } from '../map/Map';
1
2
  export default class BaseVideo {
2
- _map: any;
3
+ _mapContext: MapContext | undefined;
3
4
  options: any;
4
5
  videoElement: any;
5
6
  videoPolygonLayer: any;
@@ -9,9 +10,12 @@ export default class BaseVideo {
9
10
  synchronizer: any;
10
11
  hls: any;
11
12
  private onErrorFun;
13
+ private _maskImage;
12
14
  constructor(options: any);
13
- _canOperate(): void;
15
+ getMap(): any;
16
+ _canOperate(): boolean;
14
17
  private _init;
18
+ private _initMaskImage;
15
19
  _drawCanvas(options: any): HTMLCanvasElement;
16
20
  show(isShow: boolean): void;
17
21
  play(): void;
@@ -16,7 +16,7 @@ import * as utils from "../tool/utils";
16
16
  var BaseVideo = /*#__PURE__*/function () {
17
17
  function BaseVideo(options) {
18
18
  _classCallCheck(this, BaseVideo);
19
- _defineProperty(this, "_map", void 0);
19
+ _defineProperty(this, "_mapContext", void 0);
20
20
  _defineProperty(this, "options", void 0);
21
21
  _defineProperty(this, "videoElement", void 0);
22
22
  _defineProperty(this, "videoPolygonLayer", void 0);
@@ -26,6 +26,7 @@ var BaseVideo = /*#__PURE__*/function () {
26
26
  _defineProperty(this, "synchronizer", null);
27
27
  _defineProperty(this, "hls", void 0);
28
28
  _defineProperty(this, "onErrorFun", void 0);
29
+ _defineProperty(this, "_maskImage", null);
29
30
  this.options = options;
30
31
  if (options.video) {
31
32
  this.videoType = 'video';
@@ -34,15 +35,23 @@ var BaseVideo = /*#__PURE__*/function () {
34
35
  this.videoType = 'hls';
35
36
  }
36
37
  this._init();
38
+ this._initMaskImage();
37
39
  }
38
-
39
- // 是否能进行操作
40
40
  _createClass(BaseVideo, [{
41
+ key: "getMap",
42
+ value: function getMap() {
43
+ return this._mapContext && this._mapContext.getMap();
44
+ }
45
+
46
+ // 是否能进行操作
47
+ }, {
41
48
  key: "_canOperate",
42
49
  value: function _canOperate() {
43
50
  if (this.isDestroyed) {
44
- throw new Error('BaseLayer实例已销毁');
51
+ utils.error('video实例已销毁');
52
+ return false;
45
53
  }
54
+ return true;
46
55
  }
47
56
  }, {
48
57
  key: "_init",
@@ -116,6 +125,16 @@ var BaseVideo = /*#__PURE__*/function () {
116
125
  }
117
126
  }
118
127
 
128
+ // 添加初始化遮罩图片的方法
129
+ }, {
130
+ key: "_initMaskImage",
131
+ value: function _initMaskImage() {
132
+ if (!this._maskImage) {
133
+ this._maskImage = new Image();
134
+ this._maskImage.src = utils.getDeepTwinsFile('Image/video-mask.png');
135
+ }
136
+ }
137
+
119
138
  // 绘制投影
120
139
  }, {
121
140
  key: "_drawCanvas",
@@ -128,12 +147,10 @@ var BaseVideo = /*#__PURE__*/function () {
128
147
  var ctx = canvas.getContext('2d');
129
148
  // 1. 叠加当前视频帧
130
149
  ctx.globalAlpha = 1.0; // 确保视频帧不透明
131
- ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);
150
+ ctx.drawImage(this.videoElement, 0, 0, width, height);
132
151
  // 2. 应用羽化遮罩
133
152
  ctx.globalCompositeOperation = 'destination-in'; // 使用遮罩影响透明度
134
- var img = new Image();
135
- img.src = utils.getDeepTwinsFile('Image/video-mask.png');
136
- ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
153
+ ctx.drawImage(this._maskImage, 0, 0, width, height);
137
154
  ctx.globalCompositeOperation = 'source-over'; // 还原默认混合模式
138
155
  return canvas;
139
156
  }
@@ -142,7 +159,9 @@ var BaseVideo = /*#__PURE__*/function () {
142
159
  }, {
143
160
  key: "show",
144
161
  value: function show(isShow) {
145
- this._canOperate();
162
+ if (!this._canOperate()) {
163
+ return;
164
+ }
146
165
  this.videoPolygonLayer && this.videoPolygonLayer.show(isShow);
147
166
  isShow ? this.play() : this.pause();
148
167
  }
@@ -152,7 +171,9 @@ var BaseVideo = /*#__PURE__*/function () {
152
171
  key: "play",
153
172
  value: function play() {
154
173
  var _this2 = this;
155
- this._canOperate();
174
+ if (!this._canOperate()) {
175
+ return;
176
+ }
156
177
  this.status = 'PLAYING';
157
178
  if (this.videoType === 'video') {
158
179
  var promise = this.videoElement.play();
@@ -172,15 +193,15 @@ var BaseVideo = /*#__PURE__*/function () {
172
193
  // 暂停后继续播放
173
194
  if (this.synchronizer && this.videoType === 'hls') {
174
195
  this.hls.startLoad();
175
- this._map.clock.shouldAnimate = true;
196
+ this.getMap().clock.shouldAnimate = true;
176
197
  }
177
198
  // 开始播放
178
199
  if (!this.synchronizer && this.videoType === 'hls') {
179
200
  this.synchronizer = new Cesium.VideoSynchronizer({
180
- clock: this._map.clock,
201
+ clock: this.getMap().clock,
181
202
  element: this.videoElement
182
203
  });
183
- this._map.clock.shouldAnimate = true;
204
+ this.getMap().clock.shouldAnimate = true;
184
205
  var _promise = this.videoElement.play();
185
206
  if (_promise) {
186
207
  _promise.catch(function (e) {
@@ -203,11 +224,13 @@ var BaseVideo = /*#__PURE__*/function () {
203
224
  }, {
204
225
  key: "pause",
205
226
  value: function pause() {
206
- this._canOperate();
227
+ if (!this._canOperate()) {
228
+ return;
229
+ }
207
230
  this.status = 'PAUSE';
208
231
  if (this.videoType === 'hls') {
209
232
  this.hls.stopLoad();
210
- this._map.clock.shouldAnimate = false;
233
+ this.getMap().clock.shouldAnimate = false;
211
234
  }
212
235
  this.videoElement.pause();
213
236
  }
@@ -217,7 +240,9 @@ var BaseVideo = /*#__PURE__*/function () {
217
240
  key: "setPlaybackRate",
218
241
  value: function setPlaybackRate() {
219
242
  var playbackRate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
220
- this._canOperate();
243
+ if (!this._canOperate()) {
244
+ return;
245
+ }
221
246
  if (this.videoType === 'video') {
222
247
  this.videoElement.playbackRate = playbackRate;
223
248
  }
@@ -227,7 +252,9 @@ var BaseVideo = /*#__PURE__*/function () {
227
252
  }, {
228
253
  key: "rePlay",
229
254
  value: function rePlay() {
230
- this._canOperate();
255
+ if (!this._canOperate()) {
256
+ return;
257
+ }
231
258
  if (this.videoType === 'video') {
232
259
  this.videoElement.currentTime = 0;
233
260
  this.play();
@@ -238,13 +265,15 @@ var BaseVideo = /*#__PURE__*/function () {
238
265
  }, {
239
266
  key: "destroy",
240
267
  value: function destroy() {
241
- this._canOperate();
268
+ if (!this._canOperate()) {
269
+ return;
270
+ }
242
271
  this.status = 'PREPARE';
243
272
  this.isDestroyed = true;
244
273
  if (this.videoType === 'hls') {
245
274
  this.synchronizer && this.synchronizer.destroy();
246
275
  this.hls && this.hls.destroyed();
247
- this._map.clock.shouldAnimate = false;
276
+ this.getMap().clock.shouldAnimate = false;
248
277
  }
249
278
  this.videoElement.remove();
250
279
  this.videoPolygonLayer.remove();
@@ -38,8 +38,10 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
38
38
  key: "addToMap",
39
39
  value: function addToMap(map) {
40
40
  var _this2 = this;
41
- this._canOperate();
42
- this._map = map;
41
+ if (!this._canOperate()) {
42
+ return;
43
+ }
44
+ this._mapContext = map._mapContext;
43
45
  var videoOptions;
44
46
  if (this.videoType === 'video') {
45
47
  this.options.video.autoPlay && this.play();
@@ -130,7 +132,9 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
130
132
  }, {
131
133
  key: "show",
132
134
  value: function show(isShow) {
133
- this._canOperate();
135
+ if (!this._canOperate()) {
136
+ return;
137
+ }
134
138
  this.frustumLineLayer && this.frustumLineLayer.show(isShow);
135
139
  _get(_getPrototypeOf(VideoProject.prototype), "show", this).call(this, isShow);
136
140
  }
@@ -142,7 +146,7 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
142
146
  var _this3 = this,
143
147
  _this$options$style3;
144
148
  var draw = function draw(geoJson) {
145
- _this3.frustumLineLayer = _this3._map.addGraphicLayer(geoJson, {
149
+ _this3.frustumLineLayer = _this3.getMap().addGraphicLayer(geoJson, {
146
150
  type: 'polylineP',
147
151
  style: {
148
152
  color: '#ffffff'
@@ -152,7 +156,7 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
152
156
  var linePoints = [];
153
157
  // 是否计算贴地
154
158
  if ((_this$options$style3 = this.options.style) !== null && _this$options$style3 !== void 0 && _this$options$style3.clampToGround && this.type === 'projection') {
155
- var clampToGround = new ClampToGround(this._map);
159
+ var clampToGround = new ClampToGround(this.getMap());
156
160
  var c3arr = utils.lngLatAltArrayToCartesian3Array(interPoints);
157
161
  clampToGround.getLngLatAltArrToHeight(c3arr, 'terrain').then(function (result) {
158
162
  result.coordinates.forEach(function (point) {
@@ -193,14 +197,14 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
193
197
  var startPoint = utils.lngLatAltToCartographic(start[0], start[1], start[2]);
194
198
  var endPoint = utils.lngLatAltToCartographic(end[0], end[1], end[2]);
195
199
  // 创建起点和终点的笛卡尔坐标
196
- var startCartesian = this._map.scene.globe.ellipsoid.cartographicToCartesian(startPoint);
197
- var endCartesian = this._map.scene.globe.ellipsoid.cartographicToCartesian(endPoint);
200
+ var startCartesian = this.getMap().scene.globe.ellipsoid.cartographicToCartesian(startPoint);
201
+ var endCartesian = this.getMap().scene.globe.ellipsoid.cartographicToCartesian(endPoint);
198
202
  // 通过原点和方向 创建射线
199
203
  var direction = Cesium.Cartesian3.subtract(endCartesian, startCartesian, new Cesium.Cartesian3());
200
204
  var ray = new Cesium.Ray(startCartesian, direction);
201
205
 
202
206
  // 计算射线与地球表面的交点
203
- var result = Cesium.IntersectionTests.rayEllipsoid(ray, this._map.scene.globe.ellipsoid);
207
+ var result = Cesium.IntersectionTests.rayEllipsoid(ray, this.getMap().scene.globe.ellipsoid);
204
208
  if (result && result.start !== result.stop) {
205
209
  // 计算交点的位置
206
210
  var intersectionPoint = Cesium.Ray.getPoint(ray, result.start);
@@ -217,10 +221,12 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
217
221
  }, {
218
222
  key: "destroy",
219
223
  value: function destroy() {
220
- this._canOperate();
224
+ if (!this._canOperate()) {
225
+ return;
226
+ }
221
227
  this.frustum && this.frustum.destroy();
222
228
  this.frustum = null;
223
- this.frustumLineLayer && this._map.removeGraphicSource(this.frustumLineLayer.id);
229
+ this.frustumLineLayer && this.getMap().removeGraphicSource(this.frustumLineLayer.id);
224
230
  this.frustumLineLayer = null;
225
231
  _get(_getPrototypeOf(VideoProject.prototype), "destroy", this).call(this);
226
232
  }