refactor(map): 清理人员定位相关代码并优化注释

master
LiuJiaNan 2026-07-28 09:20:29 +08:00
parent c1f9fd0169
commit 1f7fee828f
1 changed files with 11 additions and 5 deletions

View File

@ -63,7 +63,6 @@ const peopleImg = {
red: people_red, red: people_red,
yellow: people_yellow, yellow: people_yellow,
}; // 人员定位颜色图片 }; // 人员定位颜色图片
const peopleTrajectoryEntityId = "peopleTrajectoryEntity";
const Cesium = window.Cesium; const Cesium = window.Cesium;
@ -92,8 +91,11 @@ export default function useMapMethods(viewerRef, request) {
height: 900000, height: 900000,
}); });
const peopleId = useRef([]); // 人员定位 ID 列表 // 人员定位 ID 列表
const peoplePositionStartTime = useRef(null); // 当前人员定位会话共用的采样起始时间 const peopleId = useRef([]);
// 当前人员定位会话共用的采样起始时间
const peoplePositionStartTime = useRef(null);
// 设置中心点 // 设置中心点
const flyTo = ({ longitude, latitude, height } = defineCenterPoint) => { const flyTo = ({ longitude, latitude, height } = defineCenterPoint) => {
@ -413,7 +415,7 @@ export default function useMapMethods(viewerRef, request) {
// 查询新轨迹前先移除旧轨迹,确保地图上始终只展示当前筛选结果。 // 查询新轨迹前先移除旧轨迹,确保地图上始终只展示当前筛选结果。
const removePeopleTrajectory = () => { 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]); const coordinates = points.flatMap(point => [point.lon, point.lat, point.alt || 0]);
getViewer().entities.add({ getViewer().entities.add({
id: peopleTrajectoryEntityId, id: "peopleTrajectoryEntity",
polyline: { polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(coordinates), positions: Cesium.Cartesian3.fromDegreesArrayHeights(coordinates),
width: 5, width: 5,
@ -446,6 +448,7 @@ export default function useMapMethods(viewerRef, request) {
return start; return start;
}; };
// 添加人员定位点
const addPeoplePoint = async (point, options) => { const addPeoplePoint = async (point, options) => {
const image = peopleImg[point.icon_type]; const image = peopleImg[point.icon_type];
if (!image) if (!image)
@ -478,6 +481,7 @@ export default function useMapMethods(viewerRef, request) {
}); });
}; };
// 更新人员定位点
const updatePeoplePoint = async (point) => { const updatePeoplePoint = async (point) => {
const viewer = getViewer(); const viewer = getViewer();
if (viewer.clock.shouldAnimate === false) { if (viewer.clock.shouldAnimate === false) {
@ -505,11 +509,13 @@ export default function useMapMethods(viewerRef, request) {
point.lastTime = nextTime; point.lastTime = nextTime;
}; };
// 删除人员定位点
const removePeoplePoint = (id) => { const removePeoplePoint = (id) => {
getViewer().entities.removeById(id); getViewer().entities.removeById(id);
peopleId.current = peopleId.current.filter(item => item !== id); peopleId.current = peopleId.current.filter(item => item !== id);
}; };
// 删除所有人员定位点
const removePeoplePointAll = () => { const removePeoplePointAll = () => {
peopleId.current.forEach((id) => { peopleId.current.forEach((id) => {
getViewer().entities.removeById(id); getViewer().entities.removeById(id);