feat: 航线规划以及水域边界标绘
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import React, { useEffect, useRef, useState, useCallback, useMemo } from 'react';
|
||||
import { message, Button, Tooltip } from 'antd';
|
||||
import { AppstoreOutlined } from '@ant-design/icons';
|
||||
import { AppstoreOutlined, BarsOutlined } from '@ant-design/icons';
|
||||
import RightPanel from './3d/BottomPanel/RightPanel';
|
||||
import LeftControlPanel from './3d/BottomPanel/LeftControlPanel';
|
||||
import TaskPanel from './3d/BottomPanel/TaskPanel';
|
||||
import TilesetPanel from './3d/TilesetPanel';
|
||||
import LayerPanel, { LayerPanelProps } from './3d/BottomPanel/LayerPanel';
|
||||
import RouteEditor from '../RouteEditor';
|
||||
import BoundaryEditor from '../BoundaryEditor';
|
||||
import { useTilesetLoader, TilesetConfig } from './3d/hooks/useTilesetLoader';
|
||||
import { useDroneSSE } from './3d/hooks/useDroneSSE';
|
||||
import { getModelsByDeviceSn, convertToTilesetConfig } from '@/services/threeDModel';
|
||||
import TilesetPanel from "@/pages/map3d/components/MapContainer/3d/TilesetPanel";
|
||||
|
||||
// 动态导入Cesium
|
||||
let Cesium: any = null;
|
||||
@@ -30,6 +33,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const viewerRef = useRef<any>(null);
|
||||
const entitiesRef = useRef<Map<string, any>>(new Map());
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [viewerReady, setViewerReady] = useState(false); // 新增:viewer 是否完全就绪
|
||||
|
||||
// 3D 模式专属状态
|
||||
const [selectedDevice, setSelectedDevice] = useState<any>(null);
|
||||
@@ -45,6 +49,16 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const [taskPanelDevice, setTaskPanelDevice] = useState<any>(null);
|
||||
const [taskPanelDockData, setTaskPanelDockData] = useState<any>(null);
|
||||
|
||||
// 航线规划面板状态(无人船)
|
||||
const [routePlanningVisible, setRoutePlanningVisible] = useState(false);
|
||||
const [routePlanningDevice, setRoutePlanningDevice] = useState<any>(null);
|
||||
|
||||
// 边界编辑面板状态(水域边界)
|
||||
const [boundaryEditorVisible, setBoundaryEditorVisible] = useState(false);
|
||||
|
||||
// 图层管理面板状态
|
||||
const [layerPanelVisible, setLayerPanelVisible] = useState(false);
|
||||
|
||||
// 无人机SSE订阅(用于在3D地球上显示无人机位置)
|
||||
const [droneDeviceSn, setDroneDeviceSn] = useState<string>('');
|
||||
const { droneData, connectDroneSSE, disconnectDroneSSE, resetDroneData } = useDroneSSE();
|
||||
@@ -392,6 +406,48 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
setTaskPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 处理从右侧面板点击"航线规划"(无人船)
|
||||
const handleOpenRoutePlanning = useCallback((device: any) => {
|
||||
setRoutePlanningDevice(device);
|
||||
setRoutePlanningVisible(true);
|
||||
// 关闭其他面板
|
||||
setRightPanelVisible(false);
|
||||
}, []);
|
||||
|
||||
// 关闭航线规划面板
|
||||
const handleCloseRoutePlanning = useCallback(() => {
|
||||
setRoutePlanningVisible(false);
|
||||
setRoutePlanningDevice(null);
|
||||
}, []);
|
||||
|
||||
// 航线保存成功回调
|
||||
const handleRoutesSaveSuccess = useCallback((routeId: string) => {
|
||||
message.success('航线保存成功');
|
||||
setRoutePlanningVisible(false);
|
||||
setRoutePlanningDevice(null);
|
||||
}, []);
|
||||
|
||||
// 处理从图层管理面板点击"新建边界"
|
||||
const handleOpenBoundaryEditor = useCallback(() => {
|
||||
setBoundaryEditorVisible(true);
|
||||
// 关闭其他面板
|
||||
setLayerPanelVisible(false);
|
||||
setRightPanelVisible(false);
|
||||
}, []);
|
||||
|
||||
// 关闭边界编辑器
|
||||
const handleCloseBoundaryEditor = useCallback(() => {
|
||||
setBoundaryEditorVisible(false);
|
||||
}, []);
|
||||
|
||||
// 边界保存成功回调
|
||||
const handleBoundarySaveSuccess = useCallback((boundaryId: string) => {
|
||||
message.success('边界保存成功');
|
||||
setBoundaryEditorVisible(false);
|
||||
// 重新打开图层管理面板,显示新创建的边界
|
||||
setLayerPanelVisible(true);
|
||||
}, []);
|
||||
|
||||
// 计算无人机实时位置
|
||||
const realtimePosition = useMemo(() => {
|
||||
if (!droneData) return null;
|
||||
@@ -624,6 +680,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
if (!Cesium) {
|
||||
const cesiumModule = await import('cesium');
|
||||
Cesium = cesiumModule;
|
||||
|
||||
// 将 Cesium 挂载到 window 上,供其他组件使用(如 BoundaryEditor)
|
||||
(window as any).Cesium = cesiumModule;
|
||||
console.log('[CesiumContainer] ✓ Cesium 已挂载到 window');
|
||||
|
||||
const cesiumBaseUrl = process.env.CESIUM_BASE_URL || '/';
|
||||
Cesium.buildModuleUrl.setBaseUrl(`${cesiumBaseUrl}cesium/`);
|
||||
|
||||
@@ -717,11 +778,14 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
setViewerReady(true); // Viewer 初始化完成
|
||||
console.log('[CesiumContainer] ✓ Viewer 初始化完成,viewerReady=true');
|
||||
message.success('3D地图加载完成');
|
||||
} catch (error) {
|
||||
console.error('Cesium初始化失败:', error);
|
||||
message.error('3D地图加载失败');
|
||||
setLoading(false);
|
||||
setViewerReady(false); // 初始化失败
|
||||
}
|
||||
};
|
||||
|
||||
@@ -731,6 +795,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
if (viewerRef.current && !viewerRef.current.isDestroyed()) {
|
||||
viewerRef.current.destroy();
|
||||
}
|
||||
setViewerReady(false); // 清理时重置状态
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -833,6 +898,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
};
|
||||
}, [loading, handleDeviceSelect]);
|
||||
|
||||
// @ts-ignore
|
||||
return (
|
||||
<div style={{ width: '100%', height: '100%', position: 'relative' }}>
|
||||
<div ref={containerRef} style={{ width: '100%', height: '100%' }} />
|
||||
@@ -915,8 +981,27 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{/* 图层管理按钮 - 航线和边界图层控制 */}
|
||||
{!loading && selectedDevice && (
|
||||
<Tooltip title="图层管理">
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<BarsOutlined />}
|
||||
onClick={() => setLayerPanelVisible(!layerPanelVisible)}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 10,
|
||||
right: 230,
|
||||
zIndex: 700,
|
||||
background: layerPanelVisible ? '#00f0ff' : 'rgba(10, 20, 40, 0.9)',
|
||||
borderColor: '#00f0ff',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* 3D Tiles模型管理面板 - TODO: TilesetPanel组件未实现,暂时注释 */}
|
||||
|
||||
{/* 3D Tiles模型管理面板 */}
|
||||
<TilesetPanel
|
||||
visible={tilesetPanelVisible}
|
||||
tilesets={tilesets}
|
||||
@@ -945,6 +1030,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
onClose={handleRightPanelClose}
|
||||
onControlClick={handleOpenControl}
|
||||
onTaskPanelOpen={handleOpenTaskPanel}
|
||||
onRoutePlanningOpen={handleOpenRoutePlanning}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
/>
|
||||
@@ -959,6 +1045,48 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
droneData={droneData}
|
||||
dockData={taskPanelDockData}
|
||||
/>
|
||||
|
||||
{/* 图层管理面板 - 左下角 */}
|
||||
<LayerPanel
|
||||
visible={layerPanelVisible}
|
||||
onClose={() => setLayerPanelVisible(false)}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
scenicId={selectedDevice?.scenicId}
|
||||
onBoundaryEditorOpen={handleOpenBoundaryEditor}
|
||||
/>
|
||||
|
||||
{/* 无人船航线规划面板 */}
|
||||
{routePlanningVisible && routePlanningDevice && (
|
||||
<div style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
zIndex: 1000,
|
||||
background: 'rgba(0, 0, 0, 0.5)',
|
||||
}}>
|
||||
<RouteEditor
|
||||
scenicId={routePlanningDevice.scenicId || 1}
|
||||
deviceSn={routePlanningDevice.deviceSn}
|
||||
onSaveSuccess={handleRoutesSaveSuccess}
|
||||
onCancel={handleCloseRoutePlanning}
|
||||
viewerRef={viewerRef}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 水域边界编辑器 - 工具栏浮层形式,不遮挡地图 */}
|
||||
{/* 只有当 viewer 完全就绪后才渲染 */}
|
||||
{boundaryEditorVisible && viewerReady && (
|
||||
<BoundaryEditor
|
||||
scenicId={selectedDevice?.scenicId || 1}
|
||||
onSaveSuccess={handleBoundarySaveSuccess}
|
||||
onCancel={handleCloseBoundaryEditor}
|
||||
viewerRef={viewerRef}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user