feat: 添加地面站实体创建逻辑,优化管理器功能
Some checks failed
/ surge (push) Successful in 2m46s
/ build-and-deploy-to-vercel (push) Successful in 2m51s
/ lint-build-and-check (push) Successful in 4m36s
/ playwright (push) Has been cancelled

This commit is contained in:
严浩
2025-04-03 15:12:11 +08:00
parent aacd168450
commit 5a69629f35
9 changed files with 183 additions and 137 deletions

View File

@ -18,19 +18,38 @@ export class HCesiumStationManager {
* @param options - 地面站的选项参数
* @returns 添加的实体对象,如果已存在或添加失败则返回 null 或现有实体。
*/
addOrUpdateStation(options: I站点): Cesium.Entity | null {
addOrUpdateStation(options: I站点): undefined {
const existingEntity = this.currentStationEntities.get(options.id);
if (existingEntity) {
console.warn(`ID 为 "${options.id}" 的地面站实体已由管理器追踪,跳过添加。`);
// 未来可以扩展为更新逻辑
return existingEntity;
return;
}
// 解构赋值获取站点信息
const { height = 0, id, latitude, longitude, name, pixelSize = 10 } = options;
const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
const groundStationEntity = new Cesium.Entity({
const stationEntity = this._createStationEntity(id, name, position, pixelSize);
const addedEntity = this.viewerManager.addEntity(stationEntity);
if (addedEntity) {
this.currentStationEntities.set(id, addedEntity); // 添加成功后,将其存入 Map
} else {
console.error(`通过 ViewerManager 添加 ID 为 "${id}" 的地面站实体失败。`);
}
}
/**
* 创建地面站点的 Cesium 实体对象。
* 这是一个内部辅助方法,封装了实体创建的细节。
*/
private _createStationEntity(
id: string,
name: string,
position: Cesium.Cartesian3,
pixelSize: number,
): Cesium.Entity {
return new Cesium.Entity({
id, // 使用传入的 id 作为实体的唯一标识符
name,
position,
@ -49,22 +68,9 @@ export class HCesiumStationManager {
pixelOffset: new Cesium.Cartesian2(0, -12), // 标签略微偏移到点的上方
},
});
const addedEntity = this.viewerManager.addEntity(groundStationEntity);
if (addedEntity) {
// 添加成功后,将其存入 Map
this.currentStationEntities.set(id, addedEntity);
return addedEntity;
} else {
console.error(`通过 ViewerManager 添加 ID 为 "${id}" 的地面站实体失败。`);
return null;
}
}
/**
* 从视图中移除指定的地面站实体 (通过 ID)。
* @param entityId - 要移除的地面站实体的 ID。
* @returns 如果成功移除则返回 true否则返回 false。
*/
removeStation(entityId: string): boolean {
const entityToRemove = this.currentStationEntities.get(entityId);