import { dataService } from "../Service/DataService"; import { lineService } from "../Service/LineService"; import { listenLayer } from "../ListenLayer"; import VectorCategory from "../enum/VectorCategory"; export default class AddLine { constructor() { this.startInfo = {}; this.endInfo = {}; this.category = VectorCategory.Line.NormalLine; } setPointInfo(dir, pointInfo) { if (dir == "start") { this.startInfo = { position: { x: pointInfo.x, y: pointInfo.y, }, linkedPointId: pointInfo.linkedPointId, lineId: pointInfo.lineId, }; } else if (dir == "end") { this.endInfo = { position: { x: pointInfo.x, y: pointInfo.y, }, linkedPointId: pointInfo.linkedPointId, lineId: pointInfo.lineId, }; } } setNewLinePoint(dir, position) { if (dir == "start") { if (listenLayer.modifyPoint) { this.setPointInfo(dir, listenLayer.modifyPoint); } else { this.setPointInfo(dir, position); } return true; } else if (dir == "end") { if (listenLayer.modifyPoint) { this.setPointInfo(dir, listenLayer.modifyPoint); } else { this.setPointInfo(dir, position); } return true; } return false; } buildLine() { lineService.create( this.startInfo.position, this.endInfo.position, this.category ); listenLayer.clear(); this.clear(); } clear() { this.startInfo = {}; this.endInfo = {}; } } const addLine = new AddLine(); export { addLine };