优化 focuslocation变化的时候 同一位置出现俩机器的bug
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 carImg from '../assets/images/carplane.png';
|
||||||
import inspectImg from "../assets/images/inspectCar.png"
|
import inspectImg from "../assets/images/inspectCar.png"
|
||||||
import planeImg from '../assets/images/planeicon.png';
|
import planeImg from '../assets/images/planeicon.png';
|
||||||
@@ -91,6 +91,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
const realtimeLastPointRef = useRef(null);
|
const realtimeLastPointRef = useRef(null);
|
||||||
const realtimeHiddenRef = useRef(false);
|
const realtimeHiddenRef = useRef(false);
|
||||||
const focusEntityRef = useRef(null);
|
const focusEntityRef = useRef(null);
|
||||||
|
const hiddenByFocusRef = useRef([]);
|
||||||
|
|
||||||
|
|
||||||
const yellowCircleCanvas = useMemo(
|
const yellowCircleCanvas = useMemo(
|
||||||
@@ -1285,11 +1286,24 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
viewerRef.current?.entities.remove(focusEntityRef.current);
|
viewerRef.current?.entities.remove(focusEntityRef.current);
|
||||||
focusEntityRef.current = null;
|
focusEntityRef.current = null;
|
||||||
}
|
}
|
||||||
|
// 恢复被 focusEntity 隐藏的设备实体
|
||||||
|
hiddenByFocusRef.current.forEach(e => {
|
||||||
|
if (e.billboard) e.billboard.show = true;
|
||||||
|
if (e.label) e.label.show = true;
|
||||||
|
});
|
||||||
|
hiddenByFocusRef.current = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const viewer = viewerRef.current;
|
const viewer = viewerRef.current;
|
||||||
const Cesium = window.Cesium;
|
const Cesium = window.Cesium;
|
||||||
|
|
||||||
|
// 恢复上一次被隐藏的设备实体
|
||||||
|
hiddenByFocusRef.current.forEach(e => {
|
||||||
|
if (e.billboard) e.billboard.show = true;
|
||||||
|
if (e.label) e.label.show = true;
|
||||||
|
});
|
||||||
|
hiddenByFocusRef.current = [];
|
||||||
|
|
||||||
// 选择图片
|
// 选择图片
|
||||||
let image = carImg;
|
let image = carImg;
|
||||||
if (focusLocation.type === "plane" || focusLocation.type === "drone") {
|
if (focusLocation.type === "plane" || focusLocation.type === "drone") {
|
||||||
@@ -1305,6 +1319,24 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
|
|||||||
viewer.entities.remove(focusEntityRef.current);
|
viewer.entities.remove(focusEntityRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 隐藏同位置的设备实体,避免重复显示(同一设备出现两个图标和 label)
|
||||||
|
const focusLon = Number(focusLocation.lon);
|
||||||
|
const focusLat = Number(focusLocation.lat);
|
||||||
|
entityMapRef.current.forEach((entity) => {
|
||||||
|
const robotData = entity.properties?.robot?.getValue?.();
|
||||||
|
if (!robotData) return;
|
||||||
|
const raw = robotData?.locationMessage || robotData?.lastRunningStatus || {};
|
||||||
|
const entLon = Number(raw.longitude);
|
||||||
|
const entLat = Number(raw.latitude);
|
||||||
|
if (!isFinite(entLon) || !isFinite(entLat)) return;
|
||||||
|
// 经纬度相近(容差 0.0001 度)则视为同一设备
|
||||||
|
if (Math.abs(entLon - focusLon) < 0.0001 && Math.abs(entLat - focusLat) < 0.0001) {
|
||||||
|
if (entity.billboard) entity.billboard.show = false;
|
||||||
|
if (entity.label) entity.label.show = false;
|
||||||
|
hiddenByFocusRef.current.push(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 添加新的 focusEntity
|
// 添加新的 focusEntity
|
||||||
focusEntityRef.current = viewer.entities.add({
|
focusEntityRef.current = viewer.entities.add({
|
||||||
position: Cesium.Cartesian3.fromDegrees(Number(focusLocation.lon), Number(focusLocation.lat), 0),
|
position: Cesium.Cartesian3.fromDegrees(Number(focusLocation.lon), Number(focusLocation.lat), 0),
|
||||||
|
|||||||
Reference in New Issue
Block a user