deeptwins-engine-3d 0.1.36 → 0.1.37

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deeptwins-engine-3d",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "description": "map for 3d",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -1,23 +0,0 @@
1
- declare class Compass {
2
- private readonly _mapContext;
3
- isDestroyed: boolean;
4
- container: any;
5
- private _cameraChangeEvent;
6
- private _rotate;
7
- compassEl: any;
8
- private _rotateTimer;
9
- private _isRotating;
10
- private _pitchTimer;
11
- private _isPitching;
12
- constructor(map: any, container: any);
13
- private _canOperate;
14
- getMap(): any;
15
- private _create;
16
- private _updateDirection;
17
- private _startContinuousRotation;
18
- private _stopContinuousRotation;
19
- private _startContinuousPitch;
20
- private _stopContinuousPitch;
21
- destroy(): void;
22
- }
23
- export default Compass;
@@ -1,245 +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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- import * as Cesium from 'deeptwins-cesium';
9
- import { isString } from 'lodash';
10
- import Rotate from "../cameraControl/Rotate";
11
- import { CAMERA_EVENT_TYPE } from "../constant";
12
- import { error, getDeepTwinsFile, lngLatAltToCartesian3, toDegrees, toRadians } from "../tool/utils";
13
-
14
- // 罗盘
15
- var Compass = /*#__PURE__*/function () {
16
- function Compass(map, container) {
17
- var _this = this;
18
- _classCallCheck(this, Compass);
19
- _defineProperty(this, "_mapContext", void 0);
20
- _defineProperty(this, "isDestroyed", false);
21
- _defineProperty(this, "container", void 0);
22
- _defineProperty(this, "_cameraChangeEvent", void 0);
23
- _defineProperty(this, "_rotate", void 0);
24
- _defineProperty(this, "compassEl", {});
25
- _defineProperty(this, "_rotateTimer", null);
26
- _defineProperty(this, "_isRotating", false);
27
- _defineProperty(this, "_pitchTimer", null);
28
- _defineProperty(this, "_isPitching", false);
29
- this._mapContext = map._mapContext;
30
- this.container = isString(container) ? document.getElementById(container) : container;
31
- this._rotate = new Rotate(map);
32
- this._cameraChangeEvent = this.getMap().on(CAMERA_EVENT_TYPE.CHANGED, function (e) {
33
- _this._updateDirection(e === null || e === void 0 ? void 0 : e.position);
34
- });
35
- this._create();
36
- }
37
-
38
- // 是否能进行操作
39
- _createClass(Compass, [{
40
- key: "_canOperate",
41
- value: function _canOperate() {
42
- if (this.isDestroyed) {
43
- error('Compass实例已销毁');
44
- return false;
45
- }
46
- return true;
47
- }
48
- }, {
49
- key: "getMap",
50
- value: function getMap() {
51
- return this._mapContext && this._mapContext.getMap();
52
- }
53
- }, {
54
- key: "_create",
55
- value: function _create() {
56
- var _this2 = this;
57
- if (!this._canOperate()) {
58
- return;
59
- }
60
- var el = document.createElement('div');
61
- el.className = 'deeptwins-compass';
62
- var leftDirection = document.createElement('img');
63
- leftDirection.className = 'deeptwins-compass-left-direction';
64
- leftDirection.src = getDeepTwinsFile('Image/compass/compass-direction-left.png');
65
- el.appendChild(leftDirection);
66
-
67
- // 左箭头持续旋转
68
- leftDirection.onmousedown = function () {
69
- _this2._startContinuousRotation(1);
70
- };
71
- leftDirection.onmouseup = function () {
72
- _this2._stopContinuousRotation();
73
- };
74
- leftDirection.onmouseleave = function () {
75
- _this2._stopContinuousRotation();
76
- };
77
- this.compassEl.leftDirection = leftDirection;
78
- var pointer = document.createElement('img');
79
- pointer.className = 'deeptwins-compass-pointer';
80
- pointer.src = getDeepTwinsFile('Image/compass/pointer-white.png');
81
- el.appendChild(pointer);
82
- this.compassEl.pointer = pointer;
83
- var rightDirection = document.createElement('img');
84
- rightDirection.className = 'deeptwins-compass-right-direction';
85
- rightDirection.src = getDeepTwinsFile('Image/compass/compass-direction-right.png');
86
- el.appendChild(rightDirection);
87
- // 右箭头持续旋转
88
- rightDirection.onmousedown = function () {
89
- _this2._startContinuousRotation(-1);
90
- };
91
- rightDirection.onmouseup = function () {
92
- _this2._stopContinuousRotation();
93
- };
94
- rightDirection.onmouseleave = function () {
95
- _this2._stopContinuousRotation();
96
- };
97
- this.compassEl.rightDirection = rightDirection;
98
- var pitchUp = document.createElement('img');
99
- pitchUp.className = 'deeptwins-compass-pitch-up';
100
- pitchUp.src = getDeepTwinsFile('Image/compass/compass-pitch-up.png');
101
- el.appendChild(pitchUp);
102
- pitchUp.onmousedown = function () {
103
- _this2._startContinuousPitch(1);
104
- };
105
- pitchUp.onmouseup = function () {
106
- _this2._stopContinuousPitch();
107
- };
108
- pitchUp.onmouseleave = function () {
109
- _this2._stopContinuousPitch();
110
- };
111
- this.compassEl.pitchUp = pitchUp;
112
- var pitchDown = document.createElement('img');
113
- pitchDown.className = 'deeptwins-compass-pitch-down';
114
- pitchDown.src = getDeepTwinsFile('Image/compass/compass-pitch-down.png');
115
- el.appendChild(pitchDown);
116
- pitchDown.onmousedown = function () {
117
- _this2._startContinuousPitch(-1);
118
- };
119
- pitchDown.onmouseup = function () {
120
- _this2._stopContinuousPitch();
121
- };
122
- pitchDown.onmouseleave = function () {
123
- _this2._stopContinuousPitch();
124
- };
125
- this.compassEl.pitchDown = pitchDown;
126
- this.container.appendChild(el);
127
- this._updateDirection(this.getMap().getCameraView());
128
- }
129
- }, {
130
- key: "_updateDirection",
131
- value: function _updateDirection(cameraView) {
132
- if (!this._canOperate()) {
133
- return;
134
- }
135
- var _ref = cameraView || {},
136
- pitch = _ref.pitch,
137
- heading = _ref.heading;
138
- this.compassEl.pointer.style.transform = "rotateX(".concat(Math.min(90 + pitch, 80), "deg) rotateZ(").concat(360 - heading, "deg)");
139
- }
140
-
141
- // 开始持续旋转
142
- }, {
143
- key: "_startContinuousRotation",
144
- value: function _startContinuousRotation(direction) {
145
- var _this3 = this;
146
- if (!this._canOperate()) return;
147
- if (this._isRotating) return;
148
- this._isRotating = true;
149
- var rotate = function rotate() {
150
- if (!_this3._isRotating) return;
151
- // 立即旋转一个小角度
152
- _this3._rotate.start({
153
- duration: 0,
154
- angle: direction * 2 // 每次旋转2度
155
- });
156
- // 设置下次旋转
157
- _this3._rotateTimer = setTimeout(rotate, 16); // 约60fps
158
- };
159
- rotate();
160
- }
161
-
162
- // 停止持续旋转
163
- }, {
164
- key: "_stopContinuousRotation",
165
- value: function _stopContinuousRotation() {
166
- if (!this._canOperate()) return;
167
- this._isRotating = false;
168
- if (this._rotateTimer) {
169
- clearTimeout(this._rotateTimer);
170
- this._rotateTimer = null;
171
- }
172
- }
173
-
174
- // 开始持续pitch
175
- }, {
176
- key: "_startContinuousPitch",
177
- value: function _startContinuousPitch(direction) {
178
- var _this4 = this;
179
- if (!this._canOperate()) return;
180
- if (this._isPitching) return;
181
- this._isPitching = true;
182
- var setPitch = function setPitch() {
183
- if (!_this4._isPitching) return;
184
- if (direction === 1 && toDegrees(_this4.getMap().camera.pitch) >= -10) {
185
- return;
186
- }
187
- var _this4$getMap$getMapC = _this4.getMap().getMapCenter(),
188
- lng = _this4$getMap$getMapC.lng,
189
- lat = _this4$getMap$getMapC.lat,
190
- alt = _this4$getMap$getMapC.alt;
191
- var position = lngLatAltToCartesian3(lng, lat, alt);
192
- var cameraPosition = _this4.getMap().camera.position;
193
- // 根据屏幕中心像素的坐标获取中心点笛卡尔坐标
194
- var centerCartesian = _this4.getMap().camera.pickEllipsoid(new Cesium.Cartesian2(_this4.getMap().canvas.clientWidth / 2, _this4.getMap().canvas.clientHeight / 2), _this4.getMap().scene.globe.ellipsoid);
195
- // 相机距离中心点的位置
196
- var distance = Cesium.Cartesian3.distance(cameraPosition, centerCartesian);
197
- // 倾斜角
198
- var finalPitch = Math.min(toRadians(-9), Math.max(toRadians(-89), _this4.getMap().camera.pitch + toRadians(direction)));
199
- _this4.getMap().scene.camera.setView({
200
- destination: position,
201
- orientation: {
202
- heading: _this4.getMap().camera.heading,
203
- pitch: finalPitch
204
- }
205
- });
206
- _this4.getMap().scene.camera.moveBackward(distance);
207
- // 设置下次调整
208
- _this4._pitchTimer = setTimeout(setPitch, 16); // 约60fps
209
- };
210
- setPitch();
211
- }
212
-
213
- // 停止持续pitch
214
- }, {
215
- key: "_stopContinuousPitch",
216
- value: function _stopContinuousPitch() {
217
- if (!this._canOperate()) return;
218
- this._isPitching = false;
219
- if (this._pitchTimer) {
220
- clearTimeout(this._pitchTimer);
221
- this._pitchTimer = null;
222
- }
223
- }
224
-
225
- // 销毁
226
- }, {
227
- key: "destroy",
228
- value: function destroy() {
229
- if (!this._canOperate()) {
230
- return;
231
- }
232
- this.isDestroyed = true;
233
- this.container.removeChild(this.container.querySelector('.deeptwins-compass'));
234
- this._cameraChangeEvent && this._cameraChangeEvent.off();
235
- this._cameraChangeEvent = null;
236
-
237
- // 清理旋转和倾斜定时器
238
- this._stopContinuousRotation();
239
- this._stopContinuousPitch();
240
- this.compassEl = {};
241
- }
242
- }]);
243
- return Compass;
244
- }();
245
- export default Compass;