chbim-time-axis-v2 0.0.17 → 0.0.19
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/README.md
CHANGED
|
@@ -216,6 +216,66 @@ interface InstantTask extends GanttTask {
|
|
|
216
216
|
}
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
## 🎥 ViewportRoam (视角漫游)
|
|
220
|
+
|
|
221
|
+
组件包内置了一个 `ViewportRoam` 工具类,用于在 Cesium 中实现平滑的视角漫游,支持位置、偏航角(heading)、俯仰角(pitch)和翻滚角(roll)的插值动画。
|
|
222
|
+
|
|
223
|
+
### 1. 导入与定义
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { ViewportRoam, type RoamPoint } from "chbim-time-axis-v2";
|
|
227
|
+
|
|
228
|
+
// 漫游点数据结构
|
|
229
|
+
interface RoamPoint {
|
|
230
|
+
id: number | string;
|
|
231
|
+
time: string; // ISO8601 时间字符串
|
|
232
|
+
lng: number; // 经度
|
|
233
|
+
lat: number; // 纬度
|
|
234
|
+
alt: number; // 高度
|
|
235
|
+
heading: number; // 偏航角 (度)
|
|
236
|
+
pitch: number; // 俯仰角 (度)
|
|
237
|
+
roll?: number; // 翻滚角 (度),可选
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 2. 使用示例
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// 1. 准备漫游数据
|
|
245
|
+
const roamData: RoamPoint[] = [
|
|
246
|
+
{
|
|
247
|
+
id: 1,
|
|
248
|
+
time: "2023-01-01T10:00:00Z",
|
|
249
|
+
lng: 120.123,
|
|
250
|
+
lat: 30.456,
|
|
251
|
+
alt: 100,
|
|
252
|
+
heading: 0,
|
|
253
|
+
pitch: -45,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: 2,
|
|
257
|
+
time: "2023-01-01T10:01:00Z",
|
|
258
|
+
lng: 120.124,
|
|
259
|
+
lat: 30.457,
|
|
260
|
+
alt: 120,
|
|
261
|
+
heading: 90,
|
|
262
|
+
pitch: -30,
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
// 2. 初始化漫游控制器
|
|
267
|
+
const roamController = new ViewportRoam(viewer, roamData);
|
|
268
|
+
|
|
269
|
+
// 3. 开始漫游 (将自动监听时钟 tick 事件并更新相机)
|
|
270
|
+
roamController.start();
|
|
271
|
+
|
|
272
|
+
// 4. 停止漫游
|
|
273
|
+
// roamController.stop();
|
|
274
|
+
|
|
275
|
+
// 5. 销毁 (组件卸载时调用)
|
|
276
|
+
// roamController.destroy();
|
|
277
|
+
```
|
|
278
|
+
|
|
219
279
|
## ⚙️ 组件 API
|
|
220
280
|
|
|
221
281
|
### Props (属性)
|
|
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
import { watch, toValue as toValue$1, computed, unref, reactive, shallowRef, ref, getCurrentScope, onScopeDispose, shallowReadonly, defineComponent, mergeDefaults, useSlots, useTemplateRef, openBlock, createBlock, createSlots, renderList, withCtx, renderSlot, normalizeProps, guardReactiveProps, provide, readonly, toRef, onMounted, nextTick, onUnmounted, createElementBlock, normalizeClass, createVNode, Teleport, createElementVNode, normalizeStyle, Transition, createCommentVNode, inject, withModifiers, Fragment, toDisplayString, resolveDynamicComponent, h, mergeProps, createTextVNode, onBeforeUpdate, withDirectives, vShow, withKeys, createStaticVNode } from "vue";
|
|
8
|
+
import * as Cesium from "cesium";
|
|
8
9
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
9
10
|
function getDefaultExportFromCjs(x) {
|
|
10
11
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -13137,10 +13138,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
13137
13138
|
if (clock) {
|
|
13138
13139
|
isPlaying.value = clock.shouldAnimate;
|
|
13139
13140
|
const onTick = () => {
|
|
13140
|
-
const
|
|
13141
|
-
if (!
|
|
13141
|
+
const Cesium2 = window.Cesium;
|
|
13142
|
+
if (!Cesium2)
|
|
13142
13143
|
return;
|
|
13143
|
-
const now =
|
|
13144
|
+
const now = Cesium2.JulianDate.toDate(clock.currentTime);
|
|
13144
13145
|
currentTime.value = dayjs(now).toISOString();
|
|
13145
13146
|
if (isPlaying.value !== clock.shouldAnimate) {
|
|
13146
13147
|
isPlaying.value = clock.shouldAnimate;
|
|
@@ -13405,9 +13406,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
13405
13406
|
const handleTimeUpdate = (newTime) => {
|
|
13406
13407
|
currentTime.value = newTime;
|
|
13407
13408
|
const clock = targetClock.value;
|
|
13408
|
-
const
|
|
13409
|
-
if (clock &&
|
|
13410
|
-
clock.currentTime =
|
|
13409
|
+
const Cesium2 = window.Cesium;
|
|
13410
|
+
if (clock && Cesium2) {
|
|
13411
|
+
clock.currentTime = Cesium2.JulianDate.fromIso8601(newTime);
|
|
13411
13412
|
}
|
|
13412
13413
|
};
|
|
13413
13414
|
const toggleMaximize = () => {
|
|
@@ -13635,10 +13636,109 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
13635
13636
|
});
|
|
13636
13637
|
const CesiumGantt_vue_vue_type_style_index_0_scoped_bc47a9ac_lang = "";
|
|
13637
13638
|
const CesiumGantt = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-bc47a9ac"]]);
|
|
13639
|
+
class ViewportRoam {
|
|
13640
|
+
constructor(viewer, data) {
|
|
13641
|
+
__publicField(this, "viewer");
|
|
13642
|
+
__publicField(this, "positionProperty");
|
|
13643
|
+
__publicField(this, "headingProperty");
|
|
13644
|
+
__publicField(this, "pitchProperty");
|
|
13645
|
+
__publicField(this, "rollProperty");
|
|
13646
|
+
__publicField(this, "_onTick");
|
|
13647
|
+
__publicField(this, "_isPlaying", false);
|
|
13648
|
+
this.viewer = viewer;
|
|
13649
|
+
this.positionProperty = new Cesium.SampledPositionProperty();
|
|
13650
|
+
this.headingProperty = new Cesium.SampledProperty(Number);
|
|
13651
|
+
this.pitchProperty = new Cesium.SampledProperty(Number);
|
|
13652
|
+
this.rollProperty = new Cesium.SampledProperty(Number);
|
|
13653
|
+
this.positionProperty.setInterpolationOptions({
|
|
13654
|
+
interpolationDegree: 1,
|
|
13655
|
+
interpolationAlgorithm: Cesium.LinearApproximation
|
|
13656
|
+
});
|
|
13657
|
+
this.headingProperty.setInterpolationOptions({
|
|
13658
|
+
interpolationDegree: 1,
|
|
13659
|
+
interpolationAlgorithm: Cesium.LinearApproximation
|
|
13660
|
+
});
|
|
13661
|
+
this.pitchProperty.setInterpolationOptions({
|
|
13662
|
+
interpolationDegree: 1,
|
|
13663
|
+
interpolationAlgorithm: Cesium.LinearApproximation
|
|
13664
|
+
});
|
|
13665
|
+
this.rollProperty.setInterpolationOptions({
|
|
13666
|
+
interpolationDegree: 1,
|
|
13667
|
+
interpolationAlgorithm: Cesium.LinearApproximation
|
|
13668
|
+
});
|
|
13669
|
+
this.initData(data);
|
|
13670
|
+
this._onTick = (clock) => {
|
|
13671
|
+
const time = clock.currentTime;
|
|
13672
|
+
this.updateCamera(time);
|
|
13673
|
+
};
|
|
13674
|
+
}
|
|
13675
|
+
initData(data) {
|
|
13676
|
+
const sortedData = [...data].sort(
|
|
13677
|
+
(a, b) => dayjs(a.time).valueOf() - dayjs(b.time).valueOf()
|
|
13678
|
+
);
|
|
13679
|
+
sortedData.forEach((item) => {
|
|
13680
|
+
const time = Cesium.JulianDate.fromIso8601(item.time);
|
|
13681
|
+
const position = Cesium.Cartesian3.fromDegrees(
|
|
13682
|
+
item.lng,
|
|
13683
|
+
item.lat,
|
|
13684
|
+
item.alt
|
|
13685
|
+
);
|
|
13686
|
+
this.positionProperty.addSample(time, position);
|
|
13687
|
+
this.headingProperty.addSample(time, Cesium.Math.toRadians(item.heading));
|
|
13688
|
+
this.pitchProperty.addSample(time, Cesium.Math.toRadians(item.pitch));
|
|
13689
|
+
this.rollProperty.addSample(time, Cesium.Math.toRadians(item.roll || 0));
|
|
13690
|
+
});
|
|
13691
|
+
}
|
|
13692
|
+
/**
|
|
13693
|
+
* 开始跟随时间轴播放漫游
|
|
13694
|
+
*/
|
|
13695
|
+
start() {
|
|
13696
|
+
if (this._isPlaying)
|
|
13697
|
+
return;
|
|
13698
|
+
this.viewer.clock.onTick.addEventListener(this._onTick);
|
|
13699
|
+
this._isPlaying = true;
|
|
13700
|
+
}
|
|
13701
|
+
/**
|
|
13702
|
+
* 停止漫游
|
|
13703
|
+
*/
|
|
13704
|
+
stop() {
|
|
13705
|
+
if (!this._isPlaying)
|
|
13706
|
+
return;
|
|
13707
|
+
this.viewer.clock.onTick.removeEventListener(this._onTick);
|
|
13708
|
+
this._isPlaying = false;
|
|
13709
|
+
}
|
|
13710
|
+
/**
|
|
13711
|
+
* 根据当前时间更新相机
|
|
13712
|
+
* @param time
|
|
13713
|
+
*/
|
|
13714
|
+
updateCamera(time) {
|
|
13715
|
+
const position = this.positionProperty.getValue(time);
|
|
13716
|
+
const heading = this.headingProperty.getValue(time);
|
|
13717
|
+
const pitch = this.pitchProperty.getValue(time);
|
|
13718
|
+
const roll = this.rollProperty.getValue(time);
|
|
13719
|
+
if (position && heading !== void 0 && pitch !== void 0) {
|
|
13720
|
+
this.viewer.camera.setView({
|
|
13721
|
+
destination: position,
|
|
13722
|
+
orientation: {
|
|
13723
|
+
heading,
|
|
13724
|
+
pitch,
|
|
13725
|
+
roll: roll || 0
|
|
13726
|
+
}
|
|
13727
|
+
});
|
|
13728
|
+
}
|
|
13729
|
+
}
|
|
13730
|
+
/**
|
|
13731
|
+
* 销毁实例
|
|
13732
|
+
*/
|
|
13733
|
+
destroy() {
|
|
13734
|
+
this.stop();
|
|
13735
|
+
}
|
|
13736
|
+
}
|
|
13638
13737
|
CesiumGantt.install = (app) => {
|
|
13639
13738
|
app.component("CesiumGantt", CesiumGantt);
|
|
13640
13739
|
};
|
|
13641
13740
|
export {
|
|
13642
13741
|
CesiumGantt,
|
|
13742
|
+
ViewportRoam,
|
|
13643
13743
|
CesiumGantt as default
|
|
13644
13744
|
};
|