控制模式 割刀速度 加入 支持删除 返航点和障碍物点
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);
|
||||
|
||||
Reference in New Issue
Block a user