deeptwins-engine-3d 0.1.5 → 0.1.6

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.
@@ -22,6 +22,7 @@ export default class ModelRoamRealTime {
22
22
  private _stepAccumulator;
23
23
  private _frameCount;
24
24
  private _fps;
25
+ currentPos: any;
25
26
  private receivedPositions;
26
27
  private completedSegments;
27
28
  private currentSegment;
@@ -62,6 +62,8 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
62
62
  _defineProperty(this, "_stepAccumulator", 0);
63
63
  _defineProperty(this, "_frameCount", 0);
64
64
  _defineProperty(this, "_fps", 'N/A');
65
+ // 当前位置
66
+ _defineProperty(this, "currentPos", null);
65
67
  // 接收到的原始位置数据
66
68
  _defineProperty(this, "receivedPositions", []);
67
69
  // 已完成飞行的路径段
@@ -131,12 +133,12 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
131
133
  _this._stepAccumulator += 1;
132
134
  return;
133
135
  }
134
- var currentPos = _this.currentSegment.interpolatedPoints[_this.currentPointIndex];
136
+ _this.currentPos = _this.currentSegment.interpolatedPoints[_this.currentPointIndex];
135
137
 
136
138
  // 计算朝向
137
139
  if (_this.currentPointIndex > 0) {
138
140
  var prevPos = _this.currentSegment.interpolatedPoints[_this.currentPointIndex - 1];
139
- _this.getHeading(prevPos, currentPos);
141
+ _this.getHeading(prevPos, _this.currentPos);
140
142
  }
141
143
 
142
144
  // 更新朝向
@@ -151,12 +153,12 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
151
153
  // 更新模型位置
