地图实时显示无人机和机器经纬度
This commit is contained in:
@@ -272,16 +272,7 @@ export default function DeviceStatusPage({
|
||||
}, [persistentDroneData, persistentHostData]);
|
||||
|
||||
// 实时位置数据(用于地图)
|
||||
const realtimePosition = React.useMemo(() => {
|
||||
if (persistentDroneData?.longitude && persistentDroneData?.latitude) {
|
||||
return {
|
||||
lon: persistentDroneData.longitude,
|
||||
lat: persistentDroneData.latitude,
|
||||
heading: persistentDroneData.heading
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}, [persistentDroneData]);
|
||||
|
||||
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
@@ -328,6 +319,34 @@ export default function DeviceStatusPage({
|
||||
);
|
||||
const getVal = (val) => val === "no_rain" ? "无" : (val || '-');
|
||||
|
||||
const realtimePosition = React.useMemo(() => {
|
||||
// 1. 无人机:优先用 MQTT 实时数据
|
||||
if (isUAV) {
|
||||
if (currentDroneData?.longitude && currentDroneData?.latitude) {
|
||||
return {
|
||||
lon: currentDroneData.longitude,
|
||||
lat: currentDroneData.latitude,
|
||||
heading: currentDroneData.heading || 0,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 机器人:从 wsDeviceInfo / runningStatus 取实时经纬度
|
||||
const robotLon = runningStatus.longitude || wsDeviceInfo.longitude;
|
||||
const robotLat = runningStatus.latitude || wsDeviceInfo.latitude;
|
||||
|
||||
if (robotLon && robotLat) {
|
||||
return {
|
||||
lon: robotLon,
|
||||
lat: robotLat,
|
||||
heading: runningStatus.yaw || wsDeviceInfo.yaw || 0,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [isUAV, currentDroneData, runningStatus, wsDeviceInfo]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new DeviceController(userInfo, messageApi);
|
||||
@@ -354,7 +373,7 @@ export default function DeviceStatusPage({
|
||||
}, [userInfo, messageApi]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!device || !controllerRef.current || !device?.serialNumber) return;
|
||||
if (!device || !controllerRef.current || !device?.serialNumber || isUAV) return;
|
||||
|
||||
controllerRef.current.connectDevice(device);
|
||||
}, [device?.serialNumber]);
|
||||
@@ -503,6 +522,11 @@ export default function DeviceStatusPage({
|
||||
return Number(val).toFixed(2);
|
||||
};
|
||||
|
||||
const realtimeType = useMemo(() => {
|
||||
return isUAV ? 'plane' : 'car';
|
||||
}, [isUAV]);
|
||||
|
||||
|
||||
if (!device) {
|
||||
return (
|
||||
<Empty
|
||||
@@ -512,6 +536,7 @@ export default function DeviceStatusPage({
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div style={{ padding: 0 }}>
|
||||
{contextHolder}
|
||||
@@ -702,7 +727,7 @@ export default function DeviceStatusPage({
|
||||
devices={[mapDevices]}
|
||||
points={points}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType="plane"
|
||||
realtimeType={realtimeType}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
@@ -62,6 +62,7 @@ export default class DeviceController {
|
||||
// ========== 【集成】页面切前台重连 ==========
|
||||
handleVisibilityChange() {
|
||||
if (document.visibilityState === 'visible' && this.currentDevice) {
|
||||
if (!this.currentDevice?.serialNumber) return;
|
||||
console.log('✅ 页面切回前台,自动重连 WebSocket');
|
||||
setTimeout(() => {
|
||||
this.connectDevice(this.currentDevice);
|
||||
@@ -75,7 +76,7 @@ export default class DeviceController {
|
||||
if (
|
||||
this.connectedDeviceSn &&
|
||||
this.wsStatus !== 'connected' &&
|
||||
this.currentDevice
|
||||
this.currentDevice?.serialNumber
|
||||
) {
|
||||
console.log('🔄 后台保活:尝试重连 WebSocket');
|
||||
this.connectDevice(this.currentDevice);
|
||||
@@ -116,8 +117,9 @@ export default class DeviceController {
|
||||
|
||||
// 保存当前设备,用于保活/重连
|
||||
this.currentDevice = device;
|
||||
if (!device.serialNumber) return;
|
||||
|
||||
const sn = device.serialNumber || device.device_sn;
|
||||
const sn = device.serialNumber;
|
||||
|
||||
this.connectedDeviceSn = null;
|
||||
this.wsDeviceInfo = {};
|
||||
|
||||
Reference in New Issue
Block a user