deeptwins-engine-3d 0.0.43 → 0.0.44

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.
@@ -1,244 +0,0 @@
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
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
- 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); } }
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
- 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; }
14
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
- 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); }
16
- import * as Cesium from 'deeptwins-cesium';
17
- import { merge } from 'lodash';
18
- import { SCENE_EVENT_TYPE } from "../constant";
19
- import ModelEntity from "../graphicLayer/ModelEntity";
20
- import PolylineEntity from "../graphicLayer/PolylineEntity";
21
- import { cartesian3ToLngLatAlt, lngLatAltToCartesian3 } from "../tool/utils";
22
-
23
- // todo 使用行方法 ModelRoamRealTime
24
- var ModelRoamRunTime = /*#__PURE__*/function () {
25
- function ModelRoamRunTime(map, options) {
26
- _classCallCheck(this, ModelRoamRunTime);
27
- _defineProperty(this, "polylineLayer", void 0);
28
- _defineProperty(this, "polylineEntity", void 0);
29
- _defineProperty(this, "polylineOptions", void 0);
30
- _defineProperty(this, "modelLayer", void 0);
31
- _defineProperty(this, "modelEntity", void 0);
32
- _defineProperty(this, "modelOptions", void 0);
33
- _defineProperty(this, "startPosition", null);
34
- _defineProperty(this, "positionProperty", void 0);
35
- _defineProperty(this, "isFlyTo", false);
36
- _defineProperty(this, "clampToGround", false);
37
- _defineProperty(this, "timeDiff", 1);
38
- _defineProperty(this, "status", 'init');
39
- _defineProperty(this, "_map", void 0);
40
- _defineProperty(this, "_eventRunning", void 0);
41
- _defineProperty(this, "_startTime", void 0);
42
- // 更新的位置数组
43
- _defineProperty(this, "_positions", []);
44
- _defineProperty(this, "_positionsCartesian3", []);
45
- _defineProperty(this, "_path", []);
46
- _defineProperty(this, "_listenScene", void 0);
47
- _defineProperty(this, "_listenRunning", void 0);
48
- var _ref = options || {},
49
- onRunning = _ref.onRunning,
50
- model = _ref.model,
51
- _ref$flyTo = _ref.flyTo,
52
- flyTo = _ref$flyTo === void 0 ? false : _ref$flyTo,
53
- polyline = _ref.polyline,
54
- _ref$timeDiff = _ref.timeDiff,
55
- timeDiff = _ref$timeDiff === void 0 ? 1 : _ref$timeDiff,
56
- _ref$clampToGround = _ref.clampToGround,
57
- clampToGround = _ref$clampToGround === void 0 ? false : _ref$clampToGround;
58
- onRunning && (this._eventRunning = onRunning);
59
- model && (this.modelOptions = model);
60
- polyline && (this.polylineOptions = polyline);
61
- this.timeDiff = timeDiff;
62
- this.isFlyTo = flyTo;
63
- this.clampToGround = clampToGround;
64
- if (this.clampToGround) {
65
- this.modelOptions.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND;
66
- this.polylineOptions.clampToGround = true;
67
- }
68
- this._map = map;
69
- this._init();
70
- }
71
- _createClass(ModelRoamRunTime, [{
72
- key: "_init",
73
- value: function _init() {
74
- var _this = this;
75
- var startTime = Cesium.JulianDate.now();
76
- this._map.clock.startTime = startTime.clone();
77
- this._map.clock.currentTime = startTime.clone();
78
-
79
- // 播放速率
80
- this._map.clock.multiplier = 1;
81
- this._map.clock.clockRange = Cesium.ClockRange.UNBOUNDED;
82
- // 停止播放
83
- this._map.clock.shouldAnimate = false;
84
- this.positionProperty = new Cesium.SampledPositionProperty();
85
- this._listenRunning = function () {
86
- // 获取当前时间
87
- var currentTime = _this._map.clock.currentTime;
88
- // 获取插值后的当前位置
89
- var currentPosition = _this.positionProperty.getValue(currentTime);
90
- if (currentPosition) {
91
- // 动态轨迹
92
- _this._path = [].concat(_toConsumableArray(_this._positionsCartesian3.slice(0, -1)), [currentPosition]);
93
- }
94
- // 监听运行状态
95
- if (_this._eventRunning && _this._map.clock.shouldAnimate) {
96
- if (currentPosition) {
97
- _this._eventRunning({
98
- position: cartesian3ToLngLatAlt(currentPosition),
99
- time: Cesium.JulianDate.toDate(currentTime)
100
- });
101
- }
102
- }
103
- };
104
- this._map.clock.onTick.addEventListener(this._listenRunning);
105
- }
106
-
107
- // 更新坐标
108
- }, {
109
- key: "updatePosition",
110
- value: function updatePosition(position) {
111
- var _this2 = this;
112
- if (this.status === 'destroy') return;
113
- this.status = 'running';
114
- this._positions.push(position);
115
- var positionCartesian3 = lngLatAltToCartesian3(position.lng, position.lat, position.alt);
116
- this._positionsCartesian3.push(positionCartesian3);
117
- var nowDate = Cesium.JulianDate.fromDate(new Date());
118
- if (this._positions.length === 1) {
119
- this._startTime = nowDate;
120
- this.positionProperty.addSample(nowDate, positionCartesian3);
121
- // 创建模型
122
- this.modelEntity = new Cesium.Entity({
123
- position: positionCartesian3,
124
- model: ModelEntity.handleOptions(this.modelOptions)
125
- });
126
- this.modelLayer = this._map.addGraphicEntityToLayer(this.modelEntity.position, {
127
- type: 'model',
128
- entity: this.modelEntity
129
- });
130
- if (this.isFlyTo) {
131
- this._map.flyTo(this.modelEntity);
132
- }
133
- } else {
134
- if (this._positions.length === 2) {
135
- // 计算时间差
136
- this._map.clock.currentTime = Cesium.JulianDate.addSeconds(this._startTime, this.timeDiff * -1, new Cesium.JulianDate());
137
- this._map.clock.shouldAnimate = true;
138
- // 轨迹
139
- if (!this.polylineLayer) {
140
- this.polylineEntity = new Cesium.Entity({
141
- polyline: _objectSpread({
142
- positions: new Cesium.CallbackProperty(function () {
143
- return _this2._path;
144
- }, false)
145
- }, PolylineEntity.handleOptions(this.polylineOptions))
146
- });
147
- this.polylineLayer = this._map.addGraphicEntityToLayer(this.polylineEntity.polyline.positions, {
148
- type: 'polyline',
149
- entity: this.polylineEntity
150
- });
151
- }
152
- }
153
- this.positionProperty.addSample(nowDate, positionCartesian3);
154
- this.modelEntity.orientation = new Cesium.VelocityOrientationProperty(this.positionProperty);
155
- this.modelEntity.position = this.positionProperty;
156
- }
157
- }
158
-
159
- // 第一人称视角跟随
160
- }, {
161
- key: "setFollowFirst",
162
- value: function setFollowFirst() {
163
- var _this3 = this;
164
- var distance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
165
- if (this.status === 'destroy') return;
166
- this.cancelFollow();
167
- this._listenScene = this._map.on(SCENE_EVENT_TYPE.PRE_UPDATE, function () {
168
- var position = _this3.modelEntity.position.getValue(_this3._map.clock.currentTime);
169
- if (position) {
170
- // 获取模型的姿态
171
- var orientation = _this3.modelEntity.orientation.getValue(_this3._map.clock.currentTime);
172
- var transform = Cesium.Transforms.eastNorthUpToFixedFrame(position);
173
- transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation), position);
174
- _this3._map.camera.lookAtTransform(transform, new Cesium.Cartesian3(-20, 0, distance));
175
- }
176
- });
177
- }
178
-
179
- // 第三人称视角跟随
180
- }, {
181
- key: "setFollowThird",
182
- value: function setFollowThird() {
183
- if (this.status === 'destroy') return;
184
- this.cancelFollow();
185
- this._map.trackedEntity = this.modelEntity;
186
- }
187
-
188
- // 取消跟随
189
- }, {
190
- key: "cancelFollow",
191
- value: function cancelFollow() {
192
- if (this.status === 'destroy') return;
193
- this._listenScene && this._listenScene.off();
194
- this._map.trackedEntity = null;
195
- this._map.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
196
- }
197
-
198
- // 监听
199
- }, {
200
- key: "on",
201
- value: function on(type, event) {
202
- return this._map._event.listenToModelRoam(type, event, this);
203
- }
204
-
205
- // 更新线
206
- }, {
207
- key: "updatePolyline",
208
- value: function updatePolyline(style) {
209
- this.polylineOptions = merge({}, this.polylineOptions, style);
210
- this.polylineLayer && this.polylineLayer.setStyle(style);
211
- }
212
-
213
- // 更新模型
214
- }, {
215
- key: "updateModel",
216
- value: function updateModel(style) {
217
- this.modelOptions = merge({}, this.modelOptions, style);
218
- this.modelLayer && this.modelLayer.setStyle(style);
219
- }
220
-
221
- // 销毁
222
- }, {
223
- key: "destroy",
224
- value: function destroy() {
225
- this.status = 'destroy';
226
- this._map.clock.shouldAnimate = false;
227
- this._map.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
228
- this._map.clock.onTick.removeEventListener(this._listenRunning);
229
- this._listenRunning = null;
230
- this.cancelFollow();
231
- this.polylineLayer && this.polylineLayer.remove();
232
- this.polylineEntity = null;
233
- this.polylineOptions = null;
234
- this.modelLayer && this.modelLayer.remove();
235
- this.modelEntity = null;
236
- this.modelOptions = null;
237
- this._positions = [];
238
- this.positionProperty = null;
239
- this._map = null;
240
- }
241
- }]);
242
- return ModelRoamRunTime;
243
- }();
244
- export { ModelRoamRunTime as default };