// @ts-nocheck import type { Disposable } from '../Common' import Utils from '../Utils' import { ElementManager } from './ElementManager' import type { DesCallback, Stateble, Positeble, Areable, PositeInfo, AreaInfo, Groupable } from './Common' import { ElementOperator } from './Common' export abstract class BaseElement> implements Groupable, Stateble, Disposable { readonly id: string; groupId: string; // 是否处于编辑状态 protected editing: boolean = true; // 是否可见 protected visible: boolean = true; protected constructor(id: string) { this.id = id; this.groupId = id; } abstract dispose(): void; abstract _inflateElement(): void; abstract _removeElement(): void; abstract _resetElement(): void; abstract refreshGeo(): void; asGroup(groupId: string): T { this.groupId = groupId; return this.asType(); } /** * 开始编辑 * */ startEdit(): T { this.editing = true; this.refreshGeo(); return this.asType(); } /** * 结束编辑 * */ stopEdit(): T { this.editing = false; this.refreshGeo(); return this.asType(); } /** * 是否处于编辑模式 * */ isEditing() { return this.editing; } /** * 显示 * */ show(): T { this.visible = true; this.refreshGeo(); return this.asType(); } /** * 隐藏 * */ hide(): T { this.visible = false; this.refreshGeo(); return this.asType(); } /** * 是否可见 * */ isVisible(): boolean { return this.visible; } protected asType(): T { return this as any as T; } } export abstract class MapElement, T extends MapElement> extends BaseElement { readonly des: Des; readonly info: Info; protected operator: Operator | undefined = undefined; protected constructor(id: string, info: Info, des?: Des,) { super(id); this.info = info; this.des = des ?? this.createDes(); } protected abstract createDes(): Des; dispose(): void { this._removeElement(); }; _answerDrag(): boolean { return true; } abstract init(): T; _inflateElement(): void { this.operator!.inflate(); } _removeElement(): void { this.operator!.remove(); } _resetElement(): void { this._removeElement(); this._inflateElement(); } protected repositeGeo(): void { this.operator!.reposite(); } /** * 加载元素至地图 * */ inflate(): T { ElementManager.inflateElement(this); return this.asType(); } /** * 自定义样式 * @param callback 样式回调 * @returns */ custom(callback: DesCallback): T { callback(this.des); return this.asType(); } /** * 更新 * */ refreshGeo(): void { this.operator!.refresh(); } } export abstract class PositebleElement, T extends PositebleElement> extends MapElement implements Positeble>{ /** * 移动位置 * */ move(vector: Cesium.Cartesian3): T { this.info.position = Utils.Vector.move(this.info.position, vector); this.repositeGeo(); return this.asType(); } /** * 重置位置 * */ reposite(position: Cesium.Cartesian3): T { this.info.position = position; this.repositeGeo(); return this.asType(); } } export abstract class AreableElement, T extends AreableElement> extends MapElement implements Areable>{ /** * 移动位置 * */ move(vector: Cesium.Cartesian3): T { this.info.vector = vector; for (let i = 0, s = this.info.positionList?.length; i < s; i++) { const position: Cesium.Cartesian3 = this.info.positionList[i]; this.info.positionList[i] = Utils.Vector.move(position, vector); } this.repositeGeo(); this.info.vector = undefined; return this.asType(); } /** * 重置所有数据点 * */ repositeArea(positionList: Array): T { this.info.positionList = positionList; this._resetElement(); return this.asType(); } }