// @ts-nocheck import { ActionManager } from "../../action/ActionManager" import type { Activeble, Disposable, ErrorCallback } from "../../Common" import { PlottingEle } from "./PlottingElement" import { PlottingEditor } from "./PlottingEditor" import MapElement from "../../map_element/MapElement" import { ModuleCode } from '../../Module'; import { Authorize } from '../../Authorize'; const PlottingCreateActionId = 'PlottingCreateActionId'; const PlottingActionId = 'PlottingActionId'; export class PlottingHelper implements Activeble, Disposable { readonly editorMap: Map = new Map(); private editor: PlottingEditor | undefined = undefined; private callback: ErrorCallback | undefined = undefined; constructor() { Authorize.check(ModuleCode.Plotting); } dispose(): void { this.deactive(); this.editorMap.clear(); } init(plottingList: Array = []): PlottingHelper { if(Authorize.without(ModuleCode.Plotting)){ return this; } plottingList.forEach(plotting => this.editorMap.set(plotting.id, new PlottingEditor(plotting))); return this; } onError(callback: ErrorCallback): PlottingHelper { this.callback = callback; return this; } /** * 创建新图形 * @param id * @returns */ createNew(id: string): PlottingHelper { if(Authorize.without(ModuleCode.Plotting)){ return this; } this.editor = new PlottingEditor(new PlottingEle(id)).active(); this.editorMap.set(id, this.editor); return this; } /** * 结束对当前图形的编辑 * @returns */ finishEdit(): PlottingHelper { if (this.editor != undefined) { this.editor.deactive(); // // 校验至少拥有一个图形信息 if (!this.editor.plotting.isQualified()) { this.removeTarget(); } this.editor = undefined; } return this; } /** * 移除图形 * @returns */ removeTarget(id?: string): PlottingHelper { if (id == undefined) { if (this.editor != undefined) { this.editor.deactive(); this.editor.plotting.dispose(); this.editorMap.delete(this.editor.plotting.id); } } else { const targetEditor = this.editorMap.get(id); if (targetEditor != undefined) { targetEditor.deactive(); targetEditor.plotting.dispose(); this.editorMap.delete(id); } } return this; } /** * 选中图形 * @returns */ targetPlotting(id: string): PlottingHelper { this.editor = this.editorMap.get(id); this.editor?.active(); return this; } active(): PlottingHelper { if(Authorize.without(ModuleCode.Plotting)){ return this; } ActionManager.newHelper(PlottingActionId) .simple.active() .simple.onLeftTap((helper, info) => { if (info.elementId == undefined) { return; } if (this.editor == undefined) { const groupId = MapElement.findElement(info.elementId)?.groupId; if (groupId != undefined) { this.targetPlotting(groupId); } return; } const groupId = MapElement.findElement(info.elementId)?.groupId; if (groupId != undefined && this.editor.plotting.marker?.id != groupId) { if (this.editor.plotting.isQualified()) { this.targetPlotting(groupId); } else { this.callback?.('当前标绘未编辑完成'); } } }) .simple.onRightTap((helper, info) => { if (this.editor == undefined || this.editor.plotting.isQualified()) { this.finishEdit(); } else { this.callback?.('当前标绘未编辑完成'); } }) return this; } deactive(): PlottingHelper { this.finishEdit(); ActionManager.removeHelper(PlottingCreateActionId); ActionManager.removeHelper(PlottingActionId); return this; } getTarget(): PlottingEditor | undefined { return this.editor; } }