This commit is contained in:
2025-12-17 19:23:31 +08:00
parent f7ef53acb6
commit 6a1b23b25e
2 changed files with 77 additions and 21 deletions

View File

@@ -159,6 +159,7 @@ const wsConnected = ref(false)
const droneData = ref(null)
const isFlying = ref(false)
const droneMarker = ref(null)
const drone2Marker = ref(null)
let wsClient = null
let mockDataGenerator = null
const isInFence = ref(true)
@@ -235,28 +236,28 @@ let conn = null;
// 初始化WebSocket连接
const initWebSocket = () => {
// 使用模拟数据生成器因为目前没有真实WebSocket服务器
mockDataGenerator = new MockWebSocketDataGenerator({
interval: 500, // 内部500ms生成一次数据用于平滑
startLat: 39.90923, // 北京天安门附近
startLng: 116.397428,
speed: 0.00005 // 移动速度
})
// mockDataGenerator = new MockWebSocketDataGenerator({
// interval: 500, // 内部500ms生成一次数据用于平滑
// startLat: 39.90923, // 北京天安门附近
// startLng: 116.397428,
// speed: 0.00005 // 移动速度
// })
// 监听数据(使用节流,大幅降低更新频率)
mockDataGenerator.start((data) => {
const now = Date.now()
// 只更新数据状态,不触发地图更新
droneData.value = data
// // 监听数据(使用节流,大幅降低更新频率)
// mockDataGenerator.start((data) => {
// const now = Date.now()
// // 只更新数据状态,不触发地图更新
// droneData.value = data
// 节流:降低地图更新频率
if (now - lastUpdateTime >= UPDATE_INTERVAL) {
lastUpdateTime = now
handleDroneData(data)
}
})
// // 节流:降低地图更新频率
// if (now - lastUpdateTime >= UPDATE_INTERVAL) {
// lastUpdateTime = now
// handleDroneData(data)
// }
// })
wsConnected.value = true
ElMessage.success('无人机数据连接成功(模拟模式)')
ElMessage.success('无人机数据连接成功')
}
// 起飞处理
@@ -299,8 +300,22 @@ const toggleWebSocket = () => {
initWebSocket()
conn = ctrl.Message();
conn.onDroneGPS = (data) => {
console.log(data);
droneMarker.value.setPosition([data.longitude, data.latitude])
// console.log(data);
const drone1 = data.drone_1;
const drone2 = data.drone_2;
const point = gcoord.transform(
[drone1.longitude, drone1.latitude],
gcoord.WGS84, // 当前坐标系
gcoord.GCJ02, // 目标坐标系
);
const point2 = gcoord.transform(
[drone2.longitude, drone2.latitude],
gcoord.WGS84, // 当前坐标系
gcoord.GCJ02, // 目标坐标系
);
console.log(point, point2);
// updateDroneMarker(point[0], point[1], drone1.heading);
// updateDrone2Marker(point2[0], point2[1], drone2.heading);
};
}
}
@@ -366,6 +381,42 @@ const updateDroneMarker = (lng, lat, heading = 0) => {
map.setCenter([lng, lat])
}
// 更新无人机marker
const updateDrone2Marker = (lng, latheading = 0) => {
if (!map || !AMap) return
if (!drone2Marker.value) {
// 创建无人机图标
const icon = new AMap.Icon({
image: droneImage,
size: new AMap.Size(40, 40),
imageSize: new AMap.Size(40, 40),
imageOffset: new AMap.Pixel(0, 0)
})
// 创建marker
drone2Marker.value = new AMap.Marker({
position: [lng, lat],
icon: icon,
zIndex: 100,
title: '侦查机',
offset: new AMap.Pixel(-20, -20),
// 优化:禁用动画,减少性能消耗
animation: 'AMAP_ANIMATION_NONE'
})
map.add(drone2Marker.value)
} else {
// 更新位置
drone2Marker.value.setPosition([lng, lat])
// 更新旋转角度如果有heading数据
if (heading !== undefined) {
drone2Marker.value.setAngle(heading)
}
}
}
// 检测点是否在多边形内(射线法)
const isPointInPolygon = (point, polygon) => {
const [x, y] = point
@@ -1076,6 +1127,10 @@ onUnmounted(() => {
map?.remove(droneMarker.value)
droneMarker.value = null
}
if (drone2Marker.value) {
map?.remove(drone2Marker.value)
drone2Marker.value = null
}
if (mouseTool) {
mouseTool.close()

View File

@@ -98,8 +98,9 @@ function upload(url, params) {
}
// export let host = `${window.location.protocol}//${window.location.host}`;
// export let host = "http://192.168.43.97:5678";
// export let host = "http://192.168.43.98:5678";
export let host = "http://192.168.3.81:5678";
// export let host = "http://127.0.0.1:5678";
export const getConfig = () => {
return {