撤回 布局修改 任务点击的接口格式修改
This commit is contained in:
@@ -40,6 +40,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
const polygonRef = useRef(null); // coverage 区域多边形
|
||||
const navLineRef = useRef(null); // 完成点实时轨迹
|
||||
const markedPointsRef = useRef([]); // 标记点实体
|
||||
const markedLineRef = useRef(null); // 标记点连线实体
|
||||
const onMarkPointRef = useRef(onMarkPoint); // 总是指向最新的 onMarkPoint,避免闭包滞后
|
||||
const onCameraClickRef = useRef(onCameraClick); // 同样处理,避免闭包滞后
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
@@ -474,19 +477,41 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
}
|
||||
}, [points]);
|
||||
|
||||
// 渲染绿色标记点
|
||||
// 渲染标记点 + 连线(唯一系统,避免重复标记)
|
||||
const drawMarkedPoints = (points) => {
|
||||
const viewer = viewerRef.current;
|
||||
if (!viewer) return;
|
||||
|
||||
// 先清空之前的标记点
|
||||
// 先清空之前的标记点与连线
|
||||
markedPointsRef.current.forEach(id => {
|
||||
viewer.entities.removeById(id);
|
||||
});
|
||||
markedPointsRef.current = [];
|
||||
|
||||
if (markedLineRef.current) {
|
||||
try {
|
||||
viewer.entities.remove(markedLineRef.current);
|
||||
} catch (e) { }
|
||||
markedLineRef.current = null;
|
||||
}
|
||||
|
||||
if (!points || points.length === 0) return;
|
||||
|
||||
// 先绘制连线:有 2 个及以上打点才连线
|
||||
if (points.length >= 2) {
|
||||
const linePositions = points.map(p =>
|
||||
window.Cesium.Cartesian3.fromDegrees(Number(p.lon), Number(p.lat))
|
||||
);
|
||||
markedLineRef.current = viewer.entities.add({
|
||||
polyline: {
|
||||
positions: linePositions,
|
||||
width: 4,
|
||||
material: window.Cesium.Color.SKYBLUE,
|
||||
clampToGround: true,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
points.forEach((p, i) => {
|
||||
const id = `marked-point-${i}`;
|
||||
viewer.entities.add({
|
||||
@@ -1627,6 +1652,10 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
};
|
||||
}, [points]);
|
||||
|
||||
// 每次渲染都更新回调引用,确保单击处理器用最新版本(避免闭包滞后)
|
||||
onMarkPointRef.current = onMarkPoint;
|
||||
onCameraClickRef.current = onCameraClick;
|
||||
|
||||
useEffect(() => {
|
||||
const viewer = viewerRef.current;
|
||||
if (!viewer) return;
|
||||
@@ -1650,7 +1679,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
const picked = viewer.scene.pick(movement.position);
|
||||
if (window.Cesium.defined(picked) && picked.id?.properties?.robot) {
|
||||
const robot = picked.id.properties.robot.getValue();
|
||||
robot.feStatus == 1 && onCameraClick?.(robot);
|
||||
robot.feStatus == 1 && onCameraClickRef.current?.(robot);
|
||||
}
|
||||
}, window.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
|
||||
@@ -1663,10 +1692,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
const lon = window.Cesium.Math.toDegrees(cartographic.longitude);
|
||||
const lat = window.Cesium.Math.toDegrees(cartographic.latitude);
|
||||
const newPoint = { lon, lat };
|
||||
const newPoints = [...drawPoints, newPoint];
|
||||
setDrawPoints(newPoints);
|
||||
updateDrawPath(newPoints);
|
||||
onMarkPoint?.({ lon, lat });
|
||||
onMarkPointRef.current?.({ lon, lat });
|
||||
}, window.Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
|
||||
if (onClearDraw) {
|
||||
|
||||
Reference in New Issue
Block a user