husq
2023-10-17 7abab3d5474858f58ddd96bebbdf0379ddd1aa77
飞机起飞时实时位置更新
4 files modified
67 ■■■■ changed files
src/hooks/use-cesium-tsa.ts 29 ●●●●● patch | view | raw | blame | history
src/pages/page-web/projects/tsa.vue 26 ●●●● patch | view | raw | blame | history
src/types/device.ts 3 ●●●●● patch | view | raw | blame | history
src/utils/jobTime.ts 9 ●●●● patch | view | raw | blame | history
src/hooks/use-cesium-tsa.ts
@@ -27,6 +27,9 @@
  billboard?: billboardSetting
  label?: labelSetting
  id?: string
  heading?: number
  pitch?: number
  roll?: number
}
// 定义全局的viewer变量防止重复生成
// eslint-disable-next-line no-var
@@ -140,12 +143,15 @@
  // 添加标记点
  const addPoint = (pointOption: pointOption) => {
    if (!pointOption.longitude && !pointOption.latitude) return
    const position = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude)
    const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(pointOption.heading, pointOption.pitch, pointOption.roll))
    viewer?.entities.add({
      position: Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude),
      billboard: pointOption.billboard,
      point: pointOption.point,
      label: pointOption.label,
      id: pointOption.id,
      orientation
    })
  }
