Browse Source

模型移动

wuxiang 1 year ago
parent
commit
8f454bf968
1 changed files with 29 additions and 8 deletions
  1. 29 8
      src/views/simulation/index.vue

+ 29 - 8
src/views/simulation/index.vue

@@ -761,7 +761,7 @@ export default {
         const currentTime = clock.currentTime; // 获取当前时间轴的时间
         const elapsedTime = this.Cesium.JulianDate.secondsDifference(
           currentTime,
-          this.viewer2D.clock.startTime
+          this.viewer3D.clock.startTime
         ); // 获取从起始时间到当前时间的秒数
         if (parseInt(elapsedTime) % stepTime === 0 && elapsedTime!=0) {
           console.log('elapsedTime :>> ', elapsedTime);
@@ -778,10 +778,10 @@ export default {
       //   .get("/api", this.jsonData).then(res=>{
       //     console.log('res :>> ', res);
       //   })
-      await axios
-        .post("/api/traj", this.jsonData).then(res=>{
-          console.log('res :>> ', res);
-        })
+      // await axios
+      //   .post("/api/traj", this.jsonData).then(res=>{
+      //     console.log('res :>> ', res);
+      //   })
 
     },
     // 根据时间参数请求模型位置并更新 2D
@@ -794,17 +794,38 @@ export default {
       await axios
         .post("/api/pos", {simulation_time: newTimeString+'.000'}).then(res=>{
           console.log('res :>> ', res);
+          //更新模型位置
+          // this.modelEntityMoveByIDAndLocation(this.viewer2D,"1654426964397658112",res.data[1].data.W1.x,res.data[1].data.W1.y,res.data[1].data.W1.z)
         })
+        
     },
      // 根据时间参数请求模型位置并更新 3D
-     requestDataAndUpdateModel3D(startTime, elapsedTime) {
+     async requestDataAndUpdateModel3D(startTime, elapsedTime) {
       const jsDate = new Date(startTime);
       // 增加 elapsedTime 秒
       jsDate.setSeconds(jsDate.getSeconds() + elapsedTime);
       // 转换为需求字符串格式
       const newTimeString = `${jsDate.getFullYear()}-${(jsDate.getMonth() + 1).toString().padStart(2, '0')}-${jsDate.getDate().toString().padStart(2, '0')} ${jsDate.getHours().toString().padStart(2, '0')}:${jsDate.getMinutes().toString().padStart(2, '0')}:${jsDate.getSeconds().toString().padStart(2, '0')}`;
-     
-    }
+      await axios
+        .post("/api/pos", {simulation_time: newTimeString+'.000'}).then(res=>{
+          console.log('res :>> ', res);
+           //更新模型位置
+          //  this.modelEntityMoveByIDAndLocation(this.viewer3D,viewer,"1654426964397658112",res.data[1].data.W1.x,res.data[1].data.W1.y,res.data[1].data.W1.z)  
+        })
+        
+    },
+     // 根据模型实体Id和终点位置进行移动
+     modelEntityMoveByIDAndLocation(viewer,id,x,y,z) {
+      
+        let entity = viewer.entities.getById(id)
+        //终点位置
+        let position = new this.Cesium.Cartesian3(x, y, z);
+        //设置方向,根据实体的位置来配置方向
+        entity.orientation = new this.Cesium.VelocityOrientationProperty(entity.position);
+        //设置查看器,让模型动起来
+        entity.position.setValue(position)
+
+     }
   }
 };
 </script>