控制模式 割刀速度 加入 支持删除 返航点和障碍物点
This commit is contained in:
@@ -16,7 +16,7 @@ import * as Cesium from 'cesium';
|
||||
|
||||
import 'cesium/Build/Cesium/Widgets/widgets.css';
|
||||
|
||||
const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint, routeMode = '', polyPoints, mapLayer, activeType, overlayRefreshKey = 0, focusOverlay = null, onObstacleRadiusChange, siteMapInfoId }, ref) => {
|
||||
const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, finishPoint, drawRealTime, realtimePosition, realtimeType, pathPoints = [], devices = [], onCameraClick, focusLocation, points = [], markedPoints = [], onPathChange, from, onClearDraw, onMarkPoint, routeMode = '', polyPoints, mapLayer, activeType, overlayRefreshKey = 0, focusOverlay = null, onObstacleRadiusChange, obstacleShapes = [], onObstacleRectResize, siteMapInfoId }, ref) => {
|
||||
const containerRef = useRef(null);
|
||||
const viewerRef = useRef(null);
|
||||
const tooltipRef = useRef(null);
|
||||
@@ -97,6 +97,49 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
);
|
||||
};
|
||||
|
||||
// 矩形障碍物:以 lon/lat 为中心、长宽(米)为 width/height 的经度纬度矩形
|
||||
const getObstacleRectCoordinates = (lon, lat, width, height) => {
|
||||
const halfWidthDeg =
|
||||
width / 2 / (111320 * Math.cos(Cesium.Math.toRadians(lat)));
|
||||
const halfHeightDeg = height / 2 / 111320;
|
||||
return Cesium.Rectangle.fromDegrees(
|
||||
lon - halfWidthDeg,
|
||||
lat - halfHeightDeg,
|
||||
lon + halfWidthDeg,
|
||||
lat + halfHeightDeg
|
||||
);
|
||||
};
|
||||
|
||||
// 矩形拖动手柄:放在矩形的东北角
|
||||
const getObstacleRectHandlePosition = (lon, lat, width, height) => {
|
||||
const halfWidthDeg =
|
||||
width / 2 / (111320 * Math.cos(Cesium.Math.toRadians(lat)));
|
||||
const halfHeightDeg = height / 2 / 111320;
|
||||
return Cesium.Cartesian3.fromDegrees(
|
||||
lon + halfWidthDeg,
|
||||
lat + halfHeightDeg,
|
||||
0
|
||||
);
|
||||
};
|
||||
|
||||
// 打印矩形障碍物信息(center 为 WGS84,size 为以 center 为中心的长宽,单位米)
|
||||
const logRectObstacleInfo = (obstacle, index, lon, lat, width, height) => {
|
||||
const info = {
|
||||
id: obstacle?.id ?? `station-obstacle-point-${index}`,
|
||||
shape_type: 'aabb',
|
||||
center: [Number(lon), Number(lat)],
|
||||
size: [Number(width.toFixed(2)), Number(height.toFixed(2))],
|
||||
yaw: 0,
|
||||
cost: 254,
|
||||
source: 'ui',
|
||||
};
|
||||
console.log('[矩形障碍物]', JSON.stringify(info, null, 2));
|
||||
return info;
|
||||
};
|
||||
|
||||
// 障碍物形状签名:内容变化时才重建地图实体
|
||||
const obstacleShapeSignature = JSON.stringify(obstacleShapes || []);
|
||||
|
||||
const [drawPoints, setDrawPoints] = useState([]);
|
||||
const drawLineRef = useRef(null);
|
||||
const pointEntitiesRef = useRef([]);
|
||||
@@ -980,7 +1023,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
</div> `;
|
||||
} else {
|
||||
tooltip.innerHTML = `
|
||||
< div style = "font-weight:600;margin-bottom:4px;" >📍 ${t('systemSetting.longitude')}:${lonStr}</div >
|
||||
<div style = "font-weight:600;margin-bottom:4px;" >📍 ${t('systemSetting.longitude')}:${lonStr}</div >
|
||||
<div style="font-weight:600;">${t('systemSetting.latitude')}:${latStr}</div>
|
||||
`;
|
||||
}
|
||||
@@ -1062,8 +1105,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
: t('devices.mapEditor.unbound');
|
||||
|
||||
tooltip.innerHTML = `
|
||||
< div style = "font-weight:600;margin-bottom:4px;" >📍 ${point.alias || '-'}</div >
|
||||
<div>🤖 ${deviceLabel}</div>
|
||||
<div style = "font-weight:600;margin-bottom:4px;" >📍 ${point.alias || '-'}</div >
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -1584,6 +1626,11 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
);
|
||||
const lat = Number(obstacle?.position?.lat);
|
||||
const radius = Number(obstacle?.radius ?? 2);
|
||||
// 形状配置:圆形走原有半径逻辑,矩形按长宽渲染
|
||||
const shapeConfig = obstacleShapes?.[idx] || {};
|
||||
const isRect = shapeConfig.shapeType === 'rect';
|
||||
const rectWidth = Math.max(0.1, Number(shapeConfig.width) || radius * 2);
|
||||
const rectHeight = Math.max(0.1, Number(shapeConfig.height) || radius * 2);
|
||||
|
||||
if (
|
||||
!Number.isFinite(lon) ||
|
||||
@@ -1627,7 +1674,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
position,
|
||||
|
||||
// 以经纬度位置为圆心,radius 单位为米
|
||||
ellipse: {
|
||||
ellipse: isRect ? undefined : {
|
||||
semiMajorAxis: new Cesium.ConstantProperty(radius),
|
||||
semiMinorAxis: new Cesium.ConstantProperty(radius),
|
||||
height: 0,
|
||||
@@ -1642,6 +1689,24 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
},
|
||||
|
||||
// 矩形障碍物:以中心点为 center 的经纬度矩形
|
||||
rectangle: isRect
|
||||
? {
|
||||
coordinates: getObstacleRectCoordinates(
|
||||
lon,
|
||||
lat,
|
||||
rectWidth,
|
||||
rectHeight
|
||||
),
|
||||
height: 0,
|
||||
material: redColor.withAlpha(isHighlighted ? 0.3 : 0.18),
|
||||
outline: true,
|
||||
outlineColor: redColor,
|
||||
outlineWidth: isHighlighted ? 4 : 2,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
}
|
||||
: undefined,
|
||||
|
||||
// 圆心标记
|
||||
point: {
|
||||
pixelSize: isHighlighted ? 12 : 9,
|
||||
@@ -1653,7 +1718,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
|
||||
// 名称与半径标签
|
||||
label: {
|
||||
text: `${obstacle?.alias || `障碍物点-${idx + 1}`} (${radius}m)`,
|
||||
text: isRect
|
||||
? `${obstacle?.alias || `障碍物点-${idx + 1}`} (${rectWidth.toFixed(2)}×${rectHeight.toFixed(2)}m)`
|
||||
: `${obstacle?.alias || `障碍物点-${idx + 1}`} (${radius}m)`,
|
||||
font: isHighlighted ? 'bold 14px sans-serif' : '12px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
showBackground: true,
|
||||
@@ -1680,11 +1747,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
obstacleId: obstacle?.id,
|
||||
},
|
||||
|
||||
position: getObstacleHandlePosition(
|
||||
lon,
|
||||
lat,
|
||||
radius
|
||||
),
|
||||
position: isRect
|
||||
? getObstacleRectHandlePosition(lon, lat, rectWidth, rectHeight)
|
||||
: getObstacleHandlePosition(lon, lat, radius),
|
||||
|
||||
point: {
|
||||
pixelSize: isHighlighted ? 16 : 13,
|
||||
@@ -1707,7 +1772,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
});
|
||||
|
||||
viewer.scene.requestRender();
|
||||
}, [stationOverlay, highlightReturnPointId]);
|
||||
}, [stationOverlay, highlightReturnPointId, obstacleShapeSignature]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
@@ -1765,6 +1830,18 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
return;
|
||||
}
|
||||
|
||||
// 形状配置:圆形 / 矩形
|
||||
const shapeConfig = obstacleShapes?.[index] || {};
|
||||
const isRect = shapeConfig.shapeType === 'rect';
|
||||
const rectWidth = Math.max(
|
||||
0.1,
|
||||
Number(shapeConfig.width) || radius * 2
|
||||
);
|
||||
const rectHeight = Math.max(
|
||||
0.1,
|
||||
Number(shapeConfig.height) || radius * 2
|
||||
);
|
||||
|
||||
draggingObstacleRef.current = {
|
||||
index,
|
||||
entityId: `station-obstacle-point-${index}`,
|
||||
@@ -1773,12 +1850,17 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
lon,
|
||||
lat,
|
||||
radius,
|
||||
shapeType: isRect ? 'rect' : 'circle',
|
||||
width: rectWidth,
|
||||
height: rectHeight,
|
||||
};
|
||||
|
||||
setIsDraggingObstacle(true);
|
||||
|
||||
// 拖动时禁用相机旋转,避免地图跟着转
|
||||
viewer.scene.screenSpaceCameraController.enableRotate = false;
|
||||
viewer.scene.screenSpaceCameraController.enableTranslate = false;
|
||||
viewer.scene.screenSpaceCameraController.enableZoom = false;
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
||||
|
||||
// 鼠标移动:实时更新圆圈半径
|
||||
@@ -1862,6 +1944,69 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
);
|
||||
if (!mousePosition) return;
|
||||
|
||||
// 矩形:按鼠标相对中心点的偏移计算长宽,并同步矩形与手柄
|
||||
if (dragging.shapeType === 'rect') {
|
||||
const carto = Cesium.Cartographic.fromCartesian(mousePosition);
|
||||
if (!carto) return;
|
||||
const mouseLon = Cesium.Math.toDegrees(carto.longitude);
|
||||
const mouseLat = Cesium.Math.toDegrees(carto.latitude);
|
||||
|
||||
const width = Math.max(
|
||||
0.2,
|
||||
2 *
|
||||
Cesium.Cartesian3.distance(
|
||||
dragging.center,
|
||||
Cesium.Cartesian3.fromDegrees(mouseLon, dragging.lat, 0)
|
||||
)
|
||||
);
|
||||
const height = Math.max(
|
||||
0.2,
|
||||
2 *
|
||||
Cesium.Cartesian3.distance(
|
||||
dragging.center,
|
||||
Cesium.Cartesian3.fromDegrees(dragging.lon, mouseLat, 0)
|
||||
)
|
||||
);
|
||||
|
||||
dragging.width = width;
|
||||
dragging.height = height;
|
||||
|
||||
const rectEntity = viewer.entities.getById(dragging.entityId);
|
||||
const rectHandle = viewer.entities.getById(dragging.handleId);
|
||||
|
||||
if (rectEntity?.rectangle) {
|
||||
rectEntity.rectangle.coordinates.setValue(
|
||||
getObstacleRectCoordinates(
|
||||
dragging.lon,
|
||||
dragging.lat,
|
||||
width,
|
||||
height
|
||||
)
|
||||
);
|
||||
}
|
||||
if (rectHandle) {
|
||||
rectHandle.position = new Cesium.ConstantPositionProperty(
|
||||
getObstacleRectHandlePosition(
|
||||
dragging.lon,
|
||||
dragging.lat,
|
||||
width,
|
||||
height
|
||||
)
|
||||
);
|
||||
}
|
||||
if (rectEntity?.label) {
|
||||
const obstacle =
|
||||
stationOverlay.tempObstaclePoints?.[dragging.index];
|
||||
rectEntity.label.text.setValue(
|
||||
`${obstacle?.alias || `障碍物点-${dragging.index + 1}`} (${width.toFixed(2)}×${height.toFixed(2)}m)`
|
||||
);
|
||||
}
|
||||
|
||||
viewer.scene.requestRender();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 计算鼠标到圆心的距离,单位米
|
||||
const nextRadius = Math.max(
|
||||
0.01,
|
||||
@@ -1913,16 +2058,41 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
|
||||
if (!dragging) return;
|
||||
|
||||
// 保存最终半径
|
||||
const { index, radius } = dragging;
|
||||
|
||||
draggingObstacleRef.current = null;
|
||||
setIsDraggingObstacle(false);
|
||||
|
||||
if (viewer) {
|
||||
viewer.scene.screenSpaceCameraController.enableRotate = true;
|
||||
const ctrl = viewer.scene.screenSpaceCameraController;
|
||||
ctrl.enableRotate = true;
|
||||
ctrl.enableTranslate = true;
|
||||
ctrl.enableZoom = true;
|
||||
}
|
||||
|
||||
// 矩形:打印信息并回传长宽给父组件(暂不走圆形保存逻辑)
|
||||
if (dragging.shapeType === 'rect') {
|
||||
const obstacle =
|
||||
stationOverlay.tempObstaclePoints?.[index];
|
||||
const { width, height } = dragging;
|
||||
|
||||
logRectObstacleInfo(
|
||||
obstacle,
|
||||
index,
|
||||
dragging.lon,
|
||||
dragging.lat,
|
||||
width,
|
||||
height
|
||||
);
|
||||
|
||||
onObstacleRectResize?.(
|
||||
index,
|
||||
Number(width.toFixed(2)),
|
||||
Number(height.toFixed(2))
|
||||
);
|
||||
viewer?.scene.requestRender();
|
||||
return;
|
||||
}
|
||||
// 通知父组件更新列表
|
||||
|
||||
// 通知父组件更新列表
|
||||
onObstacleRadiusChange?.(index, radius, siteMapInfoId);
|
||||
|
||||
@@ -2570,11 +2570,39 @@ export default function DeviceStatusPage() {
|
||||
|
||||
<ConsoleRow icon={<DashboardOutlined />} label={t('devices.rtMainTemp')} value={(runningStatus?.main_temperature ?? runningStatus?.chipTemp) !== undefined ? formatTemperature(Number(runningStatus?.main_temperature ?? runningStatus?.chipTemp), 1).label : '-'} />
|
||||
|
||||
<ConsoleRow icon={<ControlOutlined />} label={t('devices.rtMode')} value={(runningStatus?.control_mode ?? runningStatus?.controlMode) !== undefined ? ((runningStatus?.control_mode ?? runningStatus?.controlMode) === '1' ? t('devices.localMode') : (runningStatus?.control_mode ?? runningStatus?.controlMode) === '3' ? t('devices.remoteMode') : t('constants.locationUnknown')) : '-'} />
|
||||
<ConsoleRow
|
||||
icon={<ControlOutlined />}
|
||||
label={t('devices.rtMode')}
|
||||
value={
|
||||
(runningStatus?.control_mode ?? runningStatus?.controlMode) !== undefined
|
||||
? (() => {
|
||||
const mode =
|
||||
runningStatus?.control_mode ?? runningStatus?.controlMode;
|
||||
|
||||
switch (mode) {
|
||||
case '0':
|
||||
case 0:
|
||||
return t('devices.controlOff');
|
||||
case '1':
|
||||
case 1:
|
||||
return t('devices.localCpntrol');
|
||||
case '2':
|
||||
case 2:
|
||||
return t('devices.autoTask');
|
||||
case '3':
|
||||
case 3:
|
||||
return t('devices.remoteControl');
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
})()
|
||||
: '-'
|
||||
}
|
||||
/>
|
||||
|
||||
|
||||
<ConsoleRow icon={<EnvironmentOutlined />} label={t('devices.motionStatus')} value={runningStatus?.motion === 'moving' ? t('devices.motionMoving') : runningStatus?.motion === 'stopped' ? t('devices.motionStopped') : runningStatus?.motion === 'blocked' ? t('devices.motionBlocked') : '-'} />
|
||||
<ConsoleRow icon={<EnvironmentOutlined />} label={t('devices.cutterSpedd')} value={runningStatus?.cutter_speed ?? "-"} />
|
||||
|
||||
<ConsoleRow icon={<SafetyOutlined />} label={t('devices.rtEmergency')} value={runningStatus?.emergency_stop === true ? t('devices.estopTriggered') : runningStatus?.emergency_stop === false ? t('devices.estopNormal') : '-'} />
|
||||
|
||||
|
||||
@@ -823,7 +823,94 @@ export default function MapEditorPage() {
|
||||
console.error('[MapEditor] preview route failed:', e);
|
||||
}
|
||||
};
|
||||
// 修改已配置障碍物点的半径
|
||||
|
||||
// ========== 删除已配置的返航点 / 障碍物点 ==========
|
||||
const handleDeleteMapPoint = (item: any, index: number) => {
|
||||
const isReturnPoint = activeType === 'returnPoint';
|
||||
const isObstaclePoint = activeType === 'obstaclePoint';
|
||||
|
||||
if (!isReturnPoint && !isObstaclePoint) return;
|
||||
|
||||
const pointName = isReturnPoint
|
||||
? item.alias || `返航点-${index + 1}`
|
||||
: item.name || item.alias || `障碍物点-${index + 1}`;
|
||||
|
||||
modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定删除「${pointName}」吗?`,
|
||||
okText: '删除',
|
||||
cancelText: '取消',
|
||||
okButtonProps: { danger: true },
|
||||
|
||||
onOk: async () => {
|
||||
try {
|
||||
let payload: any;
|
||||
|
||||
if (isReturnPoint) {
|
||||
// 删除当前返航点,保留其他返航点
|
||||
const nextPoints = returnPointConfigList
|
||||
.filter((_: any, i: number) => i !== index);
|
||||
|
||||
payload = {
|
||||
restPoints: nextPoints.map((p: any) => ({
|
||||
alias: p.alias || '',
|
||||
position: p.position,
|
||||
bindDeviceId: p.bindDeviceId || null,
|
||||
})),
|
||||
siteId: stationId,
|
||||
orgId: currentStation?.orgId,
|
||||
};
|
||||
} else {
|
||||
// 删除当前障碍物点,保留其他障碍物点
|
||||
const nextPoints = obstaclePointConfigList.filter(
|
||||
(point: any) =>
|
||||
String(point.id) !== String(item.id)
|
||||
);
|
||||
|
||||
payload = {
|
||||
tempObstaclePoints: nextPoints.map((point: any) => ({
|
||||
position: {
|
||||
lat: Number(
|
||||
point.position?.lat ?? point.lat ?? 0
|
||||
),
|
||||
lng: Number(
|
||||
point.position?.lng ??
|
||||
point.position?.lon ??
|
||||
point.lon ??
|
||||
0
|
||||
),
|
||||
},
|
||||
radius: Number(point.radius) || 2,
|
||||
alias: point.name ?? point.alias ?? '',
|
||||
})),
|
||||
siteId: stationId,
|
||||
orgId: currentStation?.orgId,
|
||||
};
|
||||
}
|
||||
|
||||
// 更新已有站点地图信息时,带上后端返回的主键 ID
|
||||
if (siteMapInfoId != null) {
|
||||
payload.id = siteMapInfoId;
|
||||
}
|
||||
|
||||
const res: any = await saveSiteMapInfo(payload);
|
||||
|
||||
if (res?.code === 200) {
|
||||
messageApi.success('删除成功');
|
||||
|
||||
// 刷新服务端数据及地图覆盖物
|
||||
await getSiteMapInfoFn();
|
||||
setOverlayRefreshKey((k) => k + 1);
|
||||
} else {
|
||||
messageApi.error(res?.msg || '删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[MapEditor] 删除返航点/障碍物点失败:', error);
|
||||
messageApi.error('删除失败,请稍后重试');
|
||||
}
|
||||
},
|
||||
});
|
||||
}; // 修改已配置障碍物点的半径
|
||||
const handleUpdateObstacleRadius = async (
|
||||
item: any,
|
||||
radius: number
|
||||
@@ -1951,6 +2038,22 @@ export default function MapEditorPage() {
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 返航点 / 障碍物点:增加删除按钮 */}
|
||||
{(isReturnPoint || isObstaclePoint) && (
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
title={t('common.delete')}
|
||||
onClick={(e) => {
|
||||
// 防止触发行项目的地图聚焦事件
|
||||
e.stopPropagation();
|
||||
handleDeleteMapPoint(item, idx);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -1596,11 +1596,41 @@ export default function RobotTaskPage() {
|
||||
|
||||
<span>
|
||||
{t('devices.controlMode')}
|
||||
{robotRealtimePosition?.controlMode == '1' ? (
|
||||
<span style={{ color: '#ff6f6f' }}>{t('devices.localMode')}</span>
|
||||
) : (
|
||||
<span style={{ color: '#9eff9e' }}>{t('devices.remoteMode')}</span>
|
||||
)}
|
||||
{(() => {
|
||||
const mode = robotRealtimePosition?.controlMode || robotRealtimePosition?.control_mode;
|
||||
|
||||
const modeConfig: Record<string, { label: string; color: string }> = {
|
||||
'0': {
|
||||
label: t('devices.controlOff'),
|
||||
color: '#999999',
|
||||
},
|
||||
'1': {
|
||||
label: t('devices.localCpntrol'),
|
||||
color: '#ff6f6f',
|
||||
},
|
||||
'2': {
|
||||
label: t('devices.autoTask'),
|
||||
color: '#9eff9e',
|
||||
},
|
||||
'3': {
|
||||
label: t('devices.remoteControl'),
|
||||
color: '#9eff9e',
|
||||
},
|
||||
};
|
||||
|
||||
const config =
|
||||
mode !== undefined && mode !== null
|
||||
? modeConfig[String(mode)]
|
||||
: undefined;
|
||||
|
||||
return config ? (
|
||||
<span style={{ color: config.color }}>{config.label}</span>
|
||||
) : (
|
||||
<span style={{ color: '#999999' }}>
|
||||
-
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
</span>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user