// @ts-nocheck import { Enviroment } from '../Enviroment' import type { Disposable } from '../Common' import { MapElement } from './BaseElement' export class _ElementManager implements Disposable { readonly elementMap: Map>; constructor() { this.elementMap = new Map>(); } init() { if (Enviroment.primitives == undefined) { Enviroment.primitives = Enviroment.scene.primitives; Enviroment.points = Enviroment.primitives?.add(new Cesium.PointPrimitiveCollection({ blendOption: Cesium.BlendOption.TRANSLUCENT })); Enviroment.lines = Enviroment.primitives?.add(new Cesium.PolylineCollection()); Enviroment.labels = Enviroment.primitives?.add(new Cesium.LabelCollection({ blendOption: Cesium.BlendOption.TRANSLUCENT })); Enviroment.billboards = Enviroment.primitives?.add(new Cesium.BillboardCollection({ blendOption: Cesium.BlendOption.TRANSLUCENT })); } } dispose() { this.clearElement(); Enviroment.primitives.remove(Enviroment.points); Enviroment.points?.destroy(); Enviroment.primitives.remove(Enviroment.lines); Enviroment.lines?.destroy(); Enviroment.primitives.remove(Enviroment.labels); Enviroment.labels?.destroy(); Enviroment.primitives.remove(Enviroment.billboards); Enviroment.billboards?.destroy(); Enviroment.primitives?.removeAll(); Enviroment.primitives = undefined; } /** * 清空所有地图元素 * */ clearElement(): void { this.elementMap.forEach((element) => { this.removeMapElement(element); }) } /** * 通过id移除地图元素 * */ removeElement(id: string): void { const element = this._findElement(id); if (element != undefined) { this.removeMapElement(element); } } /** * 加载地图元素 * */ inflateElement(element: MapElement): void { element._inflateElement(); this.elementMap.set(element.id, element); } /** * 通过id获取地图元素 * */ _findElement(id: string): MapElement | undefined { return this.elementMap.get(id); } private removeMapElement(element: MapElement): void { element?._removeElement(); element?.dispose(); } defocusAllElement() { this.elementMap.forEach(element => element.stopEdit()); } } export const ElementManager = new _ElementManager(); export function findElement>(id?: string): T | undefined { if (id == undefined) { return; } // id = IdUtil.deserialize(id); return ElementManager._findElement(id) as any as T; }