@@ -157,7 +163,24 @@
      viewer?.entities.remove(pointEntity)
    }
  }
  // 通过点ID获取实体
  function getEntityById (id:string) {
    const pointEntity = viewer?.entities.getById(id)
    return pointEntity
  }
  // 更新实体位置
  function updateEntityPosition (longitude:number, latitude:number, id:string, params?:any) {
    const entity = getEntityById(id) as Cesium.Entity
    const position = Cesium.Cartesian3.fromDegrees(longitude, latitude)
    const heading = Cesium.Math.toRadians(params.heading)
    const pitch = Cesium.Math.toRadians(params.pitch)
    const roll = Cesium.Math.toRadians(params.roll)
    const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(heading, pitch, roll))
    if (Cesium.defined(entity)) {
      entity.position = position
      entity.orientation = orientation
    }
  }
  // 飞行 flyto
  const flyTo = (pointOption: pointOption, time: number = 4) => {
    if (!pointOption.longitude && !pointOption.latitude) return
@@ -256,6 +279,8 @@
    zoonIn,
    zoonOut,
    roadPattern,
    patternMap
    patternMap,
    getEntityById,
    updateEntityPosition
  }
}
src/pages/page-web/projects/tsa.vue
@@ -266,7 +266,6 @@
<script lang="ts" setup>
import { computed, onMounted, reactive, ref, watch, WritableComputedRef } from 'vue'
import { EDeviceTypeName, ELocalStorageKey } from '/@/types'
import noData from '/@/assets/icons/no-data.png'
import rc from '/@/assets/icons/rc.png'
import { OnlineDevice, EModeCode, OSDVisible, EDockModeCode, DeviceOsd, EDockModeText, EModeText } from '/@/types/device'
import { useMyStore } from '/@/store'
@@ -280,6 +279,7 @@
} from '@ant-design/icons-vue'
import { EHmsLevel } from '/@/types/enums'
import { cesiumOperation } from '/@/hooks/use-cesium-tsa'
let droneEntity
const { appContext } = getCurrentInstance()
const global = appContext.config.globalProperties
@@ -326,28 +326,46 @@
const cesium = cesiumOperation()
// 添加机场标注
watch(() => store.state.deviceState, data => {
  if (snCode.value.includes(data.currentSn)) return
  snCode.value.push(data.currentSn)
  // cesium.removeAllPoint()
  if (data.currentType === EDeviceTypeName.Aircraft && data.deviceInfo[data.currentSn]) {
    // cesium.removeById('drone_fly')
    if (!droneEntity) {
      droneEntity = cesium.getEntityById('drone_fly')
    }
    console.log(data.deviceInfo[data.currentSn], '====deviceInfo====')
    if (droneEntity) {
      const orientation = {
        heading: data.deviceInfo[data.currentSn].attitude_head,
        pitch: data.deviceInfo[data.currentSn].attitude_pitch,
        roll: data.deviceInfo[data.currentSn].attitude_roll
      }
      cesium.updateEntityPosition(data.deviceInfo[data.currentSn].longitude, data.deviceInfo[data.currentSn].latitude, 'drone_fly', orientation)
    } else {
    // 无人机图标
    const setting = {
      longitude: data.deviceInfo[data.currentSn].longitude,
      latitude: data.deviceInfo[data.currentSn].latitude,
        id: 'drone_fly',
      billboard: {
        image: getResource('drone.png'),
        outlineWidth: 0,
        width: 36,
        height: 36,
        scale: 1.0,
      }
        },
        heading: data.deviceInfo[data.currentSn].attitude_head,
        pitch: data.deviceInfo[data.currentSn].attitude_pitch,
        roll: data.deviceInfo[data.currentSn].attitude_roll
    }
    cesium.addPoint(setting)
    }
    // if (osdVisible.value.visible && osdVisible.value.sn !== '') {
    //   deviceInfo.value.device = data.deviceInfo[osdVisible.value.sn]
    // }
  }
  if (data.currentType === EDeviceTypeName.Dock && data.dockInfo[data.currentSn]) {
    if (snCode.value.includes(data.currentSn)) return
    snCode.value.push(data.currentSn)
    // 机场图标位置
    const setting = {
      longitude: data.dockInfo[data.currentSn].basic_osd?.longitude,
src/types/device.ts
@@ -265,6 +265,9 @@
}
export interface DeviceOsd {
  attitude_head?:number,
  attitude_pitch?:number,
  attitude_roll?:number,
  longitude: number,
  latitude: number,
  gear: number,
src/utils/jobTime.ts
@@ -8,7 +8,6 @@
 * @param creatPlan
 */
export function getFlyTimeList (creatPlan: CreatePlan) {
  const startDate = moment.unix(creatPlan.task_days[0]).toDate()
  const endDate = moment.unix(creatPlan.task_days[1]).toDate()
@@ -135,7 +134,6 @@
              }
              creatPlan.task_periods?.forEach(timearr => {
                timearr.forEach(time=>{
                  const timeStr = moment.unix(time).format('HH:mm')
                  const str = date + '-' + day + ' ' + timeStr
@@ -178,7 +176,6 @@
            const tmpDate = new Date(yearMonth)
            const date = getMonthWeek(tmpDate.getFullYear(), tmpDate.getMonth(), creatPlan.rep_rule_val[0], creatPlan.rep_rule_val[1])
            creatPlan.task_periods?.forEach(timearr => {
              timearr.forEach(time=>{
                const timeStr = moment.unix(time).format('HH:mm')
                const dateStr = date + ' ' + timeStr
@@ -201,12 +198,10 @@
        // 拼接时间
        dateList.forEach(date => {
          creatPlan.task_periods?.forEach(timearr => {
            timearr.forEach(time=>{
              const timeStr = moment.unix(time).format('HH:mm')
              finalDateTimeArr.push(date + ' ' + timeStr)
            })
          })
        })
        break
@@ -223,7 +218,6 @@
              finalDateTimeArr.push(date + ' ' + timeStr)
            })
          })
        })
        break
@@ -232,7 +226,7 @@
  }
  console.log('最终时间:', finalDateTimeArr)
  var tempDateTimeArr = []
  let tempDateTimeArr = []
  if (creatPlan.task_type === TaskType.Repeat) {
    tempDateTimeArr =  finalDateTimeArr.map(dateTime=>[dateTime])
  }else if (creatPlan.task_type === TaskType.Continuous){
@@ -240,7 +234,6 @@
      tempDateTimeArr.push([finalDateTimeArr[i],finalDateTimeArr[i+1]])
    }
  }
  // 对tempDateTimeArr进行时间过滤,筛选掉过去时间和无效时间
  const futureDateTimeArr = tempDateTimeArr.filter(dateArr => {