deeptwins-engine-3d 0.1.34 → 0.1.35

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.
@@ -46,13 +46,33 @@ var Rotate = /*#__PURE__*/function () {
46
46
  var cameraPosition = this.getMap().camera.position;
47
47
  // 根据屏幕中心像素的坐标获取中心点笛卡尔坐标
48
48
  var centerCartesian = this.getMap().camera.pickEllipsoid(new Cesium.Cartesian2(this.getMap().canvas.clientWidth / 2, this.getMap().canvas.clientHeight / 2), this.getMap().scene.globe.ellipsoid);
49
- // 每秒飞行的角度
50
- var angleOneSecond = 360 / (360 / angle * duration);
51
49
  // 相机距离中心点的位置
52
50
  var distance = Cesium.Cartesian3.distance(cameraPosition, centerCartesian);
53
51
  // 倾斜角
54
52
  var pitch = this.getMap().camera.pitch;
55
53
 
54
+ // 如果duration为0,立即飞行到目标位置
55
+ if (duration === 0) {
56
+ var finalHeading = this.getMap().camera.heading + Cesium.Math.toRadians(angle);
57
+ this.getMap().scene.camera.setView({
58
+ destination: position,
59
+ // 点的坐标
60
+ orientation: {
61
+ heading: finalHeading,
62
+ pitch: pitch
63
+ }
64
+ });
65
+ this.getMap().scene.camera.moveBackward(distance);
66
+ // 立即触发完成事件
67
+ if (this._eventComplete) {
68
+ this._eventComplete();
69
+ }
70
+ return;
71
+ }
72
+
73
+ // 每秒飞行的角度
74
+ var angleOneSecond = 360 / (360 / angle * duration);
75
+
56
76
  // 开始时间
57
77
  var startTime = Cesium.JulianDate.fromDate(new Date());
58
78
  // 结束时间
@@ -1,3 +1,39 @@
1
1
  #yunjinglogo {
2
2
  display: none;
3
3
  }
4
+
5
+ .deeptwins-compass {
6
+ position: relative;
7
+ width: 92px;
8
+ height: 92px;
9
+ background: #f7f7f7;
10
+ border-radius: 50%;
11
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
12
+ display: flex;
13
+ align-items: center;
14
+ user-select: none;
15
+ }
16
+
17
+ .deeptwins-compass-left-direction {
18
+ cursor: pointer;
19
+ }
20
+
21
+ .deeptwins-compass-right-direction {
22
+ cursor: pointer;
23
+ }
24
+
25
+ .deeptwins-compass-pitch-up {
26
+ cursor: pointer;
27
+ position: absolute;
28
+ top: 3px;
29
+ left: 50%;
30
+ transform: translateX(-50%);
31
+ }
32
+
33
+ .deeptwins-compass-pitch-down {
34
+ cursor: pointer;
35
+ position: absolute;
36
+ bottom: 3px;
37
+ left: 50%;
38
+ transform: translateX(-50%);
39
+ }
@@ -61,5 +61,7 @@ export declare class DeepTwinsEngine3D {
61
61
  static SplitDirection: any;
62
62
  static ImageGlowingMaterialProperty: any;
63
63
  static SubmergenceAnalysis: any;
64
+ static Compass: any;
65
+ static KmlDataSource: any;
64
66
  }
65
67
  export default DeepTwinsEngine3D;
package/dist/esm/index.js CHANGED
@@ -33,6 +33,7 @@ import ArcGisLayer from "./tileLayer/ArcGisLayer";
33
33
  import RasterLayer from "./tileLayer/RasterLayer";
34
34
  import WmsLayer from "./tileLayer/WmsLayer";
35
35
  import WmtsLayer from "./tileLayer/WmtsLayer";
36
+ import Compass from "./tool/Compass";
36
37
  import TimerInterval from "./tool/TimerInterval";