152
154
  if (_this.modelLayer) {
153
155
  // 只有位置真正发生变化时才更新矩阵
154
- _this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(currentPos, _this.hpRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'));
156
+ _this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(_this.currentPos, _this.hpRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'));
155
157
  _this.modelLayer.modelMatrix = _this.modelMatrix;
156
158
 
157
159
  // 调用位置更新回调
158
160
  if (_this._onPositionUpdate) {
159
- var cartographic = Cesium.Cartographic.fromCartesian(currentPos);
161
+ var cartographic = Cesium.Cartographic.fromCartesian(_this.currentPos);
160
162
  _this._onPositionUpdate({
161
163
  lng: Cesium.Math.toDegrees(cartographic.longitude),
162
164
  lat: Cesium.Math.toDegrees(cartographic.latitude),
@@ -221,6 +223,7 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
221
223
  // 如果是第一次接收数据,初始化模型
222
224
  if (this.receivedPositions.length === 0) {
223
225
  this.receivedPositions.push(newPosition);
226
+ this.currentPos = Cesium.Cartesian3.fromDegrees(newPosition.lng, newPosition.lat, newPosition.alt);
224
227
  this.initModel(newPosition);
225
228
  if (this._onPositionUpdate) {
226
229
  this._onPositionUpdate({
@@ -670,14 +673,13 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
670
673
  }, {
671
674
  key: "updateCameraView",
672
675
  value: function updateCameraView() {
673
- if (!this.modelLayer || !this.currentSegment) {
676
+ if (!this.modelLayer && this.currentPos) {
674
677
  return;
675
678
  }
676
- var position = this.currentPointIndex >= this.currentSegment.interpolatedPoints.length ? this.currentSegment.interpolatedPoints[this.currentSegment.interpolatedPoints.length - 1] : this.currentSegment.interpolatedPoints[this.currentPointIndex];
677
679
  if (this.follow === 'first') {
678
- this.updateFirstPersonView(position);
680
+ this.updateFirstPersonView(this.currentPos);
679
681
  } else if (this.follow === 'third') {
680
- this.updateThirdPersonView(position);
682
+ this.updateThirdPersonView(this.currentPos);
681
683
  }
682
684
  }
683
685
 
@@ -16,7 +16,6 @@ export declare class DeepTwinsEngine3D {
16
16
  static RotateInPlace: any;
17
17
  static ModelRoamHistory: any;
18
18
  static ModelRoamRealTime: any;
19
- static ModelRoamUpDate: any;
20
19
  static TimerInterval: any;
21
20
  static ShapeSection: any;
22
21
  static ClampToGround: any;
package/dist/esm/index.js CHANGED
@@ -9,7 +9,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
9
9
  import * as Cesium from 'deeptwins-cesium';
10
10
  import ModelRoamHistory from "./cameraControl/ModelRoamHistory";
11
11
  import ModelRoamRealTime from "./cameraControl/ModelRoamRealTime";
12
- import ModelRoamUpDate from "./cameraControl/ModelRoamUpDate";
13
12
  import Roam from "./cameraControl/Roam";
14
13
  import Rotate from "./cameraControl/Rotate";
15
14
  import RotateInPlace from "./cameraControl/RotateInPlace";
@@ -48,7 +47,7 @@ loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
48
47
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
49
48
  _classCallCheck(this, DeepTwinsEngine3D);
50
49
  });
51
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.5");
50
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.6");
52
51
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
53
52
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
54
53
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -64,7 +63,6 @@ _defineProperty(DeepTwinsEngine3D, "Roam", Roam);
64
63
  _defineProperty(DeepTwinsEngine3D, "RotateInPlace", RotateInPlace);
65
64
  _defineProperty(DeepTwinsEngine3D, "ModelRoamHistory", ModelRoamHistory);
66
65
  _defineProperty(DeepTwinsEngine3D, "ModelRoamRealTime", ModelRoamRealTime);
67
- _defineProperty(DeepTwinsEngine3D, "ModelRoamUpDate", ModelRoamUpDate);
68
66
  _defineProperty(DeepTwinsEngine3D, "TimerInterval", TimerInterval);
69
67
  _defineProperty(DeepTwinsEngine3D, "ShapeSection", ShapeSection);
70
68
  _defineProperty(DeepTwinsEngine3D, "ClampToGround", ClampToGround);
@@ -1,8 +1,11 @@
1
1
  export default class Event {
2
2
  private _map;
3
+ private _eventSubscriptions;
3
4
  constructor(map: any);
4
5
  private _getPosition;
5
6
  private _getPickedObject;
7
+ private _notifySubscribers;
8
+ private _subscribe;
6
9
  listenToMap(type: any, event: any): any;
7
10
  listenToCamera(type: any, event: any): any;
8
11
  listenToScene(type: any, event: any): any;
@@ -45,9 +45,12 @@ function dealWithMapType(type, event) {
45
45
  return obj[type];
46
46
  }
47
47
  var Event = /*#__PURE__*/function () {
48
+ // 存储所有事件订阅者
49
+
48
50
  function Event(map) {
49
51
  _classCallCheck(this, Event);
50
52
  _defineProperty(this, "_map", void 0);
53
+ _defineProperty(this, "_eventSubscriptions", new Map());
51
54
  this._map = map;
52
55
  }
53
56
 
@@ -86,37 +89,88 @@ var Event = /*#__PURE__*/function () {
86
89
  return pickedObject;
87
90
  }
88
91
 
92
+ // 发布
93
+ }, {
94
+ key: "_notifySubscribers",
95
+ value: function _notifySubscribers(type, e) {
96
+ if (this._eventSubscriptions.has(type)) {
97
+ var _subscriber$callbacks;
98
+ // 订阅器
99
+ var subscriber = this._eventSubscriptions.get(type);
100
+ (_subscriber$callbacks = subscriber.callbacks) === null || _subscriber$callbacks === void 0 || _subscriber$callbacks.forEach(function (callback) {
101
+ return callback(e);
102
+ });
103
+ }
104
+ }
105
+
106
+ // 订阅
107
+ }, {
108
+ key: "_subscribe",
109
+ value: function _subscribe(type, callback) {
110
+ var _this = this;
111
+ var self = this;
112
+ // 如果没有注册过该类型的事件处理器,则创建一个
113
+ if (!this._eventSubscriptions.has(type)) {
114
+ // 注册事件
115
+ var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
116
+ handler.setInputAction(function (e) {
117
+ // 发布订阅
118
+ _this._notifySubscribers(type, e);
119
+ }, type);
120
+ handler.__proto__.off = function () {
121
+ handler.removeInputAction(type);
122
+ };
123
+ // 订阅器
124
+ var subscriber = {
125
+ handler: handler,
126
+ callbacks: new Set([callback])
127
+ };
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
+ this._eventSubscriptions.set(type, subscriber);
138
+ return subscriber;
139
+ } else {
140
+ // 订阅器
141
+ var _subscriber = this._eventSubscriptions.get(type);
142
+ // 订阅列表
143
+ _subscriber.callbacks.add(callback);
144
+ return _subscriber;
145
+ }
146
+ }
147
+
89
148
  // 监听地图事件
90
149
  }, {
91
150
  key: "listenToMap",
92
151
  value: function listenToMap(type, event) {
93
- var _this = this;
94
- var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
95
- handler.setInputAction(function (e) {
152
+ var _this2 = this;
153
+ return this._subscribe(type, function (e) {
96
154
  var _ref = dealWithMapType(type, e) || {},
97
155
  position = _ref.position;
98
156
  event({
99
- position: _this._getPosition(position),
157
+ position: _this2._getPosition(position),
100
158
  original: e,
101
- pickedObject: _this._getPickedObject(position)
159
+ pickedObject: _this2._getPickedObject(position)
102
160
  });
103
- }, type);
104
- handler.__proto__.off = function () {
105
- handler.removeInputAction(type);
106
- };
107
- return handler;
161
+ });
108
162
  }
109
163
 
110
164
  // 监听镜头事件
111
165
  }, {
112
166
  key: "listenToCamera",
113
167
  value: function listenToCamera(type, event) {
114
- var _this2 = this;
168
+ var _this3 = this;
115
169
  var self = this;
116
170
  var handler = function handler(e) {
117
171
  event({
118
172
  original: e,
119
- position: _this2._map.getCameraView()
173
+ position: _this3._map.getCameraView()
120
174
  });
121
175
  };
122
176
  this._map.camera[type].addEventListener(handler);
@@ -145,24 +199,23 @@ var Event = /*#__PURE__*/function () {
145
199
  }, {
146
200
  key: "listenToLayer",
147
201
  value: function listenToLayer(type, event, layer) {
148
- var _this3 = this;
149
- var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
202
+ var _this4 = this;
150
203
  var isHoverLayer = null;
151
204
  var toLeave = function toLeave(e, position) {
152
205
  if (isHoverLayer && type === Cesium.ScreenSpaceEventType.MOUSE_MOVE) {
153
206
  event({
154
207
  original: e,
155
- position: _this3._getPosition(position),
208
+ position: _this4._getPosition(position),
156
209
  layer: isHoverLayer,
157
210
  mouseType: 'mouseLeave'
158
211
  });
159
212
  isHoverLayer = null;
160
213
  }
161
214
  };
162
- handler.setInputAction(function (e) {
215
+ return this._subscribe(type, function (e) {
163
216
  var _ref2 = dealWithMapType(type, e) || {},
164
217
  position = _ref2.position;
165
- var pickedObject = _this3._getPickedObject(position);
218
+ var pickedObject = _this4._getPickedObject(position);
166
219
  if (pickedObject) {
167
220
  var currLayer;
168
221
  if (layer.isEntity) {
@@ -178,7 +231,7 @@ var Event = /*#__PURE__*/function () {
178
231
  if (currLayer) {
179
232
  var result = {
180
233
  original: e,
181
- position: _this3._getPosition(position),
234
+ position: _this4._getPosition(position),
182
235
  layer: currLayer
183
236
  };
184
237
  if (type === Cesium.ScreenSpaceEventType.MOUSE_MOVE) {
@@ -192,23 +245,18 @@ var Event = /*#__PURE__*/function () {
192
245
  } else {
193
246
  toLeave(e, position);
194
247
  }
195
- }, type);
196
- handler.__proto__.off = function () {
197
- handler.removeInputAction(type);
198
- };
199
- return handler;
248
+ });
200
249
  }
201
250
 
202
251
  // 监听点聚合
203
252
  }, {
204
253
  key: "listenToPointCluster",
205
254
  value: function listenToPointCluster(type, event, cluster) {
206
- var _this4 = this;
207
- var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
208
- handler.setInputAction(function (e) {
255
+ var _this5 = this;
256
+ return this._subscribe(type, function (e) {
209
257
  var _ref3 = dealWithMapType(type, e) || {},
210
258
  position = _ref3.position;
211
- var pickedObject = _this4._getPickedObject(position);
259
+ var pickedObject = _this5._getPickedObject(position);
212
260
  if (pickedObject) {
213
261
  var clusterPoints = cluster.billboards.filter(function (t) {
214
262
  return ((pickedObject === null || pickedObject === void 0 ? void 0 : pickedObject.id) || []).includes(t.id);
@@ -216,49 +264,45 @@ var Event = /*#__PURE__*/function () {
216
264
  if (clusterPoints) {
217
265
  event({
218
266
  original: e,
219
- position: _this4._getPosition(position),
267
+ position: _this5._getPosition(position),
220
268
  clusterPoints: clusterPoints
221
269
  });
222
270
  }
223
271
  }
224
- }, type);
225
- handler.__proto__.off = function () {
226
- handler.removeInputAction(type);
227
- };
228
- return handler;
272
+ });
229
273
  }
230
274
 
231
275
  // 监听模型漫游
232
276
  }, {
233
277
  key: "listenToModelRoam",
234
278
  value: function listenToModelRoam(type, event, modelRoam) {
235
- var _this5 = this;
236
- var handler = new Cesium.ScreenSpaceEventHandler(this._map.scene.canvas);
279
+ var _this6 = this;
237
280
  var isHoverLayer = null;
238
281
  var toLeave = function toLeave(e, position) {
239
282
  if (isHoverLayer && type === Cesium.ScreenSpaceEventType.MOUSE_MOVE) {
240
283
  event({
241
284
  original: e,
242
- position: _this5._getPosition(position),
285
+ position: _this6._getPosition(position),
243
286
  modelRoam: isHoverLayer,
244
287
  mouseType: 'mouseLeave'
245
288
  });
246
289
  isHoverLayer = null;
247
290
  }
248
291
  };
249
- handler.setInputAction(function (e) {
292
+ return this._subscribe(type, function (e) {
250
293
  var _ref4 = dealWithMapType(type, e) || {},
251
294
  position = _ref4.position;
252
- var pickedObject = _this5._getPickedObject(position);
295
+ var pickedObject = _this6._getPickedObject(position);
253
296
  if (pickedObject) {
254
- var _modelRoam$polylineLa, _pickedObject$id2, _modelRoam$modelLayer;
255
- var targetPolyline = (modelRoam === null || modelRoam === void 0 || (_modelRoam$polylineLa = modelRoam.polylineLayer) === null || _modelRoam$polylineLa === void 0 ? void 0 : _modelRoam$polylineLa.id) === (pickedObject === null || pickedObject === void 0 || (_pickedObject$id2 = pickedObject.id) === null || _pickedObject$id2 === void 0 ? void 0 : _pickedObject$id2.id);
256
- var targetModel = (modelRoam === null || modelRoam === void 0 || (_modelRoam$modelLayer = modelRoam.modelLayer) === null || _modelRoam$modelLayer === void 0 ? void 0 : _modelRoam$modelLayer.id) === (pickedObject === null || pickedObject === void 0 ? void 0 : pickedObject.id);
257
- if (targetPolyline || targetModel) {
297
+ var _modelRoam$polylineLa, _modelRoam$polylineLa2, _pickedObject$id2, _modelRoam$historyPol, _modelRoam$historyPol2, _pickedObject$id3, _modelRoam$modelLayer, _modelRoam$modelLayer2;
298
+ var targetPolyline = modelRoam !== null && modelRoam !== void 0 && (_modelRoam$polylineLa = modelRoam.polylineLayer) !== null && _modelRoam$polylineLa !== void 0 && _modelRoam$polylineLa.id ? (modelRoam === null || modelRoam === void 0 || (_modelRoam$polylineLa2 = modelRoam.polylineLayer) === null || _modelRoam$polylineLa2 === void 0 ? void 0 : _modelRoam$polylineLa2.id) === (pickedObject === null || pickedObject === void 0 || (_pickedObject$id2 = pickedObject.id) === null || _pickedObject$id2 === void 0 ? void 0 : _pickedObject$id2.id) : null;
299
+ var targetHistoryPolyline = modelRoam !== null && modelRoam !== void 0 && (_modelRoam$historyPol = modelRoam.historyPolylineLayer) !== null && _modelRoam$historyPol !== void 0 && _modelRoam$historyPol.id ? (modelRoam === null || modelRoam === void 0 || (_modelRoam$historyPol2 = modelRoam.historyPolylineLayer) === null || _modelRoam$historyPol2 === void 0 ? void 0 : _modelRoam$historyPol2.id) === (pickedObject === null || pickedObject === void 0 || (_pickedObject$id3 = pickedObject.id) === null || _pickedObject$id3 === void 0 ? void 0 : _pickedObject$id3.id) : null;
300
+ var targetModel = modelRoam !== null && modelRoam !== void 0 && (_modelRoam$modelLayer = modelRoam.modelLayer) !== null && _modelRoam$modelLayer !== void 0 && _modelRoam$modelLayer.id ? (modelRoam === null || modelRoam === void 0 || (_modelRoam$modelLayer2 = modelRoam.modelLayer) === null || _modelRoam$modelLayer2 === void 0 ? void 0 : _modelRoam$modelLayer2.id) === (pickedObject === null || pickedObject === void 0 ? void 0 : pickedObject.id) : null;
301
+ if (targetHistoryPolyline || targetPolyline || targetModel) {
258
302
  var result = {
259
303
  original: e,
260
- position: _this5._getPosition(position),
261
- targetType: targetPolyline ? 'polyline' : targetModel ? 'model' : '',
304
+ position: _this6._getPosition(position),
305
+ targetType: targetPolyline || targetHistoryPolyline ? 'polyline' : targetModel ? 'model' : '',
262
306
  modelRoam: modelRoam
263
307
  };
264
308
  if (type === Cesium.ScreenSpaceEventType.MOUSE_MOVE) {
@@ -272,11 +316,7 @@ var Event = /*#__PURE__*/function () {
272
316
  } else {
273
317
  toLeave(e, position);
274
318
  }
275
- }, type);
276
- handler.__proto__.off = function () {
277
- handler.removeInputAction(type);
278
- };
279
- return handler;
319
+ });
280
320
  }
281
321
  }]);
282
322
  return Event;