chbim-time-axis-v2 0.0.19 → 0.0.191

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.
@@ -13637,7 +13637,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
13637
13637
  const CesiumGantt_vue_vue_type_style_index_0_scoped_bc47a9ac_lang = "";
13638
13638
  const CesiumGantt = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-bc47a9ac"]]);
13639
13639
  class ViewportRoam {
13640
- constructor(viewer, data) {
13640
+ constructor(viewer, data, intervals) {
13641
13641
  __publicField(this, "viewer");
13642
13642
  __publicField(this, "positionProperty");
13643
13643
  __publicField(this, "headingProperty");
@@ -13645,38 +13645,146 @@ class ViewportRoam {
13645
13645
  __publicField(this, "rollProperty");
13646
13646
  __publicField(this, "_onTick");
13647
13647
  __publicField(this, "_isPlaying", false);
13648
+ __publicField(this, "validIntervals");
13648
13649
  this.viewer = viewer;
13650
+ this.validIntervals = new Cesium.TimeIntervalCollection([]);
13649
13651
  this.positionProperty = new Cesium.SampledPositionProperty();
13650
13652
  this.headingProperty = new Cesium.SampledProperty(Number);
13651
13653
  this.pitchProperty = new Cesium.SampledProperty(Number);
13652
13654
  this.rollProperty = new Cesium.SampledProperty(Number);
13653
- this.positionProperty.setInterpolationOptions({
13655
+ const interpolationOptions = {
13654
13656
  interpolationDegree: 1,
13655
13657
  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);
13658
+ };
13659
+ this.positionProperty.setInterpolationOptions(interpolationOptions);
13660
+ this.headingProperty.setInterpolationOptions(interpolationOptions);
13661
+ this.pitchProperty.setInterpolationOptions(interpolationOptions);
13662
+ this.rollProperty.setInterpolationOptions(interpolationOptions);
13670
13663
  this._onTick = (clock) => {
13671
13664
  const time = clock.currentTime;
13672
13665
  this.updateCamera(time);
13673
13666
  };
13667
+ if (data) {
13668
+ this.updateData(data, intervals);
13669
+ }
13670
+ }
13671
+ /**
13672
+ * 更新漫游数据
13673
+ * @param data 漫游点列表或任务列表
13674
+ * @param intervals 有效时间区间(仅当data为点列表时有效)
13675
+ */
13676
+ updateData(data, intervals) {
13677
+ this.positionProperty = new Cesium.SampledPositionProperty();
13678
+ this.headingProperty = new Cesium.SampledProperty(Number);
13679
+ this.pitchProperty = new Cesium.SampledProperty(Number);
13680
+ this.rollProperty = new Cesium.SampledProperty(Number);
13681
+ const interpolationOptions = {
13682
+ interpolationDegree: 1,
13683
+ interpolationAlgorithm: Cesium.LinearApproximation
13684
+ };
13685
+ this.positionProperty.setInterpolationOptions(interpolationOptions);
13686
+ this.headingProperty.setInterpolationOptions(interpolationOptions);
13687
+ this.pitchProperty.setInterpolationOptions(interpolationOptions);
13688
+ this.rollProperty.setInterpolationOptions(interpolationOptions);
13689
+ this.validIntervals = new Cesium.TimeIntervalCollection([]);
13690
+ if (this.isRoamPointArray(data)) {
13691
+ this.initData(data);
13692
+ if (intervals) {
13693
+ intervals.forEach(
13694
+ (interval) => this.validIntervals.addInterval(interval)
13695
+ );
13696
+ }
13697
+ } else {
13698
+ const { points, intervals: taskIntervals } = this.parseTasks(data);
13699
+ this.initData(points);
13700
+ taskIntervals.forEach(
13701
+ (interval) => this.validIntervals.addInterval(interval)
13702
+ );
13703
+ }
13704
+ }
13705
+ isRoamPointArray(data) {
13706
+ return data.length > 0 && "lat" in data[0] && "lng" in data[0];
13707
+ }
13708
+ /**
13709
+ * 解析任务列表,提取漫游点和时间区间
13710
+ */
13711
+ parseTasks(tasks) {
13712
+ const points = [];
13713
+ const intervals = [];
13714
+ const processRoamData = (roamData, startTime, endTime) => {
13715
+ if (!roamData || roamData.length === 0)
13716
+ return;
13717
+ const start = dayjs(startTime).valueOf();
13718
+ const end = dayjs(endTime).valueOf();
13719
+ const totalDuration = end - start;
13720
+ const hasSelfTime = roamData.every((item) => item.time);
13721
+ if (!hasSelfTime) {
13722
+ if (roamData.length === 1) {
13723
+ if (!roamData[0].time) {
13724
+ roamData[0].time = startTime;
13725
+ }
13726
+ } else {
13727
+ roamData.forEach((item, index) => {
13728
+ const progress = index / (roamData.length - 1);
13729
+ const time = start + totalDuration * progress;
13730
+ item.time = dayjs(time).toISOString();
13731
+ });
13732
+ }
13733
+ }
13734
+ points.push(...roamData);
13735
+ if (hasSelfTime && roamData.length > 0) {
13736
+ const firstTime = roamData[0].time;
13737
+ const lastTime = roamData[roamData.length - 1].time;
13738
+ intervals.push(
13739
+ new Cesium.TimeInterval({
13740
+ start: Cesium.JulianDate.fromIso8601(firstTime),
13741
+ stop: Cesium.JulianDate.fromIso8601(lastTime)
13742
+ })
13743
+ );
13744
+ } else {
13745
+ intervals.push(
13746
+ new Cesium.TimeInterval({
13747
+ start: Cesium.JulianDate.fromIso8601(startTime),
13748
+ stop: Cesium.JulianDate.fromIso8601(endTime)
13749
+ })
13750
+ );
13751
+ }
13752
+ };
13753
+ const traverse = (list) => {
13754
+ list.forEach((item) => {
13755
+ var _a;
13756
+ if (item.type === "group" && item.children) {
13757
+ traverse(item.children);
13758
+ } else {
13759
+ if (((_a = item.attr) == null ? void 0 : _a.roamData) && item.startTime && item.endTime) {
13760
+ processRoamData(item.attr.roamData, item.startTime, item.endTime);
13761
+ }
13762
+ if (item.blocks) {
13763
+ item.blocks.forEach((block) => {
13764
+ var _a2;
13765
+ if (((_a2 = block.attr) == null ? void 0 : _a2.roamData) && block.startTime && block.endTime) {
13766
+ processRoamData(
13767
+ block.attr.roamData,
13768
+ block.startTime,
13769
+ block.endTime
13770
+ );
13771
+ }
13772
+ });
13773
+ }
13774
+ }
13775
+ });
13776
+ };
13777
+ traverse(tasks);
13778
+ return { points, intervals };
13674
13779
  }
13675
13780
  initData(data) {
13676
13781
  const sortedData = [...data].sort(
13677
13782
  (a, b) => dayjs(a.time).valueOf() - dayjs(b.time).valueOf()
13678
13783
  );
13784
+ let lastHeading;
13679
13785
  sortedData.forEach((item) => {
13786
+ if (!item.time)
13787
+ return;
13680
13788
  const time = Cesium.JulianDate.fromIso8601(item.time);
13681
13789
  const position = Cesium.Cartesian3.fromDegrees(
13682
13790
  item.lng,
@@ -13684,7 +13792,23 @@ class ViewportRoam {
13684
13792
  item.alt
13685
13793
  );
13686
13794
  this.positionProperty.addSample(time, position);
13687
- this.headingProperty.addSample(time, Cesium.Math.toRadians(item.heading));
13795
+ let currentHeading = item.heading;
13796
+ if (lastHeading !== void 0) {
13797
+ let diff = currentHeading - lastHeading;
13798
+ while (diff > 180) {
13799
+ currentHeading -= 360;
13800
+ diff -= 360;
13801
+ }
13802
+ while (diff < -180) {
13803
+ currentHeading += 360;
13804
+ diff += 360;
13805
+ }
13806
+ }
13807
+ lastHeading = currentHeading;
13808
+ this.headingProperty.addSample(
13809
+ time,
13810
+ Cesium.Math.toRadians(currentHeading)
13811
+ );
13688
13812
  this.pitchProperty.addSample(time, Cesium.Math.toRadians(item.pitch));
13689
13813
  this.rollProperty.addSample(time, Cesium.Math.toRadians(item.roll || 0));
13690
13814
  });
@@ -13712,6 +13836,9 @@ class ViewportRoam {
13712
13836
  * @param time
13713
13837
  */
13714
13838
  updateCamera(time) {
13839
+ if (this.validIntervals.length > 0 && !this.validIntervals.contains(time)) {
13840
+ return;
13841
+ }
13715
13842
  const position = this.positionProperty.getValue(time);
13716
13843
  const heading = this.headingProperty.getValue(time);
13717
13844
  const pitch = this.pitchProperty.getValue(time);