// @ts-nocheck import type { GroundPolygonEle } from "../../map_element/element/Polygon"; import type { Activeble, Disposable } from "../../Common"; import { ActionManager } from '../../action/ActionManager' import { PolygonEditor } from '../../editor/PolygonEditor' import { ModuleCode } from '../../Module'; import { Authorize } from '../../Authorize'; const MonomerActionId = 'MonomerActionId'; export class MonomerHelper implements Activeble, Disposable { readonly eleMap: Map = new Map(); constructor(){ Authorize.check(ModuleCode.Monomer); } dispose(): void { this.deactive(); this.eleMap.clear(); } init(eleList: Array = []): MonomerHelper { if(Authorize.without(ModuleCode.Monomer)){ return this; } eleList.forEach(ele => this.eleMap.set(ele.id, ele)); return this; } /** * 创建新图形 * @param id * @returns */ createNew(id: string): MonomerHelper { if(Authorize.without(ModuleCode.Monomer)){ return this; } PolygonEditor.newGroundPolygon(id).active(); const polygon = PolygonEditor.holder.polygon; this.eleMap.set(polygon!.id, polygon!); return this; } /** * 重置图形 * @returns */ resetTarget(): MonomerHelper { PolygonEditor.clear(); return this; } /** * 结束对当前图形的编辑 * @returns */ finishEdit(): MonomerHelper { PolygonEditor.unbindPolygon(); return this; } /** * 移除图形 * @returns */ removeTarget(id?: string): MonomerHelper { if (id == undefined) { id = PolygonEditor.holder.polygon?.id; } if (id == PolygonEditor.holder.polygon?.id) { PolygonEditor.unbindPolygon(); } if (id == undefined) { return this; } this.eleMap.get(id)?.dispose(); this.eleMap.delete(id); return this; } active(): MonomerHelper { if(Authorize.without(ModuleCode.Monomer)){ return this; } ActionManager.newHelper(MonomerActionId) .simple.active() .simple.onLeftTap((helper, info) => { if (PolygonEditor.holder.polygon?.isEditing()) { return; } if (info.elementId == undefined) { return; } const polygon = this.eleMap.get(info.elementId); if (polygon == undefined) { return; } PolygonEditor.bindPolygon(polygon).active(); }) return this; } deactive(): MonomerHelper { ActionManager.removeHelper(MonomerActionId); PolygonEditor.unbindPolygon(); return this; } }