模拟障碍物 继续作业 连续作业 初始化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useRef, useState, useMemo, useImperativeHandle, forwardRef, useCallback } from 'react';
|
||||
import React, { useEffect, useRef, useState, useMemo, useImperativeHandle, forwardRef, useCallback } from 'react';
|
||||
import carImg from '../assets/images/carplane.png';
|
||||
import planeImg from '../assets/images/planeicon.png';
|
||||
import cameraImg from '../assets/images/camera.png';
|
||||
@@ -16,6 +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, obstacleShapes = [], onObstacleRectResize, siteMapInfoId, detectReportInfo }, ref) => {
|
||||
const containerRef = useRef(null);
|
||||
const viewerRef = useRef(null);
|
||||
@@ -280,55 +281,65 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
if (lastFlightPromiseRef.current) viewer.camera.cancelFlight();
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
function updateLiveObstacleBoxes(
|
||||
viewer,
|
||||
message,
|
||||
) {
|
||||
const viewer = viewerRef.current;
|
||||
if (!viewer || !Cesium) return;
|
||||
|
||||
console.log(message, "障碍物信息")
|
||||
return;
|
||||
const payload = message.data ?? message;
|
||||
const objects = payload.objects ?? [];
|
||||
const payload = message?.data ?? message;
|
||||
const objects = Array.isArray(payload) ? payload : (payload?.objects ?? []);
|
||||
|
||||
if (objects.length === 0) return;
|
||||
|
||||
// 记录第一个有效障碍物的位置,用于视角跳转
|
||||
let firstPos = null;
|
||||
|
||||
objects.forEach((obj, index) => {
|
||||
const lat = Number(obj.latitude);
|
||||
const lon = Number(obj.longitude);
|
||||
const sx = Number(obj.size_x);
|
||||
const sy = Number(obj.size_y);
|
||||
const sz = Number(obj.size_z);
|
||||
const lat = Number(obj.latitude ?? obj.lat);
|
||||
const lon = Number(obj.longitude ?? obj.lng ?? obj.lon);
|
||||
|
||||
if (
|
||||
!Number.isFinite(lat) ||
|
||||
!Number.isFinite(lon) ||
|
||||
!Number.isFinite(sx) ||
|
||||
!Number.isFinite(sy) ||
|
||||
!Number.isFinite(sz) ||
|
||||
sx <= 0 ||
|
||||
sy <= 0 ||
|
||||
sz <= 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
// 根据类型设置默认尺寸和颜色
|
||||
const type = (obj.class_name ?? obj.name ?? '').toLowerCase();
|
||||
const isPerson = type.includes('person') || type.includes('行人') || type.includes('人');
|
||||
const isVehicle = type.includes('car') || type.includes('车辆') || type.includes('车') || type.includes('truck');
|
||||
const isFence = type.includes('fence') || type.includes('围挡') || type.includes('障碍');
|
||||
|
||||
const id = `live-obstacle-${obj.track_id ?? index}`;
|
||||
const sx = Number(obj.size_x ?? obj.sizeX ?? (isPerson ? 0.6 : isVehicle ? 1.8 : 1.2));
|
||||
const sy = Number(obj.size_y ?? obj.sizeY ?? (isPerson ? 0.6 : isVehicle ? 4.2 : 1.2));
|
||||
const sz = Number(obj.size_z ?? obj.sizeZ ?? (isPerson ? 1.7 : isVehicle ? 1.5 : 1.5));
|
||||
|
||||
// size_x、size_y、size_z 作为长、宽、高,单位按米处理
|
||||
const position = Cesium.Cartesian3.fromDegrees(
|
||||
lon,
|
||||
lat,
|
||||
sz / 2,
|
||||
);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return;
|
||||
|
||||
const id = `live-obstacle-${obj.track_id ?? obj.id ?? index}`;
|
||||
const position = Cesium.Cartesian3.fromDegrees(lon, lat, sz / 2);
|
||||
|
||||
if (!firstPos) firstPos = { lon, lat };
|
||||
|
||||
const orientation = Cesium.Transforms.headingPitchRollQuaternion(
|
||||
position,
|
||||
new Cesium.HeadingPitchRoll(
|
||||
Cesium.Math.toRadians(Number(obj.angle ?? 0)),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(Number(obj.angle ?? obj.yaw ?? 0)), 0, 0)
|
||||
);
|
||||
|
||||
const labelText =
|
||||
`${obj.class_name ?? '障碍物'} #${obj.track_id ?? index}`;
|
||||
// 设置视觉差异
|
||||
let boxColor = Cesium.Color.RED;
|
||||
let typeEmoji = '⚠️';
|
||||
let iconImage = null; // 用于存储图标
|
||||
|
||||
if (isPerson) {
|
||||
boxColor = Cesium.Color.YELLOW;
|
||||
typeEmoji = '🚶';
|
||||
iconImage = 'https://img.icons8.com/color/96/walking--v1.png'; // 行人图标
|
||||
} else if (isVehicle) {
|
||||
boxColor = Cesium.Color.CYAN;
|
||||
typeEmoji = '🚗';
|
||||
iconImage = 'https://img.icons8.com/color/96/car--v1.png'; // 车辆图标
|
||||
}
|
||||
const labelText = `${typeEmoji} ${obj.class_name ?? '障碍物'} #${obj.track_id ?? obj.id ?? index} (${sx.toFixed(1)}x${sy.toFixed(1)}m)`;
|
||||
|
||||
let entity = viewer.entities.getById(id);
|
||||
|
||||
@@ -337,44 +348,118 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
||||
id,
|
||||
position,
|
||||
orientation,
|
||||
// 外部包围盒,显示物理占用空间
|
||||
box: {
|
||||
dimensions: new Cesium.Cartesian3(sx, sy, sz),
|
||||
material: Cesium.Color.RED.withAlpha(0.18),
|
||||
material: boxColor.withAlpha(0.2),
|
||||
outline: true,
|
||||
outlineColor: Cesium.Color.RED,
|
||||
outlineColor: boxColor,
|
||||
outlineWidth: 1,
|
||||
},
|
||||
// 内部图标,直观显示物体类型
|
||||
billboard: iconImage ? {
|
||||
image: iconImage,
|
||||
width: isPerson ? 24 : 32,
|
||||
height: isPerson ? 24 : 32,
|
||||
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
} : undefined,
|
||||
label: {
|
||||
text: labelText,
|
||||
font: '14px sans-serif',
|
||||
font: 'bold 14px sans-serif',
|
||||
fillColor: Cesium.Color.WHITE,
|
||||
showBackground: true,
|
||||
backgroundColor: Cesium.Color.RED.withAlpha(0.85),
|
||||
pixelOffset: new Cesium.Cartesian2(0, -20),
|
||||
backgroundColor: boxColor.withAlpha(0.85),
|
||||
pixelOffset: new Cesium.Cartesian2(0, -40),
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
entity.position = position;
|
||||
entity.orientation = orientation;
|
||||
|
||||
if (entity.box) {
|
||||
entity.box.dimensions = new Cesium.Cartesian3(sx, sy, sz);
|
||||
entity.box.material = boxColor.withAlpha(0.2);
|
||||
entity.box.outlineColor = boxColor;
|
||||
}
|
||||
if (entity.billboard && iconImage) {
|
||||
entity.billboard.image = iconImage;
|
||||
}
|
||||
|
||||
if (entity.label) {
|
||||
entity.label.text = labelText;
|
||||
entity.label.backgroundColor = boxColor.withAlpha(0.85);
|
||||
}
|
||||
}
|
||||
|
||||
liveObstacleEntities.set(id, entity);
|
||||
});
|
||||
|
||||
// 自动跳转到第一个障碍物
|
||||
//if (firstPos) {
|
||||
// flyToView(viewer, 100, {
|
||||
// destination: Cesium.Cartesian3.fromDegrees(firstPos.lon, firstPos.lat, 60),
|
||||
// orientation: {
|
||||
// heading: Cesium.Math.toRadians(0),
|
||||
// pitch: Cesium.Math.toRadians(-40),
|
||||
// roll: 0
|
||||
// },
|
||||
// duration: 2.0
|
||||
// }, 'live-obstacle-jump');
|
||||
//}
|
||||
viewer.scene.requestRender();
|
||||
}
|
||||
|
||||
// 模拟触发实时障碍物(仅用于演示)
|
||||
//useEffect(() => {
|
||||
// const viewer = viewerRef.current;
|
||||
// if (!viewer || !Cesium) return;
|
||||
|
||||
// const timer = setTimeout(() => {
|
||||
// console.log("[Mock] 触发模拟实时障碍物渲染 (人+车+围挡)");
|
||||
// const mockMsg = {
|
||||
// objects: [
|
||||
// {
|
||||
// track_id: "obs-v-001",
|
||||
// latitude: 31.2989,
|
||||
// longitude: 120.5853,
|
||||
// size_x: 1.8,
|
||||
// size_y: 4.2,
|
||||
// size_z: 1.5,
|
||||
// angle: 30,
|
||||
// class_name: "车辆"
|
||||
// },
|
||||
// {
|
||||
// track_id: "obs-p-002",
|
||||
// latitude: 31.2992,
|
||||
// longitude: 120.5856,
|
||||
// size_x: 0.6,
|
||||
// size_y: 0.6,
|
||||
// size_z: 1.7,
|
||||
// angle: 0,
|
||||
// class_name: "行人"
|
||||
// },
|
||||
// //{
|
||||
// // track_id: "obs-f-003",
|
||||
// // latitude: 31.2987,
|
||||
// // longitude: 120.5850,
|
||||
// // size_x: 3.0,
|
||||
// // size_y: 0.5,
|
||||
// // size_z: 2.0,
|
||||
// // angle: 90,
|
||||
// // class_name: "施工围挡"
|
||||
// //}
|
||||
// ]
|
||||
// };
|
||||
// updateLiveObstacleBoxes(mockMsg);
|
||||
// }, 3000);
|
||||
|
||||
// return () => clearTimeout(timer);
|
||||
//}, [stationId]);
|
||||
|
||||
|
||||
const handleDetectFn = (res) => {
|
||||
console.log(res, "监测到障碍物")
|
||||
const viewer = viewerRef.current;
|
||||
updateLiveObstacleBoxes(viewer, res);
|
||||
if (!res) return;
|
||||
updateLiveObstacleBoxes(res);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user