feat: 添加地面站实体创建逻辑,优化管理器功能
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user