| | |
| | | import IndexedDBService from '@/utils/indexDB' |
| | | import CreateFrustum from '@/utils/cesium/frustum/CreateFrustum' |
| | | import { useMyStore } from '@/store' |
| | | import { getTwoPointInfo } from '@/api/manage' |
| | | |
| | | const { getEntityById, removeById, globalCesium, addLeftClickEvent, removeLeftClickEvent, flyTo } = cesiumOperation() |
| | | // 无人机实体 |
| | | let droneEntity = null |
| | | |
| | | // 激光实体 |
| | | let laserEntity = null |
| | | |
| | | // 两点之间线实体 |
| | | let twoLineEntity = null |
| | | let myAppEntity = null; |
| | | export function droneFly () { |
| | | const store = useMyStore() |
| | | let deviceInfo = {} // 无人机信息 |
| | |
| | | let lastTime = null |
| | | let viewInfoFrustum = null |
| | | |
| | | // 手机设备定位 |
| | | let me_latitude = 0; |
| | | let me_longitude = 0; |
| | | let me_altitude = 0; |
| | | // 扫射定位 |
| | | let measure_target_longitude = 0; |
| | | let measure_target_latitude = 0; |
| | | let measure_target_altitude = 0; |
| | | |
| | | |
| | | async function initDock(data:any, sn:any, dockSn:any, workspaceId:any, ssLinePath:any, viewDroneInfo:any) { |
| | | // 获取workspaceId |
| | | wId = workspaceId |
| | |
| | | deviceInfo = data.deviceInfo[`${sn}`] |
| | | // 机场信息 |
| | | dockInfo = data.dockInfo[`${dockSn}`] |
| | | // console.log('是吧',dockInfo) |
| | | // console.log('踩踩踩', deviceInfo) |
| | | // console.log('踩踩踩', dockInfo) |
| | | viewDroneInfo = viewDroneInfo |
| | | // console.log('1111', deviceInfo.longitude) |
| | | console.log('导致地图不显示原因1',viewDroneInfo.longitude) |
| | | // 当前飞行任务创建时间 |
| | | if (data.currentType === EDeviceTypeName.Aircraft && deviceInfo) { |
| | | const droneLngLat = { |
| | |
| | | } else { |
| | | initCreateFrustum(deviceInfo, viewDroneInfo) |
| | | } |
| | | // console.log('2222', viewDroneInfo.longitude) |
| | | addFlyGltf( |
| | | viewDroneInfo.longitude, |
| | | viewDroneInfo.latitude, |
| | |
| | | dockInfo, |
| | | ssLinePath |
| | | ) |
| | | // console.log('3333', viewDroneInfo.longitude) |
| | | let domain = sessionStorage.getItem('domain') |
| | | if (domain !== '0') { |
| | | addFlyLaser( |
| | | deviceInfo.payloads[0] |
| | | ) |
| | | } |
| | | setelCamera( |
| | | viewDroneInfo.longitude, |
| | | viewDroneInfo.latitude, |
| | |
| | | } else { |
| | | if (deviceInfo.mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) { |
| | | initCreateFrustum(deviceInfo, viewDroneInfo) |
| | | console.log('4444', viewDroneInfo.longitude) |
| | | addFlyGltf( |
| | | viewDroneInfo.longitude, |
| | | viewDroneInfo.latitude, |
| | |
| | | dockInfo, |
| | | ssLinePath |
| | | ) |
| | | let domain = sessionStorage.getItem('domain') |
| | | if (domain !== '0') { |
| | | addFlyLaser( |
| | | deviceInfo.payloads[0] |
| | | ) |
| | | } |
| | | } |
| | | } |
| | | const imgRightBlue = new URL('@/assets/images/arrow-right-pink.png', import.meta.url).href |
| | |
| | | } |
| | | } |
| | | |
| | | const imgLaser = new URL('@/assets/images/laser.png', import.meta.url).href |
| | | // 增加激光扫射点 |
| | | function addFlyLaser(payloads:any) { |
| | | const startPosition = globalCesium.Cartesian3.fromDegrees( |
| | | me_longitude, me_latitude, 0 |
| | | ) |
| | | const position = globalCesium.Cartesian3.fromDegrees( |
| | | payloads.measure_target_longitude, payloads.measure_target_latitude, payloads.measure_target_altitude |
| | | ) |
| | | measure_target_longitude = payloads.measure_target_longitude; |
| | | measure_target_latitude = payloads.measure_target_latitude; |
| | | measure_target_altitude = payloads.measure_target_altitude; |
| | | |
| | | if (laserEntity && laserEntity != null) { |
| | | laserEntity.position = new globalCesium.CallbackProperty(function () { |
| | | return position |
| | | }, false) |
| | | // laserEntity.orientation = new globalCesium.CallbackProperty(function () { |
| | | // return orientation |
| | | // }, false) |
| | | |
| | | laserEntity.show = true |
| | | |
| | | window.cesiumViewer.scene.requestRender() |
| | | } else { |
| | | laserEntity = window.cesiumViewer.entities.add({ |
| | | position, |
| | | id: 'laser_coordinate', |
| | | billboard: { |
| | | image: imgLaser, |
| | | outlineWidth: 0, |
| | | width: 36, |
| | | height: 36, |
| | | scale: 1.0, |
| | | } |
| | | }) |
| | | } |
| | | removeById('route_two_line') |
| | | twoLineEntity = window.cesiumViewer.entities.add({ |
| | | id: 'route_two_line', |
| | | polyline: { |
| | | positions: new globalCesium.CallbackProperty(() => [startPosition, position], false), |
| | | width: 5, |
| | | material: new globalCesium.PolylineDashMaterialProperty({ |
| | | color: globalCesium.Color.YELLOW, // 虚线颜色 |
| | | dashLength: 6.0, // 虚线段的长度 |
| | | }), |
| | | zIndex: 1, |
| | | clampToGround: false, |
| | | } |
| | | }) |
| | | // 增加激光扫射信息 |
| | | laserEntity.label = new globalCesium.LabelGraphics({ |
| | | text: `目标海拔:${Math.ceil(payloads.measure_target_altitude)}m\n测距距离:${Math.round( |
| | | Math.ceil(payloads.measure_target_distance), |
| | | )}m`, |
| | | font: '13px monospace', |
| | | showBackground: true, |
| | | horizontalOrigin: globalCesium.HorizontalOrigin.CENTER, |
| | | verticalOrigin: globalCesium.VerticalOrigin.BOTTOM, |
| | | disableDepthTestDistance: Number.POSITIVE_INFINITY, |
| | | pixelOffset: new globalCesium.Cartesian2(0, -40), |
| | | show: true, |
| | | }) |
| | | } |
| | | |
| | | function addFlyGltf (lng:any, lat:any, alt:any, payloads:any, attitude_head:any, deviceInfo:any, dockInfo:any, ssLinePath:any) { |
| | | const { gimbal_pitch, gimbal_yaw } = payloads |
| | | const position = globalCesium.Cartesian3.fromDegrees( |
| | |
| | | async function createDroneEntityLabel (entity:any, deviceInfo:any, dockInfo:any, ssLinePath:any) { |
| | | deviceInfo = deviceInfo |
| | | if (currentTaskCreateTime === null) return |
| | | console.log('77777', deviceInfo?.basic_osd?.longitude) |
| | | if (!deviceInfo?.longitude && !deviceInfo?.latitude) return |
| | | if (deviceInfo.mode_code !== 5) { |
| | | currentTaskCreateTime = null |
| | |
| | | heading: attitude_head, |
| | | }) |
| | | } |
| | | |
| | | // 获取手机定位和激光发射定位的高度和距离 |
| | | function getTwoHeightWidth(workspaceId:String) { |
| | | // 国内地图不会为0或者小于0 |
| | | console.log('自身定位经纬度1', me_latitude) |
| | | console.log('自身定位经纬度2', me_longitude) |
| | | console.log('激光扫过定位1', measure_target_latitude) |
| | | console.log('激光扫过定位2', measure_target_longitude) |
| | | if (me_latitude <= 0 || me_longitude <= 0 || measure_target_latitude <= 0 || measure_target_longitude <= 0) return |
| | | getTwoPointInfo(workspaceId,me_latitude,me_longitude,measure_target_latitude,measure_target_longitude).then((res:any) => { |
| | | const heightDifference = res.data.heightDifference |
| | | const distance = res.data.distance |
| | | // 增加激光扫射信息 |
| | | myAppEntity.label = new globalCesium.LabelGraphics({ |
| | | text: `高度:${Math.ceil(heightDifference)}m\n距离:${Math.round( |
| | | Math.ceil(distance), |
| | | )}m`, |
| | | font: '13px monospace', |
| | | showBackground: true, |
| | | horizontalOrigin: globalCesium.HorizontalOrigin.CENTER, |
| | | verticalOrigin: globalCesium.VerticalOrigin.BOTTOM, |
| | | disableDepthTestDistance: Number.POSITIVE_INFINITY, |
| | | pixelOffset: new globalCesium.Cartesian2(0, -40), |
| | | show: true, |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | const meMapSrc = new URL('@/assets/images/me.png', import.meta.url).href |
| | | // 获取手机设备定位 |
| | | function getPhoneLocation(workspaceId:String) { |
| | | if (window.cesiumViewer == null) return |
| | | if (navigator.geolocation) { |
| | | navigator.geolocation.watchPosition((position) => { |
| | | if (me_longitude > 0 && me_longitude == position.coords.longitude && me_latitude > 0 && me_latitude == position.coords.latitude) return |
| | | me_longitude = position.coords.longitude; |
| | | me_latitude = position.coords.latitude; |
| | | me_altitude = position.coords.altitude || 0; |
| | | // 创建一个箭头实体 |
| | | removeById('me_dw') |
| | | myAppEntity = window.cesiumViewer.entities.add({ |
| | | id: 'me_dw', |
| | | position: globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude), |
| | | billboard: { |
| | | image: meMapSrc, // 箭头图片路径 |
| | | width: 30, |
| | | height: 30, |
| | | scale: 1.0, |
| | | } |
| | | }); |
| | | // 查看两条线直接距离和高度 |
| | | getTwoHeightWidth(workspaceId) |
| | | }, (error) => { |
| | | console.error('定位有误:', error); |
| | | }); |
| | | } else { |
| | | console.log('手机不支持.'); |
| | | } |
| | | } |
| | | |
| | | // 点击右边定自身定位 |
| | | function clickPhoneLocation() { |
| | | if (myAppEntity && myAppEntity != null) { |
| | | // 将相机定位到设备位置 只有点击图标才可以执行这里 |
| | | window.cesiumViewer.camera.setView({ |
| | | destination: globalCesium.Cartesian3.fromDegrees( |
| | | Number(me_longitude), |
| | | Number(me_latitude), |
| | | 10000.0, |
| | | ), // 相机高度 |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | return { |
| | | initDock |
| | | initDock, |
| | | getPhoneLocation, |
| | | clickPhoneLocation |
| | | } |
| | | } |