修复地图 跳转的顺序问题

This commit is contained in:
mmc
2026-09-04 16:22:28 +08:00
parent ab193a3be9
commit f0e1c14644
5 changed files with 59 additions and 15 deletions

View File

@@ -55,6 +55,21 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
const isCameraFlyingRef = useRef(false);
const lastFlightPromiseRef = useRef(null);
// ==============================
// 飞行优先级调度:优先级高的可打断低的;同级不重复起飞
// realtime(100) > focus(90) > devices(80) > track(70) > layer(10)
// ==============================
const lastFlightPriorityRef = useRef(-1);
const FLIGHT_PRIORITY = { realtime: 100, focus: 90, devices: 80, track: 70, layer: 10 };
const flyToView = (viewer, priority, config) => {
if (!viewer) return;
if (priority <= lastFlightPriorityRef.current) return; // 同级或更低不重复/覆盖;更高优先级才打断
lastFlightPriorityRef.current = priority;
try { viewer.camera.cancelFlight(); } catch (e) { /* 忽略取消异常 */ }
viewer.camera.flyTo(config);
};
const resetFlightPriority = () => { lastFlightPriorityRef.current = -1; };
const [drawPoints, setDrawPoints] = useState([]);
const drawLineRef = useRef(null);
const pointEntitiesRef = useRef([]);
@@ -262,7 +277,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
const p = validPoints[0];
viewer.scene.requestRender();
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.track, {
destination: Cesium.Cartesian3.fromDegrees(
p.lng,
p.lat,
@@ -284,7 +299,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
viewer.scene.requestRender();
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.track, {
destination: rectangle,
duration: 1.2
});
@@ -400,7 +415,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
const p = validPoints[0];
viewer.scene.requestRender();
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.track, {
destination: Cesium.Cartesian3.fromDegrees(
p.lng,
p.lat,
@@ -422,7 +437,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
viewer.scene.requestRender();
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.track, {
destination: rectangle,
duration: 1.2
});
@@ -435,6 +450,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
};
useEffect(() => {
resetFlightPriority();
if (polyPoints && polyPoints.length > 0) {
drawPolygon(polyPoints)
} else {
@@ -452,6 +468,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
useEffect(() => {
resetFlightPriority();
if (viewerRef.current) {
drawTrackLine(points);
}
@@ -527,7 +544,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
`;
}
const getCursorLngLat = (viewer, screenPos) => {
const getCursorLngLat = (viewer, screenPos) => {
const cartesian = viewer.camera.pickEllipsoid(screenPos, viewer.scene.globe.ellipsoid);
if (!window.Cesium.defined(cartesian)) return { lon: NaN, lat: NaN };
const cartographic = window.Cesium.Cartographic.fromCartesian(cartesian);
@@ -846,7 +863,7 @@ const getCursorLngLat = (viewer, screenPos) => {
const centerLon = (minx + maxx) / 2;
const centerLat = (miny + maxy) / 2;
viewerRef.current.camera.flyTo({
flyToView(viewerRef.current, FLIGHT_PRIORITY.layer, {
// 固定高度,第三个参数就是高度(单位米)
destination: window.Cesium.Cartesian3.fromDegrees(centerLon, centerLat, flyHeight),
orientation: {
@@ -994,9 +1011,12 @@ const getCursorLngLat = (viewer, screenPos) => {
};
}, []);
// 根据场站映射图层定位地图
// 根据场站映射图层定位地图:切换场站时始终飞向该场站的图层
// 不再用可能滞后的 devices 判断(避免用上一场站的机器决策);
// 若场站有机器,由 devices 效果按更高优先级接管飞向机器
useEffect(() => {
if (!mapLayer || !viewerRef.current) return;
resetFlightPriority();
flyToLayer(mapLayer, envConfig.geoserver_url, 100);
}, [mapLayer]);
@@ -1054,7 +1074,7 @@ const getCursorLngLat = (viewer, screenPos) => {
}
});
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.focus, {
destination: Cesium.Cartesian3.fromDegrees(Number(focusLocation.lon), Number(focusLocation.lat), focusLocation.height || 800),
orientation: {
heading: Cesium.Math.toRadians(0.0),
@@ -1081,7 +1101,7 @@ const getCursorLngLat = (viewer, screenPos) => {
});
const rectangle = window.Cesium.Rectangle.fromDegrees(west, south, east, north);
viewer.camera.flyTo({ destination: rectangle, duration: 1.5 });
flyToView(viewer, FLIGHT_PRIORITY.devices, { destination: rectangle, duration: 1.5 });
}
function parseLngLat(lon, lat) {
@@ -1530,7 +1550,7 @@ const getCursorLngLat = (viewer, screenPos) => {
const p = validPositions[0];
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.devices, {
destination: Cesium.Cartesian3.fromDegrees(
p.lon,
p.lat,
@@ -1548,7 +1568,7 @@ const getCursorLngLat = (viewer, screenPos) => {
maxLat
);
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.devices, {
destination: rectangle,
duration: 1.2
});
@@ -1731,6 +1751,7 @@ const getCursorLngLat = (viewer, screenPos) => {
realtimeLastPointRef.current = null;
realtimeHiddenRef.current = false;
hasFlownRef.current = false;
resetFlightPriority();
// 恢复所有设备显示
entityMapRef.current.forEach(e => {
@@ -1891,7 +1912,7 @@ const getCursorLngLat = (viewer, screenPos) => {
hasFlownRef.current = true;
if (getCameraMode() !== "realtime") return;
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.realtime, {
destination: Cesium.Cartesian3.fromDegrees(lon, lat, 30),
orientation: {
heading: 0,
@@ -2031,7 +2052,7 @@ const getCursorLngLat = (viewer, screenPos) => {
hasFlownRef.current = true;
if (getCameraMode() !== "realtime") return;
viewer.camera.flyTo({
flyToView(viewer, FLIGHT_PRIORITY.realtime, {
destination: Cesium.Cartesian3.fromDegrees(
lon,