From 1f7fee828f86c1aec58319e30c159434b23004fd Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Tue, 28 Jul 2026 09:20:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(map):=20=E6=B8=85=E7=90=86=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E5=AE=9A=E4=BD=8D=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Container/Map/js/useMapMethods.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/Container/Map/js/useMapMethods.js b/src/pages/Container/Map/js/useMapMethods.js index 453039c..0230511 100644 --- a/src/pages/Container/Map/js/useMapMethods.js +++ b/src/pages/Container/Map/js/useMapMethods.js @@ -63,7 +63,6 @@ const peopleImg = { red: people_red, yellow: people_yellow, }; // 人员定位颜色图片 -const peopleTrajectoryEntityId = "peopleTrajectoryEntity"; const Cesium = window.Cesium; @@ -92,8 +91,11 @@ export default function useMapMethods(viewerRef, request) { height: 900000, }); - const peopleId = useRef([]); // 人员定位 ID 列表 - const peoplePositionStartTime = useRef(null); // 当前人员定位会话共用的采样起始时间 + // 人员定位 ID 列表 + const peopleId = useRef([]); + + // 当前人员定位会话共用的采样起始时间 + const peoplePositionStartTime = useRef(null); // 设置中心点 const flyTo = ({ longitude, latitude, height } = defineCenterPoint) => { @@ -413,7 +415,7 @@ export default function useMapMethods(viewerRef, request) { // 查询新轨迹前先移除旧轨迹,确保地图上始终只展示当前筛选结果。 const removePeopleTrajectory = () => { - getViewer().entities.removeById(peopleTrajectoryEntityId); + getViewer().entities.removeById("peopleTrajectoryEntity"); }; // 将接口返回的经纬高点位绘制为动态轨迹线,少于两个点时不创建无意义的线段。 @@ -424,7 +426,7 @@ export default function useMapMethods(viewerRef, request) { const coordinates = points.flatMap(point => [point.lon, point.lat, point.alt || 0]); getViewer().entities.add({ - id: peopleTrajectoryEntityId, + id: "peopleTrajectoryEntity", polyline: { positions: Cesium.Cartesian3.fromDegreesArrayHeights(coordinates), width: 5, @@ -446,6 +448,7 @@ export default function useMapMethods(viewerRef, request) { return start; }; + // 添加人员定位点 const addPeoplePoint = async (point, options) => { const image = peopleImg[point.icon_type]; if (!image) @@ -478,6 +481,7 @@ export default function useMapMethods(viewerRef, request) { }); }; + // 更新人员定位点 const updatePeoplePoint = async (point) => { const viewer = getViewer(); if (viewer.clock.shouldAnimate === false) { @@ -505,11 +509,13 @@ export default function useMapMethods(viewerRef, request) { point.lastTime = nextTime; }; + // 删除人员定位点 const removePeoplePoint = (id) => { getViewer().entities.removeById(id); peopleId.current = peopleId.current.filter(item => item !== id); }; + // 删除所有人员定位点 const removePeoplePointAll = () => { peopleId.current.forEach((id) => { getViewer().entities.removeById(id);