From 92978da4a948066edb5645c900e1ab18edac9d9e Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Sun, 20 Sep 2026 13:51:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20focuslocation=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E6=97=B6=E5=80=99=20=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=87=BA=E7=8E=B0=E4=BF=A9=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Map.jsx | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/components/Map.jsx b/src/components/Map.jsx index 367f744..d2bf7b0 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -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 inspectImg from "../assets/images/inspectCar.png" import planeImg from '../assets/images/planeicon.png'; @@ -91,6 +91,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const realtimeLastPointRef = useRef(null); const realtimeHiddenRef = useRef(false); const focusEntityRef = useRef(null); + const hiddenByFocusRef = useRef([]); const yellowCircleCanvas = useMemo( @@ -1285,11 +1286,24 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, viewerRef.current?.entities.remove(focusEntityRef.current); 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; } const viewer = viewerRef.current; 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; if (focusLocation.type === "plane" || focusLocation.type === "drone") { @@ -1305,6 +1319,24 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, 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 focusEntityRef.current = viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(Number(focusLocation.lon), Number(focusLocation.lat), 0),