feat: 1:二维码统计明细 2:航线规划
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState, useCallback, useMemo } from 'react';
|
||||
import { message, Button, Tooltip } from 'antd';
|
||||
import { AppstoreOutlined, BarsOutlined } from '@ant-design/icons';
|
||||
import { AppstoreOutlined, BarsOutlined, ProfileOutlined, EditOutlined } from '@ant-design/icons';
|
||||
import RightPanel from './3d/BottomPanel/RightPanel';
|
||||
import LeftControlPanel from './3d/BottomPanel/LeftControlPanel';
|
||||
import TaskPanel from './3d/BottomPanel/TaskPanel';
|
||||
@@ -32,6 +32,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const viewerRef = useRef<any>(null);
|
||||
const entitiesRef = useRef<Map<string, any>>(new Map());
|
||||
const pickHandlerRef = useRef<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [viewerReady, setViewerReady] = useState(false); // 新增:viewer 是否完全就绪
|
||||
|
||||
@@ -52,9 +53,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 航线规划面板状态(无人船)
|
||||
const [routePlanningVisible, setRoutePlanningVisible] = useState(false);
|
||||
const [routePlanningDevice, setRoutePlanningDevice] = useState<any>(null);
|
||||
const [routePlanningBoundaryId, setRoutePlanningBoundaryId] = useState<string | null>(null);
|
||||
|
||||
// 边界编辑面板状态(水域边界)
|
||||
const [boundaryEditorVisible, setBoundaryEditorVisible] = useState(false);
|
||||
const [autoShowBoundaryId, setAutoShowBoundaryId] = useState<string | null>(null);
|
||||
|
||||
// 图层管理面板状态
|
||||
const [layerPanelVisible, setLayerPanelVisible] = useState(false);
|
||||
@@ -288,12 +291,14 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
// 使用较短的动画时间,因为相机已经在设备附近了
|
||||
if (firstTileset && viewerRef.current && !viewerRef.current.isDestroyed?.()) {
|
||||
try {
|
||||
const radius = Number(firstTileset?.boundingSphere?.radius);
|
||||
const range = Number.isFinite(radius) && radius > 0 ? Math.max(40, radius * 0.7) : 80;
|
||||
viewerRef.current.flyTo(firstTileset, {
|
||||
duration: 1.0, // 缩短动画时间,因为已经在附近
|
||||
duration: 0.8, // 缩短动画时间,因为已经在附近
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
Cesium.Math.toRadians(0),
|
||||
Cesium.Math.toRadians(-45),
|
||||
0
|
||||
Cesium.Math.toRadians(-70), // 改为70度俯视,更接近垂直俯视
|
||||
range
|
||||
),
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -410,6 +415,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const handleOpenRoutePlanning = useCallback((device: any) => {
|
||||
setRoutePlanningDevice(device);
|
||||
setRoutePlanningVisible(true);
|
||||
setRoutePlanningBoundaryId(null);
|
||||
// 关闭其他面板
|
||||
setRightPanelVisible(false);
|
||||
}, []);
|
||||
@@ -418,27 +424,58 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
const handleCloseRoutePlanning = useCallback(() => {
|
||||
setRoutePlanningVisible(false);
|
||||
setRoutePlanningDevice(null);
|
||||
}, []);
|
||||
setRoutePlanningBoundaryId(null);
|
||||
// 退出后恢复右侧面板入口
|
||||
if (selectedDevice) {
|
||||
setRightPanelVisible(true);
|
||||
}
|
||||
}, [selectedDevice]);
|
||||
|
||||
// 航线保存成功回调
|
||||
const handleRoutesSaveSuccess = useCallback((routeId: string) => {
|
||||
message.success('航线保存成功');
|
||||
setRoutePlanningVisible(false);
|
||||
setRoutePlanningDevice(null);
|
||||
// 保持航线规划面板不关闭:由 RouteEditor 内部切回“航线库”并刷新列表
|
||||
// 这里保留回调入口,便于后续做跨面板联动
|
||||
void routeId;
|
||||
}, []);
|
||||
|
||||
// 从图层管理面板:基于边界快速进入航线规划(仅可航行边界)
|
||||
const handleOpenRoutePlanningByBoundary = useCallback((boundary: any) => {
|
||||
if (!selectedDevice) {
|
||||
message.warning('请先选择设备');
|
||||
return;
|
||||
}
|
||||
const boundaryId = String(boundary?.boundaryId || '').trim();
|
||||
if (!boundaryId) {
|
||||
message.warning('边界ID无效,无法进入航线规划');
|
||||
return;
|
||||
}
|
||||
setRoutePlanningDevice(selectedDevice);
|
||||
setRoutePlanningVisible(true);
|
||||
setRoutePlanningBoundaryId(boundaryId);
|
||||
setLayerPanelVisible(false);
|
||||
setRightPanelVisible(false);
|
||||
}, [selectedDevice]);
|
||||
|
||||
// 处理从图层管理面板点击"新建边界"
|
||||
const handleOpenBoundaryEditor = useCallback(() => {
|
||||
const sn = String(selectedDevice?.deviceSn || '').trim();
|
||||
if (!sn) {
|
||||
message.warning('请先选择设备后再新建边界');
|
||||
return;
|
||||
}
|
||||
setBoundaryEditorVisible(true);
|
||||
// 关闭其他面板
|
||||
setLayerPanelVisible(false);
|
||||
setRightPanelVisible(false);
|
||||
}, []);
|
||||
}, [selectedDevice]);
|
||||
|
||||
// 关闭边界编辑器
|
||||
const handleCloseBoundaryEditor = useCallback(() => {
|
||||
setBoundaryEditorVisible(false);
|
||||
}, []);
|
||||
if (selectedDevice) {
|
||||
setRightPanelVisible(true);
|
||||
}
|
||||
}, [selectedDevice]);
|
||||
|
||||
// 边界保存成功回调
|
||||
const handleBoundarySaveSuccess = useCallback((boundaryId: string) => {
|
||||
@@ -446,7 +483,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
setBoundaryEditorVisible(false);
|
||||
// 重新打开图层管理面板,显示新创建的边界
|
||||
setLayerPanelVisible(true);
|
||||
}, []);
|
||||
setAutoShowBoundaryId(boundaryId);
|
||||
if (selectedDevice) {
|
||||
setRightPanelVisible(true);
|
||||
}
|
||||
}, [selectedDevice]);
|
||||
|
||||
// 计算无人机实时位置
|
||||
const realtimePosition = useMemo(() => {
|
||||
@@ -638,6 +679,11 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
flyToGlobal();
|
||||
}, [flyToGlobal, unloadAllTilesets, onClearSelection, droneDeviceSn, disconnectDroneSSE, resetDroneData, clearDroneLayers]);
|
||||
|
||||
// 收起到“设备面板”(不清空设备、不卸载模型)
|
||||
const handleRightPanelMinimize = useCallback(() => {
|
||||
setRightPanelVisible(false);
|
||||
}, []);
|
||||
|
||||
// ========== 3D Tiles 模型管理方法 ==========
|
||||
|
||||
// 加载模型
|
||||
@@ -862,9 +908,32 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
if (loading || !viewerRef.current || !Cesium) return;
|
||||
|
||||
const viewer = viewerRef.current;
|
||||
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
||||
if (viewer.isDestroyed?.()) return;
|
||||
|
||||
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
// 清理旧的拾取 handler(React 18 dev 下 effect 可能会触发多次)
|
||||
if (pickHandlerRef.current) {
|
||||
try {
|
||||
pickHandlerRef.current.destroy();
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
pickHandlerRef.current = null;
|
||||
}
|
||||
|
||||
try {
|
||||
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
|
||||
let handler: any = null;
|
||||
try {
|
||||
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
pickHandlerRef.current = handler;
|
||||
} catch (e) {
|
||||
console.warn('初始化拾取事件失败:', e);
|
||||
return;
|
||||
}
|
||||
|
||||
handler.setInputAction((movement: any) => {
|
||||
const pickedObject = viewer.scene.pick(movement.position);
|
||||
@@ -893,7 +962,14 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
||||
|
||||
return () => {
|
||||
handler.destroy();
|
||||
if (pickHandlerRef.current === handler) {
|
||||
try {
|
||||
handler.destroy();
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
pickHandlerRef.current = null;
|
||||
}
|
||||
document.body.style.cursor = 'default';
|
||||
};
|
||||
}, [loading, handleDeviceSelect]);
|
||||
@@ -964,7 +1040,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
)}
|
||||
|
||||
{/* 3D模型管理按钮 - 当设备有绑定模型时显示 */}
|
||||
{!loading && currentDeviceModels.length > 0 && (
|
||||
{!loading && !boundaryEditorVisible && currentDeviceModels.length > 0 && (
|
||||
<Tooltip title="3D模型管理">
|
||||
<Button
|
||||
type="primary"
|
||||
@@ -981,8 +1057,27 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* 航线规划按钮(无人船) - 放到图层/模型管理同一栏 */}
|
||||
{!loading && !boundaryEditorVisible && selectedDevice?.deviceType === 4 && (
|
||||
<Tooltip title="航线规划">
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleOpenRoutePlanning(selectedDevice)}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 10,
|
||||
right: 130,
|
||||
zIndex: 700,
|
||||
background: routePlanningVisible ? '#00f0ff' : 'rgba(10, 20, 40, 0.9)',
|
||||
borderColor: '#00f0ff',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{/* 图层管理按钮 - 航线和边界图层控制 */}
|
||||
{!loading && selectedDevice && (
|
||||
{!loading && !boundaryEditorVisible && selectedDevice && (
|
||||
<Tooltip title="图层管理">
|
||||
<Button
|
||||
type="primary"
|
||||
@@ -1000,6 +1095,25 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* 设备面板按钮 - 重新打开右侧数据面板 */}
|
||||
{!loading && !boundaryEditorVisible && selectedDevice && (
|
||||
<Tooltip title="设备面板">
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<ProfileOutlined />}
|
||||
onClick={() => setRightPanelVisible(v => !v)}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 10,
|
||||
right: 280,
|
||||
zIndex: 700,
|
||||
background: rightPanelVisible ? '#00f0ff' : 'rgba(10, 20, 40, 0.9)',
|
||||
borderColor: '#00f0ff',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* 3D Tiles模型管理面板 - TODO: TilesetPanel组件未实现,暂时注释 */}
|
||||
|
||||
<TilesetPanel
|
||||
@@ -1028,6 +1142,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
visible={rightPanelVisible}
|
||||
device={selectedDevice}
|
||||
onClose={handleRightPanelClose}
|
||||
onMinimize={handleRightPanelMinimize}
|
||||
onControlClick={handleOpenControl}
|
||||
onTaskPanelOpen={handleOpenTaskPanel}
|
||||
onRoutePlanningOpen={handleOpenRoutePlanning}
|
||||
@@ -1052,36 +1167,31 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||
onClose={() => setLayerPanelVisible(false)}
|
||||
viewer={viewerRef.current}
|
||||
Cesium={Cesium}
|
||||
deviceSn={selectedDevice?.deviceSn}
|
||||
scenicId={selectedDevice?.scenicId}
|
||||
onBoundaryEditorOpen={handleOpenBoundaryEditor}
|
||||
onRoutePlanningOpen={handleOpenRoutePlanningByBoundary}
|
||||
autoShowBoundaryId={autoShowBoundaryId || undefined}
|
||||
onAutoShowBoundaryHandled={() => setAutoShowBoundaryId(null)}
|
||||
/>
|
||||
|
||||
{/* 无人船航线规划面板 */}
|
||||
{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>
|
||||
{/* 无人船航线规划面板 - 浮层形式,不遮挡地图点击 */}
|
||||
{routePlanningVisible && routePlanningDevice && viewerReady && (
|
||||
<RouteEditor
|
||||
scenicId={routePlanningDevice.scenicId || 1}
|
||||
deviceSn={routePlanningDevice.deviceSn}
|
||||
boundaryId={routePlanningBoundaryId || undefined}
|
||||
onSaveSuccess={handleRoutesSaveSuccess}
|
||||
onCancel={handleCloseRoutePlanning}
|
||||
viewerRef={viewerRef}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 水域边界编辑器 - 工具栏浮层形式,不遮挡地图 */}
|
||||
{/* 只有当 viewer 完全就绪后才渲染 */}
|
||||
{boundaryEditorVisible && viewerReady && (
|
||||
{boundaryEditorVisible && viewerReady && !!selectedDevice?.deviceSn && (
|
||||
<BoundaryEditor
|
||||
scenicId={selectedDevice?.scenicId || 1}
|
||||
deviceSn={selectedDevice?.deviceSn}
|
||||
onSaveSuccess={handleBoundarySaveSuccess}
|
||||
onCancel={handleCloseBoundaryEditor}
|
||||
viewerRef={viewerRef}
|
||||
|
||||
Reference in New Issue
Block a user