37
38
  import { ClampToGround, ShapeSection } from "./tool/common";
38
39
  import { loadCss } from "./tool/utils";
@@ -50,11 +51,11 @@ DEEP_TWINS_BASE_URL && (window.CESIUM_BASE_URL = DEEP_TWINS_BASE_URL);
50
51
  // 全局加载css
51
52
  loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
52
53
  // 打印版本信息
53
- console.log('DeepTwinsEngine3D Version:', "0.1.34");
54
+ console.log('DeepTwinsEngine3D Version:', "0.1.35");
54
55
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
55
56
  _classCallCheck(this, DeepTwinsEngine3D);
56
57
  });
57
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.34");
58
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.35");
58
59
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
59
60
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
60
61
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -115,4 +116,6 @@ _defineProperty(DeepTwinsEngine3D, "BoundingRectangle", Cesium.BoundingRectangle
115
116
  _defineProperty(DeepTwinsEngine3D, "SplitDirection", Cesium.SplitDirection);
116
117
  _defineProperty(DeepTwinsEngine3D, "ImageGlowingMaterialProperty", ImageGlowingMaterialProperty);
117
118
  _defineProperty(DeepTwinsEngine3D, "SubmergenceAnalysis", SubmergenceAnalysis);
119
+ _defineProperty(DeepTwinsEngine3D, "Compass", Compass);
120
+ _defineProperty(DeepTwinsEngine3D, "KmlDataSource", Cesium.KmlDataSource);
118
121
  export default DeepTwinsEngine3D;
@@ -0,0 +1,23 @@
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;
@@ -0,0 +1,245 @@
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;
@@ -92,7 +92,12 @@ var Airspace = /*#__PURE__*/function () {
92
92
  boxPrimitive.createPrimitive({
93
93
  style: _objectSpread(_objectSpread({}, this.options), {}, {
94
94
  show: this._isShow
95
- })
95
+ }),
96
+ primitive: {
97
+ interleave: true,
98
+ allowPicking: false,
99
+ cull: false
100
+ }
96
101
  }, primitiveInstance);
97
102
  this.getMap().scene.primitives.add(boxPrimitive.primitive);
98
103
  }
@@ -1 +1 @@
1
- .deepTwins-toolTip{background:rgba(42,42,42,.9);border-radius:4px;color:#fff;display:none;font-size:12px;padding:4px 8px;pointer-events:none;position:absolute;transform:translate3d(10px,-50%,0);white-space:nowrap}.deepTwins-toolTip:before{border-bottom:5px solid transparent;border-right:5px solid rgba(0,0,0,.6);border-top:5px solid transparent;content:"";display:block;left:-5px;pointer-events:none;position:absolute;top:calc(50% - 5px)}#yunjinglogo{display:none}
1
+ .deepTwins-toolTip{background:rgba(42,42,42,.9);border-radius:4px;color:#fff;display:none;font-size:12px;padding:4px 8px;pointer-events:none;position:absolute;transform:translate3d(10px,-50%,0);white-space:nowrap}.deepTwins-toolTip:before{border-bottom:5px solid transparent;border-right:5px solid rgba(0,0,0,.6);border-top:5px solid transparent;content:"";display:block;left:-5px;pointer-events:none;position:absolute;top:calc(50% - 5px)}#yunjinglogo{display:none}.deeptwins-compass{align-items:center;background:#f7f7f7;border-radius:50%;box-shadow:0 0 10px rgba(0,0,0,.3);display:flex;height:92px;position:relative;-ms-user-select:none;user-select:none;width:92px}.deeptwins-compass-left-direction,.deeptwins-compass-right-direction{cursor:pointer}.deeptwins-compass-pitch-up{top:3px}.deeptwins-compass-pitch-down,.deeptwins-compass-pitch-up{cursor:pointer;left:50%;position:absolute;transform:translateX(-50%)}.deeptwins-compass-pitch-down{bottom:3px}