根据模式显示 区域还是线
This commit is contained in:
@@ -27,7 +27,7 @@ const CYAN_GLOW_COLOR = new window.Cesium.Color(
|
|||||||
);
|
);
|
||||||
window.Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmNjk0NjI1MC0wZGYyLTQ1YzItYjJmZi0wY2M5ODEwODllYzIiLCJpZCI6Mzk3MTQxLCJpYXQiOjE3NzI1MjkwMjV9.U6qmakhDgXJVXwLFyWzSxAUOFZRrDkIsRUPP6CCdnKg";
|
window.Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmNjk0NjI1MC0wZGYyLTQ1YzItYjJmZi0wY2M5ODEwODllYzIiLCJpZCI6Mzk3MTQxLCJpYXQiOjE3NzI1MjkwMjV9.U6qmakhDgXJVXwLFyWzSxAUOFZRrDkIsRUPP6CCdnKg";
|
||||||
|
|
||||||
const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint }, ref) => {
|
const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint, routeMode = '', polyPoints }, ref) => {
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const viewerRef = useRef(null);
|
const viewerRef = useRef(null);
|
||||||
const tooltipRef = useRef(null);
|
const tooltipRef = useRef(null);
|
||||||
@@ -37,6 +37,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
const alarmMapRef = useRef(new Map());
|
const alarmMapRef = useRef(new Map());
|
||||||
const iotMapRef = useRef(new Map());
|
const iotMapRef = useRef(new Map());
|
||||||
const planLineRef = useRef(null); // points 规划航线
|
const planLineRef = useRef(null); // points 规划航线
|
||||||
|
const polygonRef = useRef(null); // coverage 区域多边形
|
||||||
const navLineRef = useRef(null); // 完成点实时轨迹
|
const navLineRef = useRef(null); // 完成点实时轨迹
|
||||||
const markedPointsRef = useRef([]); // 标记点实体
|
const markedPointsRef = useRef([]); // 标记点实体
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -203,7 +204,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const validPoints = points.filter(p => {
|
const validPoints = points?.filter(p => {
|
||||||
|
|
||||||
const lon = Number(p.lng);
|
const lon = Number(p.lng);
|
||||||
const lat = Number(p.lat);
|
const lat = Number(p.lat);
|
||||||
@@ -296,6 +297,159 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const drawPolygon = (points) => {
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
if (!viewer) return;
|
||||||
|
const isRealtimeMode = !!(
|
||||||
|
realtimePosition?.lon &&
|
||||||
|
realtimePosition?.lat &&
|
||||||
|
!isNaN(Number(realtimePosition.lon)) &&
|
||||||
|
!isNaN(Number(realtimePosition.lat))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const Cesium = window.Cesium;
|
||||||
|
|
||||||
|
// 每次绘制区域前,先移除上一次绘制的地块
|
||||||
|
if (polygonRef.current) {
|
||||||
|
try {
|
||||||
|
viewer.entities.remove(polygonRef.current);
|
||||||
|
polygonRef.current = null;
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
if (planLineRef.current) {
|
||||||
|
try {
|
||||||
|
viewer.entities.remove(planLineRef.current);
|
||||||
|
planLineRef.current = null;
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
const validPoints = points?.filter(p => {
|
||||||
|
|
||||||
|
const lon = Number(p.lng);
|
||||||
|
const lat = Number(p.lat);
|
||||||
|
return (
|
||||||
|
!isNaN(lon) &&
|
||||||
|
!isNaN(lat) &&
|
||||||
|
Math.abs(lon) < 180 &&
|
||||||
|
Math.abs(lat) < 90 &&
|
||||||
|
lon !== 0 &&
|
||||||
|
lat !== 0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validPoints.length === 0) return;
|
||||||
|
|
||||||
|
const positions = validPoints.map(point =>
|
||||||
|
Cesium.Cartesian3.fromDegrees(
|
||||||
|
Number(point.lng),
|
||||||
|
Number(point.lat)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// coverage(区域覆盖)模式下以多边形 polygon 框绘制,否则为折线
|
||||||
|
const isCoverage = routeMode === 'coverage';
|
||||||
|
|
||||||
|
let trackLine;
|
||||||
|
if (isCoverage) {
|
||||||
|
trackLine = viewer.entities.add({
|
||||||
|
polygon: {
|
||||||
|
hierarchy: positions,
|
||||||
|
material: Cesium.Color.ORANGE.withAlpha(0.2),
|
||||||
|
outline: true,
|
||||||
|
outlineColor: Cesium.Color.ORANGE.withAlpha(0.8),
|
||||||
|
height: 0,
|
||||||
|
clampToGround: true,
|
||||||
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
trackLine = viewer.entities.add({
|
||||||
|
polyline: {
|
||||||
|
positions: positions,
|
||||||
|
width: 2,
|
||||||
|
|
||||||
|
material: Cesium.Color.ORANGE.withAlpha(0.8),
|
||||||
|
clampToGround: true,
|
||||||
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
polygonRef.current = trackLine;
|
||||||
|
|
||||||
|
// ======================
|
||||||
|
// 🚀 非实时模式 -> 自动飞到轨迹
|
||||||
|
// ======================
|
||||||
|
if (!isRealtimeMode) {
|
||||||
|
|
||||||
|
let minLon = 180, maxLon = -180;
|
||||||
|
let minLat = 90, maxLat = -90;
|
||||||
|
|
||||||
|
validPoints.forEach(p => {
|
||||||
|
minLon = Math.min(minLon, p.lng);
|
||||||
|
maxLon = Math.max(maxLon, p.lng);
|
||||||
|
minLat = Math.min(minLat, p.lat);
|
||||||
|
maxLat = Math.max(maxLat, p.lat);
|
||||||
|
});
|
||||||
|
if (getCameraMode() !== "track") return;
|
||||||
|
|
||||||
|
// 单个点
|
||||||
|
if (validPoints.length === 1) {
|
||||||
|
|
||||||
|
|
||||||
|
const p = validPoints[0];
|
||||||
|
viewer.scene.requestRender();
|
||||||
|
viewer.camera.flyTo({
|
||||||
|
destination: Cesium.Cartesian3.fromDegrees(
|
||||||
|
p.lng,
|
||||||
|
p.lat,
|
||||||
|
800
|
||||||
|
),
|
||||||
|
duration: 1.2
|
||||||
|
});
|
||||||
|
viewer.scene.requestRender();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
const rectangle = Cesium.Rectangle.fromDegrees(
|
||||||
|
minLon,
|
||||||
|
minLat,
|
||||||
|
maxLon,
|
||||||
|
maxLat
|
||||||
|
);
|
||||||
|
|
||||||
|
viewer.scene.requestRender();
|
||||||
|
|
||||||
|
viewer.camera.flyTo({
|
||||||
|
destination: rectangle,
|
||||||
|
duration: 1.2
|
||||||
|
});
|
||||||
|
|
||||||
|
viewer.scene.requestRender();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (polyPoints && polyPoints.length > 0) {
|
||||||
|
drawPolygon(polyPoints)
|
||||||
|
} else {
|
||||||
|
// polyPoints 被清空时,移除已绘制的区域
|
||||||
|
const viewer = viewerRef.current;
|
||||||
|
if (viewer && polygonRef.current) {
|
||||||
|
try {
|
||||||
|
viewer.entities.remove(polygonRef.current);
|
||||||
|
polygonRef.current = null;
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [polyPoints])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewerRef.current) {
|
if (viewerRef.current) {
|
||||||
@@ -1032,7 +1186,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const validPoints = tracePoints.filter(p => {
|
const validPoints = tracePoints?.filter(p => {
|
||||||
const lng = Number(p.lng);
|
const lng = Number(p.lng);
|
||||||
const lat = Number(p.lat);
|
const lat = Number(p.lat);
|
||||||
return !isNaN(lng) && !isNaN(lat) && Math.abs(lng) < 180 && Math.abs(lat) < 90 && lng !== 0 && lat !== 0;
|
return !isNaN(lng) && !isNaN(lat) && Math.abs(lng) < 180 && Math.abs(lat) < 90 && lng !== 0 && lat !== 0;
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ export default function RobotTaskPage() {
|
|||||||
const [taskList, setTaskList] = useState([]);
|
const [taskList, setTaskList] = useState([]);
|
||||||
const [arrivedPoint, setArrivedPoint] = useState(null);//完成点
|
const [arrivedPoint, setArrivedPoint] = useState(null);//完成点
|
||||||
const { modal } = App.useApp();
|
const { modal } = App.useApp();
|
||||||
|
const [polyPoints, setPolyPoints] = useState([]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +79,7 @@ export default function RobotTaskPage() {
|
|||||||
|
|
||||||
const [focusLocation, setFocusLocation] = useState(null);
|
const [focusLocation, setFocusLocation] = useState(null);
|
||||||
const [points, setPoints] = useState([]);
|
const [points, setPoints] = useState([]);
|
||||||
|
const [routeMode, setRouteMode] = useState('');
|
||||||
const [clearNavLine, setClearNavLine] = useState(0);
|
const [clearNavLine, setClearNavLine] = useState(0);
|
||||||
const [clearPlanLine, setClearPlanLine] = useState(0);
|
const [clearPlanLine, setClearPlanLine] = useState(0);
|
||||||
|
|
||||||
@@ -410,6 +413,43 @@ export default function RobotTaskPage() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}, [taskPoolList]);
|
}, [taskPoolList]);
|
||||||
|
const getRouteOut = async () => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const res = await getSingleRouteList({ id: selectedPathWork?.id });
|
||||||
|
// coverage(区域覆盖)绘制为多边形,其余为折线/单点
|
||||||
|
const mode = res?.data?.mode;
|
||||||
|
setRouteMode(mode);
|
||||||
|
|
||||||
|
if (res?.code === 200 && res?.data?.jsonData) {
|
||||||
|
let pathPoints = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 尝试解析 JSON
|
||||||
|
pathPoints = res?.data?.jsonData?.path || [];
|
||||||
|
} catch (err) {
|
||||||
|
console.error('解析路线数据失败:', err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pathPoints.length === 0) {
|
||||||
|
utils.message.warning(t('devices.route2'));
|
||||||
|
}
|
||||||
|
|
||||||
|
setPolyPoints(pathPoints);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setPolyPoints([]);
|
||||||
|
setRouteMode('');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('获取路线详情失败:', err);
|
||||||
|
setPolyPoints([]);
|
||||||
|
setRouteMode('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
getRouteOut();
|
||||||
|
}, [selectedPathWork?.id])
|
||||||
// 调用接口获取路线详情
|
// 调用接口获取路线详情
|
||||||
const fetchRouteDetail = async (id) => {
|
const fetchRouteDetail = async (id) => {
|
||||||
console.log(id, "获取正在执行任务的id")
|
console.log(id, "获取正在执行任务的id")
|
||||||
@@ -420,6 +460,7 @@ export default function RobotTaskPage() {
|
|||||||
|
|
||||||
const res = await getTaskPath(params)
|
const res = await getTaskPath(params)
|
||||||
//const res = await getSingleRouteList({ id: selectedPathWork.id });
|
//const res = await getSingleRouteList({ id: selectedPathWork.id });
|
||||||
|
|
||||||
if (res?.code === 200 && res?.data) {
|
if (res?.code === 200 && res?.data) {
|
||||||
let pathPoints = [];
|
let pathPoints = [];
|
||||||
|
|
||||||
@@ -1161,7 +1202,7 @@ export default function RobotTaskPage() {
|
|||||||
extra={
|
extra={
|
||||||
<Space size={4} wrap> {/* Space开启自动换行,小屏按钮自动折行 */}
|
<Space size={4} wrap> {/* Space开启自动换行,小屏按钮自动折行 */}
|
||||||
<Button size="small" icon={<DeleteOutlined />} type="primary" style={{ borderRadius: 4 }} onClick={() => setClearNavLine(v => v + 1)}>{t('devices.clearRealtimeTrack')}</Button>
|
<Button size="small" icon={<DeleteOutlined />} type="primary" style={{ borderRadius: 4 }} onClick={() => setClearNavLine(v => v + 1)}>{t('devices.clearRealtimeTrack')}</Button>
|
||||||
<Button size="small" icon={<DeleteOutlined />} danger style={{ borderRadius: 4 }} onClick={() => { setPoints([]); setClearPlanLine(v => v + 1); }}>{t('devices.clearPlanRoute')}</Button>
|
<Button size="small" icon={<DeleteOutlined />} danger style={{ borderRadius: 4 }} onClick={() => { setPoints([]); setRouteMode(""); setClearPlanLine(v => v + 1); }}>{t('devices.clearPlanRoute')}</Button>
|
||||||
{/*<Button size="small" icon={<PlusOutlined />} style={{ borderRadius: 4 }}>{t('common.addNew')}</Button>
|
{/*<Button size="small" icon={<PlusOutlined />} style={{ borderRadius: 4 }}>{t('common.addNew')}</Button>
|
||||||
<Button size="small" icon={<ImportOutlined />} style={{ borderRadius: 4 }}>{t('common.import')}</Button>
|
<Button size="small" icon={<ImportOutlined />} style={{ borderRadius: 4 }}>{t('common.import')}</Button>
|
||||||
<Button size="small" icon={<NodeIndexOutlined />} style={{ borderRadius: 4 }}>{t('devices.optimize')}</Button>
|
<Button size="small" icon={<NodeIndexOutlined />} style={{ borderRadius: 4 }}>{t('devices.optimize')}</Button>
|
||||||
@@ -1179,12 +1220,14 @@ export default function RobotTaskPage() {
|
|||||||
points={points}
|
points={points}
|
||||||
focusLocation={focusLocation}
|
focusLocation={focusLocation}
|
||||||
realtimePosition={realtimePosition}
|
realtimePosition={realtimePosition}
|
||||||
|
polyPoints={polyPoints}
|
||||||
realtimeType="robot"
|
realtimeType="robot"
|
||||||
from="deviceStatus"
|
from="deviceStatus"
|
||||||
drawRealTime={execute}
|
drawRealTime={execute}
|
||||||
finishPoint={arrivedPoint}
|
finishPoint={arrivedPoint}
|
||||||
ifClearNavLine={clearNavLine}
|
ifClearNavLine={clearNavLine}
|
||||||
ifClearPlanLine={clearPlanLine}
|
ifClearPlanLine={clearPlanLine}
|
||||||
|
routeMode={routeMode}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 机器人状态悬浮面板 - 绝对定位左上角 */}
|
{/* 机器人状态悬浮面板 - 绝对定位左上角 */}
|
||||||
@@ -1840,6 +1883,7 @@ const NewTaskModal = ({ isOpen, onClose, robots, selectedPathWork, handlGetTaskL
|
|||||||
if (selectedPathWork) {
|
if (selectedPathWork) {
|
||||||
setFormData(prev => ({ ...prev, path: selectedPathWork }));
|
setFormData(prev => ({ ...prev, path: selectedPathWork }));
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [selectedPathWork]);
|
}, [selectedPathWork]);
|
||||||
|
|
||||||
// ====================== 周/月选择 ======================
|
// ====================== 周/月选择 ======================
|
||||||
|
|||||||
Reference in New Issue
Block a user