import Load from "./Load"; import { stateService } from "./Service/StateService"; import { elementService } from "./Service/ElementService"; import { dataService } from "./Service/DataService"; import { textService } from "./Service/TextService"; import { historyService } from "./Service/HistoryService"; import UIControl from "./Controls/UIControl"; // import { moveRectangle } from "./Controls/MoveRectangle"; import { moveText } from "./Controls/MoveText"; import { addRoad } from "./Controls/AddRoad"; import { addLine } from "./Controls/AddLine"; import { addCircle } from "./Controls/AddCircle"; import { moveRoad } from "./Controls/MoveRoad"; import { coordinate } from "./Coordinate"; import Render from "./Renderer/Render"; import { draw } from "./Renderer/Draw"; import { listenLayer } from "./ListenLayer"; import LayerEvents from "./enum/LayerEvents.js"; import UIEvents from "./enum/UIEvents.js"; import SelectState from "./enum/SelectState.js"; import VectorType from "./enum/VectorType"; import { mathUtil } from "./Util/MathUtil"; import History from "./History/History"; import mitt from "mitt"; import { roadService } from "./Service/RoadService"; import { edgeService } from "./Service/EdgeService"; import { roadPointService } from "./Service/RoadPointService"; import { curveRoadService } from "./Service/CurveRoadService"; import VectorCategory from "./enum/VectorCategory"; const minDragDis = 10; export default class Layer { constructor(canvas, newsletter) { this.canvas = canvas; this.load = new Load(this); this.uiControl = new UIControl(this, newsletter); this.renderer = new Render(this); this.history = new History(this); this.mousePosition = null; this.dragging = false; // 当前是否正在拖拽 this.start(); Object.setPrototypeOf(Object.getPrototypeOf(this), mitt()); } start() { if (this.canvas) { this.canvas.width = this.canvas.clientWidth; this.canvas.height = this.canvas.clientHeight; coordinate.init(this.canvas); draw.initContext(this.canvas); dataService.initVectorData(); this.history.init(); this.bindEvents(); } window.vectorData = dataService.vectorData; } bindEvents() { this.canvas.addEventListener("contextmenu", function (e) { e.preventDefault(); }); this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this)); this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this)); this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this)); this.canvas.addEventListener("mousewheel", this.onWheel.bind(this)); this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this)); this.canvas.addEventListener("resize", this.reSize.bind(this)); document.addEventListener("keydown", this.onKeydown.bind(this)); } reSize = function () { console.log("resize"); coordinate.updateForCanvas(); this.renderer.autoRedraw(); }; onMouseDown(e) { this.startX = e.offsetX || e.layerX; this.startY = e.offsetY || e.layerY; this.lastX = e.offsetX || e.layerX; this.lastY = e.offsetY || e.layerY; let position = coordinate.getXYFromScreen({ x: this.startX, y: this.startY, }); // 右键 if (e.button == 2) { this.stopAddVector(); this.uiControl.currentUI = null; this.renderer.autoRedraw(); return; } this.dragging = false; this.setEventName("mouseDown"); const selectItem = stateService.getSelectItem(); const eventName = stateService.getEventName(); switch (eventName) { //用于支持平板电脑 case null: needAutoRedraw = listenLayer.start(position); stateService.getSelectItem(); if (needAutoRedraw) { this.renderer.autoRedraw(); } case LayerEvents.AddRoad: stateService.setEventName(LayerEvents.AddingRoad); addRoad.setNewRoadPoint("start", position); break; case LayerEvents.AddCurveRoad: stateService.setEventName(LayerEvents.AddingCurveRoad); addRoad.setNewRoadPoint("start", position); break; case LayerEvents.AddLine: stateService.setEventName(LayerEvents.AddingLine); addLine.setNewLinePoint("start", position); break; case LayerEvents.AddCircle: stateService.setEventName(LayerEvents.AddingCircle); addCircle.setCenter(position); break; } stateService.setDraggingItem(selectItem); // 清除上一个状态 // 设置当前事件名称 e.preventDefault(); e.stopPropagation(); } onMouseMove(e) { const X = e.offsetX || e.layerX; const Y = e.offsetY || e.layerY; let dx = X - this.lastX; let dy = Y - this.lastY; let position = coordinate.getXYFromScreen({ x: X, y: Y, }); this.mousePosition = { x: position.x, y: position.y, }; if ( Math.abs(X - this.startX) > minDragDis || Math.abs(Y - this.startY) > minDragDis ) { // 是否拖拽了 this.dragging = true; } const eventName = stateService.getEventName(); // 是否需要重绘 let needAutoRedraw = false; let point = null; const draggingItem = stateService.getDraggingItem(); switch (eventName) { case null: //监控 needAutoRedraw = listenLayer.start(position); let seleteItem = stateService.getSelectItem(); if (seleteItem != null) { console.log("选中:" + seleteItem.vectorId); } else { console.log("什么也没选中"); } break; case LayerEvents.PanBackGround: stateService.clearItems(); coordinate.center.x = coordinate.center.x - (dx * coordinate.defaultZoom) / coordinate.zoom; coordinate.center.y = coordinate.center.y + (dy * coordinate.defaultZoom) / coordinate.zoom; dataService.setGridForPan( (dx * coordinate.defaultZoom) / coordinate.zoom, (dy * coordinate.defaultZoom) / coordinate.zoom ); this.lastX = X; this.lastY = Y; needAutoRedraw = true; break; case LayerEvents.AddRoad: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.hideAll(); elementService.setPoint(position); elementService.showPoint(); if (listenLayer.modifyPoint) { elementService.execute(listenLayer.modifyPoint, position); } break; case LayerEvents.AddLine: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.hideAll(); elementService.setPoint(position); elementService.showPoint(); if (listenLayer.modifyPoint) { elementService.execute(listenLayer.modifyPoint, position); } break; case LayerEvents.AddCircle: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.hideAll(); elementService.setPoint(position); elementService.showPoint(); if (listenLayer.modifyPoint) { elementService.execute(listenLayer.modifyPoint, position); } break; case LayerEvents.AddingRoad: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.execute(addRoad.startInfo.position, position); elementService.setPoint(position); elementService.setNewRoad(addRoad.startInfo.position, position); elementService.showNewRoad(); addRoad.setNewRoadPoint("end", position); addRoad.canAdd = addRoad.canAddRoadForEnd(position); if (!addRoad.canAdd) { elementService.setNewRoadState("error"); } else { elementService.setNewRoadState("normal"); } break; case LayerEvents.AddingLine: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.execute(addLine.startInfo.position, position); elementService.setPoint(position); elementService.setNewLine(addLine.startInfo.position, position); elementService.setNewLineCategory(VectorCategory.Line.NormalLine); elementService.showNewLine(); addLine.setNewLinePoint("end", position); break; case LayerEvents.AddingCircle: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.execute(addCircle.center, position); elementService.setPoint(position); addCircle.setRadius(mathUtil.getDistance(addCircle.center, position)); break; case LayerEvents.MoveRoad: needAutoRedraw = true; //只允许拖拽一条公路 let road = dataService.getRoad(draggingItem.vectorId); let start = dataService.getRoadPoint(road.startId); let end = dataService.getRoadPoint(road.endId); if ( Object.keys(start.getParent()).length == 1 && Object.keys(end.getParent()).length == 1 ) { //拖拽的路只有一条 moveRoad.moveRoad( draggingItem.vectorId, (dx * coordinate.defaultZoom) / coordinate.zoom, (dy * coordinate.defaultZoom) / coordinate.zoom ); } this.lastX = X; this.lastY = Y; break; case LayerEvents.MoveRoadPoint: point = dataService.getRoadPoint(draggingItem.vectorId); listenLayer.start(position, { exceptRoadPointId: draggingItem.vectorId, exceptRoadIds: point.parent, }); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } let flag = moveRoad.moveingRoadPoint( draggingItem.vectorId, position, listenLayer.modifyPoint ); if (!flag) { elementService.hideAll(); } else { // point = dataService.getRoadPoint(draggingItem.vectorId); // listenLayer.start(point, { // exceptRoadPointId: draggingItem.vectorId, // exceptRoadIds: point.parent, // }); let otherPoint = null; if ( listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointId ) { otherPoint = dataService.getRoadPoint( listenLayer.modifyPoint.linkedRoadPointId ); } else if ( listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdX ) { otherPoint = dataService.getRoadPoint( listenLayer.modifyPoint.linkedRoadPointIdX ); } else if ( listenLayer.modifyPoint && listenLayer.modifyPoint.linkedRoadPointIdY ) { otherPoint = dataService.getRoadPoint( listenLayer.modifyPoint.linkedRoadPointIdY ); } elementService.execute(otherPoint, point); } needAutoRedraw = true; break; case LayerEvents.AddCurveRoad: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.hideAll(); elementService.setPoint(position); elementService.showPoint(); if (listenLayer.modifyPoint) { elementService.execute(listenLayer.modifyPoint, position); } break; case LayerEvents.AddingCurveRoad: needAutoRedraw = true; listenLayer.start(position); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } elementService.execute(addRoad.startInfo.position, position); elementService.setPoint(position); elementService.setNewRoad(addRoad.startInfo.position, position); elementService.showNewRoad(); addRoad.setNewRoadPoint("end", position); addRoad.canAdd = addRoad.canAddRoadForEnd(position); if (!addRoad.canAdd) { elementService.setNewRoadState("error"); } else { elementService.setNewRoadState("normal"); } break; case LayerEvents.MoveCurveRoad: needAutoRedraw = true; moveRoad.moveCurveRoad( draggingItem.vectorId, (dx * coordinate.defaultZoom) / coordinate.zoom, (dy * coordinate.defaultZoom) / coordinate.zoom ); this.lastX = X; this.lastY = Y; break; case LayerEvents.MoveCurveRoadPoint: if (!draggingItem || !draggingItem.vectorId) { return; } point = dataService.getCurveRoadPoint(draggingItem.vectorId); listenLayer.start(position, { exceptRoadPointId: draggingItem.vectorId, exceptCurveRoadId: point.parent, //不会融合,所以parent只有一个 }); if (listenLayer.modifyPoint) { position = { x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }; } moveRoad.moveCurveRoadPoint(draggingItem.vectorId, position); needAutoRedraw = true; break; case LayerEvents.MoveControlPoint: if (!draggingItem || !draggingItem.vectorId) { return; } moveRoad.moveControlPoint(draggingItem.vectorId, position); needAutoRedraw = true; break; case LayerEvents.MoveEdge: moveRoad.moveEdge(draggingItem.vectorId, position); needAutoRedraw = true; break; case LayerEvents.MoveCurveEdge: if (listenLayer.modifyPoint) { moveRoad.moveCurveEdge( draggingItem.vectorId, listenLayer.modifyPoint.selectIndex, position ); } needAutoRedraw = true; break; case LayerEvents.AddText: needAutoRedraw = true; if (draggingItem == null) { const text = textService.createText(position); if (text.vectorId) { stateService.setSelectItem( text.vectorId, VectorType.Text, SelectState.Select ); stateService.setDraggingItem(stateService.selectItem); } } else { moveText.moveFullText(position, draggingItem.vectorId); } break; case LayerEvents.MoveText: needAutoRedraw = true; if (draggingItem != null) { moveText.moveFullText(position, draggingItem.vectorId); } break; } if (needAutoRedraw) { this.renderer.autoRedraw(); } } onMouseUp(e) { // 右键 if (e.button == 2) { return; } const X = e.offsetX || e.layerX; const Y = e.offsetY || e.layerY; let eventName = stateService.getEventName(); const draggingItem = stateService.getDraggingItem(); const selectItem = stateService.getSelectItem(); let focusItem = null; if (!this.dragging && selectItem) { focusItem = { vectorId: selectItem.vectorId, type: selectItem.type, cursor: { x: this.lastX, y: this.lastY }, }; stateService.setFocusItem(focusItem); this.uiControl.focusVector = focusItem; stateService.clearDraggingItem(); } let position = coordinate.getXYFromScreen({ x: X, y: Y, }); let needAutoRedraw = false; switch (eventName) { case null: return; case LayerEvents.PanBackGround: needAutoRedraw = true; stateService.clearFocusItem(); this.uiControl.focusVector = null; this.uiControl.currentUI = null; break; case LayerEvents.MoveRoadPoint: if (!draggingItem || !draggingItem.vectorId) { break; } needAutoRedraw = true; elementService.hideAll(); let point = dataService.getRoadPoint(draggingItem.vectorId); if (point) { listenLayer.start(point, { exceptPointId: draggingItem.vectorId, exceptRoadIds: point.parent, }); if ( listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty("linkedRoadPointId") ) { moveRoad.moveTo( draggingItem.vectorId, listenLayer.modifyPoint.linkedRoadPointId ); } else if ( listenLayer.modifyPoint && (listenLayer.modifyPoint.linkedRoadPointIdX || listenLayer.modifyPoint.linkedRoadPointIdY) ) { mathUtil.clonePoint(point, listenLayer.modifyPoint); } else if ( listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty("linkedRoadId") ) { point = roadPointService.create({ x: listenLayer.modifyPoint.x, y: listenLayer.modifyPoint.y, }); roadService.splitRoad( listenLayer.modifyPoint.linkedRoadId, point.vectorId, "start" ); moveRoad.moveTo(draggingItem.vectorId, point.vectorId); } else if (moveRoad.splitRoadId != null) { roadService.splitRoad( moveRoad.splitRoadId, draggingItem.vectorId, "start" ); } //draggingItem.vectorId所在的墙面与其他墙角相交 moveRoad.updateForAbsorbRoadPoints(); let parent = point.getParent(); for (let key in parent) { roadService.setLanes(key); } this.history.save(); } break; // case LayerEvents.AddRoad: // addRoad.setNewRoadPoint("start", position); // break; case LayerEvents.AddingRoad: needAutoRedraw = true; if (addRoad.canAdd) { addRoad.buildRoad(); addRoad.clear(); this.history.save(); elementService.hideAll(); } break; case LayerEvents.AddingLine: needAutoRedraw = true; addLine.buildLine(); addLine.clear(); this.history.save(); elementService.hideAll(); break; case LayerEvents.AddingCircle: needAutoRedraw = true; addCircle.buildCircle(); addCircle.clear(); this.history.save(); elementService.hideAll(); break; // case LayerEvents.AddCurveRoad: // addRoad.setNewRoadPoint("start", position); // break; case LayerEvents.AddingCurveRoad: needAutoRedraw = true; if (addRoad.canAdd) { addRoad.buildCurveRoad(); addRoad.clear(); this.history.save(); elementService.hideAll(); } break; case LayerEvents.MoveRoad: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveCurveRoad: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveCurveRoadPoint: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveControlPoint: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveEdge: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveCurveEdge: needAutoRedraw = true; this.history.save(); break; case LayerEvents.MoveText: needAutoRedraw = true; if (focusItem != null && focusItem.type == VectorType.Text) { this.uiControl.currentUI = focusItem.type; } this.history.save(); break; } this.setEventName("mouseUp"); stateService.clearDraggingItem(); this.renderer.autoRedraw(); } onWheel(e) { e.preventDefault(); const type = e.type; if (type == "DOMMouseScroll" || type == "mousewheel") { // 当在canvas用滚轮滚动时 const delta = e.wheelDelta ? (e.wheelDelta / 120) * 20 : (-(e.detail || 0) / 3) * 20; const zoom = coordinate.zoom + delta; if (zoom < 14) { return; } coordinate.updateZoom(zoom); dataService.setGridForZoom( coordinate.width, coordinate.height, coordinate.zoom / coordinate.defaultZoom ); this.renderer.autoRedraw(); } } //测试用 onKeydown(e) { let focusItem = stateService.getFocusItem(); let dir = "left"; if (focusItem) { console.log("键盘(foucus有效):" + e.code); if (e.code == "Delete") { //删除 const road = dataService.getRoad(focusItem.vectorId); roadService.subtraRoadFromIntersect(road.startId, focusItem.vectorId); roadService.subtraRoadFromIntersect(road.endId, focusItem.vectorId); //dataService.deleteControlPoint() dataService.deleteRoad(focusItem.vectorId); this.renderer.autoRedraw(); this.history.save(); } //加宽 else if (e.code == "KeyA") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForWidth(road.vectorId, road.leftWidth + 50, dir); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForWidth( road.vectorId, road.leftWidth + 50, dir ); } this.renderer.autoRedraw(); this.history.save(); } //变窄 else if (e.code == "KeyB") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForWidth(road.vectorId, road.leftWidth - 25, dir); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForWidth( road.vectorId, road.leftWidth - 25, dir ); } this.renderer.autoRedraw(); this.history.save(); } //添加左车道 else if (e.code == "KeyQ") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForAddSubtractLanesCount( focusItem.vectorId, road.leftDrivewayCount + 1, "left" ); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForAddSubtractLanesCount( road, road.leftDrivewayCount + 1, //rightDrivewayCount "left" ); } this.renderer.autoRedraw(); this.history.save(); } //减少左车道 else if (e.code == "KeyW") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForAddSubtractLanesCount( focusItem.vectorId, road.leftDrivewayCount - 1, "left" ); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForAddSubtractLanesCount( road, road.leftDrivewayCount - 1, //rightDrivewayCount "left" ); } this.renderer.autoRedraw(); this.history.save(); } //添加右车道 else if (e.code == "KeyE") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForAddSubtractLanesCount( focusItem.vectorId, road.rightDrivewayCount + 1, "right" ); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForAddSubtractLanesCount( road, road.rightDrivewayCount + 1, //rightDrivewayCount "right" ); } this.renderer.autoRedraw(); this.history.save(); } //减少右车道 else if (e.code == "KeyR") { let road = dataService.getRoad(focusItem.vectorId); if (road) { roadService.updateForAddSubtractLanesCount( focusItem.vectorId, road.rightDrivewayCount - 1, "right" ); } else { road = dataService.getCurveRoad(focusItem.vectorId); curveRoadService.updateForAddSubtractLanesCount( road, road.rightDrivewayCount - 1, //rightDrivewayCount "right" ); } this.renderer.autoRedraw(); this.history.save(); } //弯路添加控制点 else if (e.code == "KeyT") { const curveRoad = dataService.getCurveRoad(focusItem.vectorId); let index = mathUtil.getIndexForCurvesPoints( this.mousePosition, curveRoad.points ); if (index != -1) { curveRoadService.addCPoint(curveRoad, this.mousePosition, index); } else { const dis1 = mathUtil.getDistance( curveRoad.points[0], this.mousePosition ); const dis2 = mathUtil.getDistance( curveRoad.points[curveRoad.points.length - 1], this.mousePosition ); if (dis1 > dis2) { curveRoadService.addCPoint( curveRoad, this.mousePosition, curveRoad.points.length - 2 ); } else { curveRoadService.addCPoint(curveRoad, this.mousePosition, 1); } } this.renderer.autoRedraw(); this.history.save(); } //弯路删除控制点 else if (e.code == "KeyY") { const curvePoint = dataService.getCurveRoadPoint(focusItem.vectorId); const curveRoad = dataService.getCurveRoad(curvePoint.parent); curveRoadService.subCPoint(curveRoad, curvePoint.getIndex()); this.renderer.autoRedraw(); this.history.save(); } } else { console.log("键盘(foucus无效):" + e.code); } } setEventName(eventType) { let eventName = stateService.getEventName(); if (eventType == "mouseDown") { if (eventName == null) { const selectItem = stateService.getSelectItem(); if (selectItem == null) { stateService.setEventName(LayerEvents.PanBackGround); } else if (selectItem.type == VectorType.Road) { stateService.setEventName(LayerEvents.MoveRoad); } else if (selectItem.type == VectorType.RoadPoint) { stateService.setEventName(LayerEvents.MoveRoadPoint); } else if (selectItem.type == VectorType.CurveRoad) { stateService.setEventName(LayerEvents.MoveCurveRoad); } else if (selectItem.type == VectorType.CurveRoadPoint) { stateService.setEventName(LayerEvents.MoveCurveRoadPoint); } else if (selectItem.type == VectorType.ControlPoint) { stateService.setEventName(LayerEvents.MoveControlPoint); } else if (selectItem.type == VectorType.RoadEdge) { stateService.setEventName(LayerEvents.MoveEdge); } else if (selectItem.type == VectorType.CurveRoadEdge) { stateService.setEventName(LayerEvents.MoveCurveEdge); } else if (selectItem.type == VectorType.Line) { stateService.setEventName(LayerEvents.MoveLine); } else if (selectItem.type == VectorType.CurveLine) { stateService.setEventName(LayerEvents.MoveCurveLine); } else if (selectItem.type == VectorType.Circle) { stateService.setEventName(LayerEvents.MoveCircle); } } } else if (eventType == "mouseUp") { if (eventName == LayerEvents.AddText) { //可连续添加 //stateService.clearEventName() } // else if (eventName == LayerEvents.AddRoad) { // stateService.setEventName(LayerEvents.AddingRoad); // } else if (eventName == LayerEvents.AddingRoad) { stateService.setEventName(LayerEvents.AddRoad); } else if (eventName == LayerEvents.AddingLine) { stateService.setEventName(LayerEvents.AddLine); } // else if (eventName == LayerEvents.AddCurveRoad) { // stateService.setEventName(LayerEvents.AddingCurveRoad); // } else if (eventName == LayerEvents.AddingCurveRoad) { stateService.setEventName(LayerEvents.AddCurveRoad); } else if (eventName == LayerEvents.AddLine) { stateService.setEventName(LayerEvents.AddingLine); } else if (eventName == LayerEvents.AddingLine) { stateService.setEventName(LayerEvents.AddLine); } else { stateService.clearEventName(); } } } exit() { stateService.clear(); this.uiControl.clearUI(); this.uiControl.focusVector = null; } stopAddVector() { let eventName = stateService.getEventName(); if ( eventName != LayerEvents.AddingRoad && eventName != LayerEvents.AddingLine ) { stateService.clearEventName(); } else if (eventName == LayerEvents.AddingRoad) { stateService.setEventName(LayerEvents.AddRoad); } else if (eventName == LayerEvents.AddingLine) { stateService.setEventName(LayerEvents.AddLine); } this.uiControl.clearUI(); elementService.hideAll(); } update() {} revokeHistory() { this.history.goPreState(); this.renderer.autoRedraw(); } recoveryHistory() { this.history.goNextState(); this.renderer.autoRedraw(); } }