地图实时显示无人机和机器经纬度
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>
|
||||
|
||||
Reference in New Issue
Block a user