根据Path实现路径漫游、回放、和其他模型连在一起

话不多说上效果图,,我声明一下,我只是提供工具,不是提供数据,谢谢合作!!!!!

如果遇到问题,请私聊我。

注释已经加满了!!!!!!!!!

 代码部分:

<template>
  <div>
    <div class="btn">
      <el-button @click="getdata">路径回放</el-button>
    </div>
  </div>
</template>
<script>
let start = null;
let stop = null;
let entity = [];
//本地数据
  /**
   * @数据格式: 
   *   {
                    "id": "00052db577e742229985c53bccdd22e3",
                    "longitude": 110.001456,
                    "latitude": 18.289878,
                    "currentTime": "2022-08-30 15:35:43",
                    "dwellTime": null,
                    "underwaterVehicleId": "b6b23aa4a90f4462948fe4b3f39dad59",
                    "frequency": 0,
                    "bandwidth": 0,
                    "signalstrength": 20,
                    "dataFlag": "1"
                },
   */
import pathdata from "../../public/data";
export default {
  components: { Map },
  data() {
    return {};
  },
  computed: {},
  created() {},
  mounted() {
    this.getdata();
  },
  methods: {
    getdata() {
      this.starttruk();
      this.startAir();
    },
  
    starttruk() {
      const HistoryVos =
        pathdata.monitoringHistoryVos[0].monitoringShipHistoryPathList;
      this.startpath(
        HistoryVos[0].currentTime,
        HistoryVos[HistoryVos.length - 1].currentTime
      );
      this.StartEntiy(this.getproperty(HistoryVos), "CesiumMilkTruck.glb", 10);
    },
    startAir() {
      const history = pathdata.vehicleHistoryVos;
      for (let index = 0; index < history.length; index++) {
        this.StartEntiy(
          this.getproperty(history[index].vehicleHistoryPaths),
          "Cesium_Air.glb",
          index
        );
        this.gentimeentiti(index);
      }
    },
    /**
     * @startpath: 确定坐标轴的范围
     * @param {*} startTime :"2022-08-30 15:35:43"开始的时间
     * @param {*} stopTime :"2022-08-30 15:35:43" 末尾的时间
     * @return {*}
     */
    
    startpath(startTime, stopTime) {
      start = Cesium.JulianDate.fromDate(new Date(startTime)); //获取第一个点的时间
      stop = Cesium.JulianDate.fromDate(new Date(stopTime));
      window.viewer.clock.startTime = start.clone(); //设置开始时间
      window.viewer.clock.currentTime = start.clone(); //修改时间轴的当前时间
      window.viewer.clock.stopTime = stop.clone();
      window.viewer.clock.multiplier = 8;
      window.viewer.timeline.zoomTo(start, stop); //设置时间轴时间范围
      window.viewer.clock.shouldAnimate = true;
    },
    /**
     * @startpath: 生成带有时间的经纬度数组对象
     * @param {*} source :带时间的和经纬度数组
     * @param {*} currentTime :"2022-08-30 15:35:43"
     * @param {*} Cesium.JulianDate.addSeconds(开始时间,秒数,new Cesium.JulianDate())
     * @return {*}  return property :返回生成的对象
     */
    getproperty(source) {
      let property = null;
      property = new Cesium.SampledPositionProperty();
      for (let i = 0; i < source.length; i++) {
        let time = Cesium.JulianDate.addSeconds(
          start,
          Cesium.JulianDate.fromDate(new Date(source[i].currentTime))
            .secondsOfDay - start.secondsOfDay,
          new Cesium.JulianDate()
        );
        // 添加位置,和时间对应
        property.addSample(
          time,
          Cesium.Cartesian3.fromDegrees(
            source[i].longitude,
            source[i].latitude,
            0
          )
        );
        if (i == source.length - 1) {
          property.addSample(
            stop,
            Cesium.Cartesian3.fromDegrees(
              source[i].longitude,
              source[i].latitude,
              0
            ),
            0
          );
        }
      }
      return property;
    },
    /**
     * @startpath: 绘制path entity对象
     * @param {*} property :带时间的和经纬度数组
     * @param {*} url :"模型的url"
     * @param {*} id  :对entity唯一个标识
     * @return {*}
     */
    StartEntiy(property, url, id) {
      entity[id] = window.viewer.entities.add({
        availability: new Cesium.TimeIntervalCollection([
          new Cesium.TimeInterval({
            start: start,
            stop: stop
          })
        ]),
        position: property,
        orientation: new Cesium.VelocityOrientationProperty(property),
        model: {
          uri: url,
          minimumPixelSize: 64
        },
        path: {
          leadTime: 0,
          resolution: 1,
          material: new Cesium.PolylineGlowMaterialProperty({
            color: Cesium.Color.WHile
          }),
          width: 2
        }
      });
      window.viewer.zoomTo(entity[id]);
    },
    /**
     * @startpath: 绘制path entity对象
     * @param {*} index  :对entity唯一个标识
     * @return {*}
     */
    gentimeentiti(index) {
      let PolylinesArray = [];
      window.viewer.entities.add({
        polyline: {
          positions: new Cesium.CallbackProperty(() => {
            //监听时间轴函数
            window.viewer.clock.onTick.addEventListener(function(clock) {
              PolylinesArray = [
                //飞艇的获取当前时间的经纬度
                entity[index].position.getValue(clock._currentTime),
                //获取船的当前的时间经纬度
                entity[10].position.getValue(clock._currentTime)
              ];
            });
            if (PolylinesArray.length != 0) return PolylinesArray;
          }, false),
          width: 1,
          material: Cesium.Color.YELLOW
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.btn {
  position: absolute;
  z-index: 999;
  top: 20px;
}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我可以帮你实现并展示NW小世界模型构建,并计算平均路径长度和聚类系数。 首先,NW小世界模型由两个部分构成:一个规则网络和一个随机网络。规则网络是一个正则的网格,每个节点与其周围的k个节点相连。随机网络是通过随机重连规则网络中的边来构建的。 我们可以使用Python中的networkx库来实现NW小世界模型。首先,我们需要导入库并创建规则网络: ```python import networkx as nx # 创建规则网络 n = 100 # 网络中节点的数量 k = 4 # 每个节点与周围k个节点相连 p = 0.1 # 重连概率 G = nx.watts_strogatz_graph(n, k, p) ``` 接下来,我们需要对规则网络进行重连,以创建随机网络: ```python # 重连规则网络中的边,以创建随机网络 for u, v in G.edges(): if (u < v) and (not G.has_edge(u, v)): if nx.utils.uniform(0, 1) < p: w = nx.utils.discrete_sequence(2, p=0.5)[0] G.remove_edge(u, v) G.add_edge(u, w) ``` 现在,我们已经创建了一个NW小世界模型。接下来,我们可以计算平均路径长度和聚类系数。平均路径长度是网络中所有节点对之间的最短路径长度的平均值。聚类系数是网络中节点的聚集程度的度量,它表示一个节点的邻居之间有多少条边。 ```python # 计算平均路径长度和聚类系数 avg_path_length = nx.average_shortest_path_length(G) clustering_coefficient = nx.average_clustering(G) print("平均路径长度:", avg_path_length) print("聚类系数:", clustering_coefficient) ``` 最后,我们可以可视化这个NW小世界模型,以便更好地理解它: ```python import matplotlib.pyplot as plt # 可视化NW小世界模型 nx.draw_networkx(G) plt.show() ``` 这样,我们就完成了NW小世界模型的构建、计算平均路径长度和聚类系数,并可视化了这个模型

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白学过的代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值