bug fix
This commit is contained in:
95
src/App.vue
95
src/App.vue
@@ -159,6 +159,7 @@ const wsConnected = ref(false)
|
|||||||
const droneData = ref(null)
|
const droneData = ref(null)
|
||||||
const isFlying = ref(false)
|
const isFlying = ref(false)
|
||||||
const droneMarker = ref(null)
|
const droneMarker = ref(null)
|
||||||
|
const drone2Marker = ref(null)
|
||||||
let wsClient = null
|
let wsClient = null
|
||||||
let mockDataGenerator = null
|
let mockDataGenerator = null
|
||||||
const isInFence = ref(true)
|
const isInFence = ref(true)
|
||||||
@@ -235,28 +236,28 @@ let conn = null;
|
|||||||
// 初始化WebSocket连接
|
// 初始化WebSocket连接
|
||||||
const initWebSocket = () => {
|
const initWebSocket = () => {
|
||||||
// 使用模拟数据生成器(因为目前没有真实WebSocket服务器)
|
// 使用模拟数据生成器(因为目前没有真实WebSocket服务器)
|
||||||
mockDataGenerator = new MockWebSocketDataGenerator({
|
// mockDataGenerator = new MockWebSocketDataGenerator({
|
||||||
interval: 500, // 内部500ms生成一次数据(用于平滑)
|
// interval: 500, // 内部500ms生成一次数据(用于平滑)
|
||||||
startLat: 39.90923, // 北京天安门附近
|
// startLat: 39.90923, // 北京天安门附近
|
||||||
startLng: 116.397428,
|
// startLng: 116.397428,
|
||||||
speed: 0.00005 // 移动速度
|
// speed: 0.00005 // 移动速度
|
||||||
})
|
// })
|
||||||
|
|
||||||
// 监听数据(使用节流,大幅降低更新频率)
|
// // 监听数据(使用节流,大幅降低更新频率)
|
||||||
mockDataGenerator.start((data) => {
|
// mockDataGenerator.start((data) => {
|
||||||
const now = Date.now()
|
// const now = Date.now()
|
||||||
// 只更新数据状态,不触发地图更新
|
// // 只更新数据状态,不触发地图更新
|
||||||
droneData.value = data
|
// droneData.value = data
|
||||||
|
|
||||||
// 节流:降低地图更新频率
|
// // 节流:降低地图更新频率
|
||||||
if (now - lastUpdateTime >= UPDATE_INTERVAL) {
|
// if (now - lastUpdateTime >= UPDATE_INTERVAL) {
|
||||||
lastUpdateTime = now
|
// lastUpdateTime = now
|
||||||
handleDroneData(data)
|
// handleDroneData(data)
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
|
|
||||||
wsConnected.value = true
|
wsConnected.value = true
|
||||||
ElMessage.success('无人机数据连接成功(模拟模式)')
|
ElMessage.success('无人机数据连接成功')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 起飞处理
|
// 起飞处理
|
||||||
@@ -299,8 +300,22 @@ const toggleWebSocket = () => {
|
|||||||
initWebSocket()
|
initWebSocket()
|
||||||
conn = ctrl.Message();
|
conn = ctrl.Message();
|
||||||
conn.onDroneGPS = (data) => {
|
conn.onDroneGPS = (data) => {
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
droneMarker.value.setPosition([data.longitude, data.latitude])
|
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])
|
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 isPointInPolygon = (point, polygon) => {
|
||||||
const [x, y] = point
|
const [x, y] = point
|
||||||
@@ -1076,6 +1127,10 @@ onUnmounted(() => {
|
|||||||
map?.remove(droneMarker.value)
|
map?.remove(droneMarker.value)
|
||||||
droneMarker.value = null
|
droneMarker.value = null
|
||||||
}
|
}
|
||||||
|
if (drone2Marker.value) {
|
||||||
|
map?.remove(drone2Marker.value)
|
||||||
|
drone2Marker.value = null
|
||||||
|
}
|
||||||
|
|
||||||
if (mouseTool) {
|
if (mouseTool) {
|
||||||
mouseTool.close()
|
mouseTool.close()
|
||||||
|
|||||||
@@ -98,8 +98,9 @@ function upload(url, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// export let host = `${window.location.protocol}//${window.location.host}`;
|
// 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://192.168.3.81:5678";
|
||||||
|
// export let host = "http://127.0.0.1:5678";
|
||||||
|
|
||||||
export const getConfig = () => {
|
export const getConfig = () => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user