From 4ff3eee77b41466d08117970970d01be6e48ffe1 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Fri, 28 Mar 2025 19:02:30 +0800
Subject: [PATCH] Merge branch 'master' of http://139.196.74.78:10010/r/drone/pilot-h5
---
src/views/hooks/droneFly.ts | 411 +++++++++++++++++++++++++++++++---------------------------
1 files changed, 220 insertions(+), 191 deletions(-)
diff --git a/src/views/hooks/droneFly.ts b/src/views/hooks/droneFly.ts
index 98a25ed..3cfebf3 100644
--- a/src/views/hooks/droneFly.ts
+++ b/src/views/hooks/droneFly.ts
@@ -5,11 +5,18 @@
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()
+const { getEntityById, removeById, globalCesium, removeAllPoint, addLeftClickEvent, removeLeftClickEvent, flyTo } = cesiumOperation()
// 无人机实体
let droneEntity = null
+// 激光实体
+let laserEntity = null
+
+// 两点之间线实体
+let twoLineEntity = null
+let myAppEntity = null;
export function droneFly () {
const store = useMyStore()
let deviceInfo = {} // 无人机信息
@@ -28,18 +35,24 @@
let lastTime = null
let viewInfoFrustum = null
- async function initDock(data:any, sn:any, dockSn:any, workspaceId:any, ssLinePath:any, viewDroneInfo:any) {
+ // 手机设备定位
+ let me_latitude = 0;// 28.624647955787974;
+ let me_longitude = 0;//115.85635808986208;
+ let me_altitude = 0;
+ // 扫射定位
+ let measure_target_longitude = 0;//115.85635872364763;
+ let measure_target_latitude = 0;//28.624648387113627;
+ let measure_target_altitude = 0;
+
+
+ async function initDock(data:any, sn:String, dockSn:String, workspaceId:String, ssLinePath:String, 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)
// 当前飞行任务创建时间
if (data.currentType === EDeviceTypeName.Aircraft && deviceInfo) {
const droneLngLat = {
@@ -49,13 +62,13 @@
// 当飞机模型存在
if (droneEntity) {
// 且在空中飞行时,实时更新飞机模型的位置
- if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 16].includes(deviceInfo.mode_code)) {
+ if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 16, 17].includes(deviceInfo.mode_code)) {
if (store.currentAngle == 3) {
viewInfoFrustum?.clear()
} else {
+ // 暂时把视锥代码注释掉
initCreateFrustum(deviceInfo, viewDroneInfo)
}
- // console.log('2222', viewDroneInfo.longitude)
addFlyGltf(
viewDroneInfo.longitude,
viewDroneInfo.latitude,
@@ -66,7 +79,12 @@
dockInfo,
ssLinePath
)
- // console.log('3333', viewDroneInfo.longitude)
+ let domain = sessionStorage.getItem('domain')
+ // if (domain !== '0') {
+ // addFlyLaser(
+ // deviceInfo.payloads[0]
+ // )
+ // }
setelCamera(
viewDroneInfo.longitude,
viewDroneInfo.latitude,
@@ -77,6 +95,9 @@
} else {
removeById('drone_fly')
droneEntity = null
+
+ removeById('me_dw')
+ myAppEntity = null
lastTime = null
viewInfoFrustum?.clear()
@@ -84,11 +105,11 @@
window.cesiumViewer.camera.lookAtTransform(globalCesium.Matrix4.IDENTITY)
store.commit('SET_CURRENTANGLE', 1)
+ removeAllPoint()
}
} else {
- if (deviceInfo.mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
+ if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 17].includes(deviceInfo.mode_code)) {
initCreateFrustum(deviceInfo, viewDroneInfo)
- console.log('4444', viewDroneInfo.longitude)
addFlyGltf(
viewDroneInfo.longitude,
viewDroneInfo.latitude,
@@ -99,10 +120,16 @@
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
- // 无人机路线轨迹,判断是否存在drone_route_remove
+ // 无人机路线轨迹,判断是否存在drone_route_remove
if (getEntityById('drone_route_remove')) {
window.cesiumViewer.entities.add({
name: 'drone_route_remove',
@@ -123,7 +150,6 @@
if (data.deviceInfo[data.currentSn].mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
if (switchSaving) return (switchSaving = false)
- // console.log('5555', data.deviceInfo[data.currentSn].longitude)
const newPositions = globalCesium.Cartesian3.fromDegrees(
data.deviceInfo[data.currentSn].longitude,
data.deviceInfo[data.currentSn].latitude,
@@ -163,9 +189,101 @@
}
if (data.currentType === EDeviceTypeName.Dock && data.dockInfo[data.currentSn]) {
if (!deviceInfo?.basic_osd?.longitude || !deviceInfo?.basic_osd?.latitude) return
- console.log('6666', deviceInfo?.basic_osd?.longitude)
if (snCode.includes(data.currentSn)) return
snCode.push(data.currentSn)
+ }
+ }
+
+ const imgLaser = new URL('@/assets/images/laser.png', import.meta.url).href
+ // 增加激光扫射点
+ function addFlyLaser(payloads:any) {
+ console.log('激光扫射经度',payloads.measure_target_longitude)
+ console.log('激光扫射纬度',payloads.measure_target_latitude)
+ 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.show = true
+ window.cesiumViewer.scene.requestRender()
+ } else {
+ removeById('laser_coordinate')
+ laserEntity = window.cesiumViewer.entities.add({
+ position: new globalCesium.CallbackProperty(() => {
+ return globalCesium.Cartesian3.fromDegrees(
+ payloads.measure_target_longitude,
+ payloads.measure_target_latitude,
+ payloads.measure_target_altitude
+ )
+ }, false),
+ id: 'laser_coordinate',
+ billboard: {
+ image: imgLaser,
+ width: 30,
+ height: 30,
+ scale: 1.0,
+ outlineWidth: 0,
+ }
+ })
+ }
+ // 增加激光扫射信息
+ laserEntity.label = new globalCesium.LabelGraphics({
+ text: `H:${Math.ceil(payloads.measure_target_altitude)}m-L:${Math.round(Math.ceil(payloads.measure_target_distance),)}m`,
+ font: '13px monospace',
+ fillColor: globalCesium.Color.fromCssColorString('red'), // 文字颜色
+ backgroundColor: globalCesium.Color.WHITE, // 背景颜色
+ showBackground: true,
+ horizontalOrigin: globalCesium.HorizontalOrigin.CENTER,
+ verticalOrigin: globalCesium.VerticalOrigin.BOTTOM,
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
+ pixelOffset: new globalCesium.Cartesian2(0, -20),
+ show: true,
+ })
+ console.log('起点',startPosition)
+ console.log('终点',position)
+ if (startPosition && position) {
+ if (twoLineEntity && twoLineEntity != null) {
+ // 如果线实体已存在,只更新位置
+ twoLineEntity.polyline.positions = new globalCesium.CallbackProperty(() => {
+ return [
+ globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, 0),
+ globalCesium.Cartesian3.fromDegrees(
+ payloads.measure_target_longitude,
+ payloads.measure_target_latitude,
+ payloads.measure_target_altitude
+ )
+ ]
+ }, false)
+ } else {
+ // 如果线实体不存在,创建新的线实体
+ twoLineEntity = window.cesiumViewer.entities.add({
+ polyline: {
+ positions: new globalCesium.CallbackProperty(() => {
+ return [
+ globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, 0),
+ globalCesium.Cartesian3.fromDegrees(
+ payloads.measure_target_longitude,
+ payloads.measure_target_latitude,
+ payloads.measure_target_altitude
+ )
+ ]
+ }, false),
+ width: 2,
+ material: globalCesium.Color.fromCssColorString('red'),
+ clampToGround: false,
+ },
+ })
+ }
}
}
@@ -217,180 +335,7 @@
}
// 创建无人机信息
- createDroneEntityLabel(droneEntity, deviceInfo, dockInfo, ssLinePath)
- }
- // 创建无人机信息
- 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
- return
- }
- const executingWayline = store.executingWayline
- if (!executingWayline?.id) return
- if (waylinePoints.length === 0) {
- // 改成获取航线地址
- // const routeRes = await getRoutePlanningUrl(
- // wId,
- // executingWayline.id,
- // )
- // const routeData = routeRes.data
- // if (routeData.code !== 0) return this.$message.error('获取航线信息失败!')
- waylinePoints = await getWaylineFilePoints(ssLinePath)
- }
-
- const nextPoint = waylinePoints[currentWaypointIndex]
- if (!nextPoint) return
- // 两点之间的距离
- console.log('8888', deviceInfo.longitude)
- const devicePosition = globalCesium.Cartesian3.fromDegrees(
- Number(deviceInfo.longitude),
- Number(deviceInfo.latitude),
- 0,
- )
- console.log('9999', nextPoint.longitude)
- const targetPosition = globalCesium.Cartesian3.fromDegrees(
- Number(nextPoint.longitude),
- Number(nextPoint.latitude),
- 0,
- )
- // 距离下个点位的距离
- let distance = globalCesium.Cartesian3.distance(
- devicePosition,
- targetPosition,
- )
- const dockPosition = {
- longitude: dockInfo?.basic_osd?.longitude,
- latitude: dockInfo?.basic_osd?.latitude,
- }
-
- const distArr = waylinePoints.map((lnglat, index) => {
- const { longitude, latitude } = lnglat
- console.log('10000', longitude)
- // 两点之间的距离
- let devicePosition = null
- if (index === 0) {
- devicePosition = globalCesium.Cartesian3.fromDegrees(
- Number(dockPosition.longitude),
- Number(dockPosition.latitude),
- 0,
- )
- } else {
- console.log('110', prevPoint.longitude)
- const prevPoint = waylinePoints[index - 1]
- devicePosition = globalCesium.Cartesian3.fromDegrees(
- Number(prevPoint.longitude),
- Number(prevPoint.latitude),
- 0,
- )
- }
- const targetPosition = globalCesium.Cartesian3.fromDegrees(
- Number(longitude),
- Number(latitude),
- 0,
- )
- let distance = globalCesium.Cartesian3.distance(
- devicePosition,
- targetPosition,
- )
- return Math.round(distance)
- })
- // 计算到达点位和之前点位的总距离
- let sum = null
- if (distArr.length > 2) {
- sum = distArr
- .slice(0, currentWaypointIndex)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0)
- } else {
- sum = distArr.reduce(
- (accumulator, currentValue) => accumulator + currentValue,
- 0,
- )
- }
-
- if (sum == 0) {
- sum = distArr[0]
- }
-
- // 距离机场的位置
- const homeDistance = Math.floor(deviceInfo.home_distance) || 0
- // 速度
- let horizontalSpeed = deviceInfo.horizontal_speed || 0
- if (!droneSpeedArr.includes(horizontalSpeed) && horizontalSpeed > 1) {
- droneSpeedArr.push(horizontalSpeed)
- }
- // 平均速度
- const averageSpeed =
- droneSpeedArr.reduce((sum, current) => sum + current, 0) /
- droneSpeedArr.length
- // 已用时间
- let usedTime = Math.round((new Date().getTime() - currentTaskCreateTime) / 1000) - 30
- let throughDistance = usedTime * averageSpeed
-
- if (throughDistance < 0) {
- throughDistance = 0
- usedTime = 0
- }
- if (isNaN(throughDistance)) {
- throughDistance = 0
- }
- if (isNaN(usedTime)) {
- usedTime = 0
- }
- if (usedTime > 60) {
- const minute = Math.floor(usedTime / 60)
- const second = Math.round(usedTime % 60)
- usedTime = `${minute}m${second}s`
- } else {
- usedTime = Math.round(usedTime) + 's'
- }
-
- if (horizontalSpeed < 5) {
- horizontalSpeed = 10
- }
- // 预计到达下一个航点时间
- let arrivalTime = distance / horizontalSpeed
- if (arrivalTime === Infinity || isNaN(arrivalTime)) {
- arrivalTime = 0
- }
- if (arrivalTime > 60) {
- const minute = Math.floor(arrivalTime / 60)
- const second = Math.round(arrivalTime % 60)
- arrivalTime = `${minute}m${second}s`
- } else {
- arrivalTime = Math.round(arrivalTime) + 's'
- }
- entity.label = new globalCesium.LabelGraphics({
- text: `距离机场水平距离:${homeDistance}m\n距离下一个航点:${Math.round(
- distance,
- )}m\n预计到达下一航点时间:${arrivalTime}\n本次飞行时间:${usedTime}\n本次航线平面里程:${Math.round(
- throughDistance,
- )}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,
- })
- }
- async function getWaylineFilePoints(fileUrl:any) {
- const fileRes = await analyzeKmzFile(fileUrl);
- const waylineContent = await fileRes['fileInfoObj']?.['wpmz/waylines.wpml'];
- const xml = XMLToJSON(waylineContent);
- const placemarkArr = xml?.Document?.Folder.Placemark;
- const points = placemarkArr.map((placemark) => {
- const lnglat = placemark.Point.coordinates?.['#text'].split(',');
- return {
- longitude: lnglat[0],
- latitude: lnglat[1],
- };
- });
- return points;
+ // createDroneEntityLabel(droneEntity, deviceInfo, dockInfo, ssLinePath)
}
function setelCamera (lng, lat, alt, payloads, attitude_head) {
@@ -451,8 +396,9 @@
}
// 创建视锥
function initCreateFrustum (deviceInfo:any, test:any) {
-
- if (!deviceInfo || !deviceInfo.longitude || !deviceInfo.latitude) return
+ // console.log('视锥传参1',deviceInfo)
+ // console.log('视锥传参2',test)
+ if (!deviceInfo || !deviceInfo.longitude || !deviceInfo.latitude || !test.longitude || !test.latitude) return
const attitude_head = 180 + deviceInfo.attitude_head
@@ -475,7 +421,90 @@
heading: attitude_head,
})
}
+
+ // 获取手机定位和激光发射定位的高度和距离
+ function getTwoHeightWidth(workspaceId:String) {
+ 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: `H:${Math.ceil(heightDifference)}m-L:${Math.round(Math.ceil(distance),)}m`,
+ font: '13px monospace',
+ fillColor: globalCesium.Color.fromCssColorString('red'), // 文字颜色
+ backgroundColor: globalCesium.Color.WHITE, // 背景颜色
+ showBackground: true,
+ horizontalOrigin: globalCesium.HorizontalOrigin.CENTER,
+ verticalOrigin: globalCesium.VerticalOrigin.BOTTOM,
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
+ pixelOffset: new globalCesium.Cartesian2(0, -24),
+ 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) {
+ // 如果实体不存在,先创建实体
+ if (!myAppEntity) {
+ myAppEntity = window.cesiumViewer.entities.add({
+ id: 'me_dw',
+ position: new globalCesium.CallbackProperty(() => {
+ return globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude)
+ }, false),
+ billboard: {
+ image: meMapSrc,
+ width: 30,
+ height: 30,
+ scale: 1.0,
+ outlineWidth: 0,
+ }
+ });
+ } else {
+ myAppEntity.position = new globalCesium.CallbackProperty(() => {
+ return globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude)
+ }, false);
+ }
+ 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;
+
+ // 查看两条线直接距离和高度
+ 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
}
}
\ No newline at end of file
--
Gitblit v1.9.3