123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996 |
- import Load from "./Load";
- import { stateService } from "./Service/StateService";
- import { elementService } from "./Service/ElementService";
- import { floorplanService } from "./Service/FloorplanService";
- import { tagService } from "./Service/TagService";
- import { tableService } from "./Service/TableService";
- import { historyService } from "./Service/HistoryService";
- import UIControl from "./Controls/UIControl";
- import { moveTag } from "./Controls/MoveTag";
- import { moveTable } from "./Controls/MoveTable";
- import { addWall } from "./Controls/AddWall";
- import { moveWall } from "./Controls/MoveWall";
- import { addRectangle } from "./Controls/AddRectangle";
- import { moveRectangle } from "./Controls/MoveRectangle";
- import { addCircle } from "./Controls/AddCircle";
- import { moveCircle } from "./Controls/MoveCircle";
- import { addIcon } from "./Controls/AddIcon";
- import { moveIcon } from "./Controls/MoveIcon";
- import { addArrow } from "./Controls/AddArrow";
- import { moveArrow } from "./Controls/MoveArrow";
- import { coordinate } from "./Coordinate";
- import Render from "./Renderer/Render";
- import { draw } from "./Renderer/Draw";
- import { listenLayer } from "./ListenLayer";
- import { floorplanData } from "./FloorplanData";
- import LayerEvents from "./enum/LayerEvents.js";
- import UIEvents from "./enum/UIEvents.js";
- import SelectState from "./enum/SelectState.js";
- import Constant from "./Constant";
- import VectorType from "./enum/VectorType";
- import MathUtil, { mathUtil } from "./MathUtil";
- import { wallService } from "./Service/WallService";
- import { history } from "./History/History.js";
- import { signService } from "./Service/SignService";
- import { iconService } from "./Service/IconService";
- import { customImageService } from "./Service/CustomImageService.js";
- import { moveCustomImage } from "./Controls/MoveCustomImage.js";
- import { moveBgImage } from "./Controls/MoveBgImage.js";
- export default class Layer {
- constructor() {
- //super()
- this.load = new Load(this);
- this.uiControl = new UIControl(this);
- this.renderer = new Render(this);
- //this.history = new History(this)
- this.canvas = null;
- this.startX = null;
- this.startY = null;
- history.layer = this;
- }
- //开始
- start(canvas, vectorData) {
- coordinate.init(canvas);
- this.canvas = canvas;
- draw.initContext(this.canvas);
- this.bindEvents();
- return this.load.load(vectorData).then(() => {
- //。。。
- this.renderer.autoRedraw();
- });
- }
- 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));
- }
- 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;
- // 右键
- if (e.button == 2) {
- this.stopAddVector();
- this.renderer.autoRedraw();
- return;
- }
- const eventName = stateService.getEventName();
- //点击第一次
- if (eventName == LayerEvents.AddWall) {
- let flag = addWall.setNewWallPoint("start", {
- x: this.startX,
- y: this.startY,
- });
- if (!flag) {
- return;
- }
- }
- //点击第二次
- else if (eventName == LayerEvents.AddingWall) {
- let flag = addWall.setNewWallPoint("end", {
- x: this.startX,
- y: this.startY,
- });
- if (!flag) {
- return;
- }
- if (addWall.canAdd) {
- addWall.buildWall();
- history.save();
- } else {
- return;
- }
- } else if (eventName == LayerEvents.AddRectangle) {
- addRectangle.execute({
- x: this.startX,
- y: this.startY,
- });
- } else if (eventName == LayerEvents.AddCircle) {
- addCircle.execute({
- x: this.startX,
- y: this.startY,
- });
- } else if (eventName == LayerEvents.AddIcon) {
- addIcon.execute({
- x: this.startX,
- y: this.startY,
- });
- } else if (eventName == LayerEvents.AddArrow) {
- addArrow.execute({
- x: this.startX,
- y: this.startY,
- });
- } else {
- const selectItem = stateService.getSelectItem();
- if (eventName == null && selectItem) {
- stateService.setDraggingItem(selectItem);
- this.uiControl.selectUI = selectItem.type;
- }
- // else if (eventName == null) {
- // this.uiControl.clearUI();
- // }
- }
- this.setEventName("mouseDown");
- this.uiControl.clearUI();
- // 清除上一个状态
- // 设置当前事件名称
- e.preventDefault();
- e.stopPropagation();
- }
- onMouseMove(e) {
- const X = e.offsetX || e.layerX;
- const Y = e.offsetY || e.layerY;
- if (this.lastX == null) {
- this.lastX = X;
- }
- if (this.lastY == null) {
- this.lastY = Y;
- }
- let dx = X - this.lastX;
- let dy = Y - this.lastY;
- let position = coordinate.getXYFromScreen({
- x: X,
- y: Y,
- });
- const eventName = stateService.getEventName();
- // 是否需要重绘
- let needAutoRedraw = false;
- const draggingItem = stateService.getDraggingItem();
- switch (eventName) {
- case null:
- //监控当前选择的构件
- needAutoRedraw = listenLayer.start(position);
- break;
- case LayerEvents.PanBackGround:
- break;
- case LayerEvents.AddWall:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- listenLayer.start(position);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.execute(null, position);
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- break;
- case LayerEvents.AddingWall:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- let startPosition = {
- x: addWall.startInfo.position.x,
- y: addWall.startInfo.position.y,
- };
- listenLayer.start(position, null, null, startPosition);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.execute(startPosition, position);
- elementService.setStartAddWall(position);
- if (!elementService.newWall.display) {
- elementService.setNewWall(startPosition, position);
- elementService.showNewWall(); //画墙
- } else {
- if (!listenLayer.modifyPoint && addWall.startInfo.linkedPointId) {
- //角度很正
- let newEndPosition = elementService.checkAngle(
- position,
- addWall.startInfo.linkedPointId,
- null
- );
- if (newEndPosition) {
- mathUtil.clonePoint(position, newEndPosition);
- listenLayer.modifyPoint = {
- x: newEndPosition.x,
- y: newEndPosition.y,
- };
- }
- }
- elementService.setNewWallEndPosition(position); //改变end位置
- }
- addWall.canAdd = addWall.canAddWallForEnd(position);
- if (!addWall.canAdd) {
- elementService.setNewWallState("error");
- } else {
- elementService.setNewWallState("normal");
- }
- break;
- case LayerEvents.MoveWall:
- dx = (dx * Constant.defaultZoom) / coordinate.zoom;
- dy = (dy * Constant.defaultZoom) / coordinate.zoom;
- // 1表示可以继续移动,2表示不能移动(启动距离还不够),3表示wallId被删除了,4表示重新开始移动(需要达到一定距离才能启动),5表示不能移动(不合适)
- let moveFlag = moveWall.moveWallPlane(draggingItem.vectorId, dx, dy);
- // 启动的时候需要点距离,所以真正移动了才更新lastX和lastY
- if (moveFlag == 1) {
- this.lastX = X;
- this.lastY = Y;
- needAutoRedraw = true;
- }
- // 需要继续保持移动,一般是距离不够启动
- else if (moveFlag == 2) {
- }
- // wallId被删除了
- else if (moveFlag == 3) {
- history.save();
- stateService.clearSelectItem();
- stateService.clearDraggingItem();
- stateService.clearEventName();
- listenLayer.clear();
- needAutoRedraw = true;
- }
- // wallId有一端被吸附了,这时候需要重新启动
- else if (moveFlag == 4) {
- this.lastX = X;
- this.lastY = Y;
- this.startX = X;
- this.startY = Y;
- needAutoRedraw = true;
- } else if (moveFlag == 5) {
- this.lastX = X;
- this.lastY = Y;
- }
- break;
- case LayerEvents.MoveWallPoint:
- let point = floorplanService.getPoint(draggingItem.vectorId);
- listenLayer.start(position, draggingItem.vectorId, point.parent);
- if (listenLayer.modifyPoint) {
- position = {
- x: listenLayer.modifyPoint.x,
- y: listenLayer.modifyPoint.y,
- };
- }
- elementService.execute(null, position);
- let flag = moveWall.movePoint(
- draggingItem.vectorId,
- position,
- listenLayer.modifyPoint
- );
- if (!flag) {
- elementService.hideAll();
- }
- needAutoRedraw = true;
- break;
- case LayerEvents.AddRectangle:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- break;
- case LayerEvents.AddingRectangle:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- addRectangle.execute(position);
- break;
- case LayerEvents.MoveRectangle:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveRectangle.moveFullRectangle(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.MoveRectangleVertex:
- needAutoRedraw = true;
- if (draggingItem != null) {
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- moveRectangle.moveRectangleVertex(
- position,
- draggingItem.vectorId,
- parseInt(draggingItem.selectIndex.substring(7))
- );
- }
- break;
- case LayerEvents.MoveRectangleSide:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveRectangle.moveRectangleSide(
- position,
- draggingItem.vectorId,
- parseInt(draggingItem.selectIndex.substring(5))
- );
- }
- break;
- case LayerEvents.AddCircle:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- break;
- case LayerEvents.AddingCircle:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- addCircle.execute(position);
- break;
- case LayerEvents.MoveCircle:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveCircle.moveFullCircle(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.MoveCircleVertex:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveCircle.moveCircleVertex(
- position,
- draggingItem.vectorId,
- parseInt(draggingItem.selectIndex.substring(7))
- );
- }
- break;
- case LayerEvents.AddIcon:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- break;
- case LayerEvents.AddingIcon:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- addIcon.execute(position);
- break;
- case LayerEvents.MoveIcon:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveIcon.moveFullIcon(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.MoveIconVertex:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveIcon.moveIconVertex(
- position,
- draggingItem.vectorId,
- parseInt(draggingItem.selectIndex.substring(7))
- );
- }
- break;
- case LayerEvents.AddArrow:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- break;
- case LayerEvents.AddingArrow:
- stateService.clearDraggingItem();
- stateService.clearFocusItem();
- needAutoRedraw = true;
- elementService.setStartAddWall(position);
- elementService.showStartAddWall();
- addArrow.execute(position);
- break;
- case LayerEvents.MoveArrow:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveArrow.moveFullArrow(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.moveArrowVertex:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveArrow.moveArrowVertex(
- position,
- draggingItem.vectorId,
- draggingItem.selectIndex
- );
- }
- break;
- case LayerEvents.AddTag:
- needAutoRedraw = true;
- if (draggingItem == null) {
- const tag = tagService.createTag(position);
- if (tag.vectorId) {
- stateService.setSelectItem(
- tag.vectorId,
- VectorType.Tag,
- SelectState.All
- );
- stateService.setDraggingItem(stateService.selectItem);
- }
- } else {
- moveTag.moveFullTag(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.MoveTag:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveTag.moveFullTag(dx, dy, draggingItem.vectorId);
- this.lastX = X;
- this.lastY = Y;
- }
- break;
- case LayerEvents.AddTable:
- needAutoRedraw = true;
- if (draggingItem == null) {
- const table = tableService.createTable(position);
- if (table.vectorId) {
- stateService.setSelectItem(
- table.vectorId,
- VectorType.Table,
- SelectState.All
- );
- stateService.setDraggingItem(stateService.selectItem);
- }
- } else {
- moveTable.moveFullTable(dx, dy, draggingItem.vectorId);
- }
- this.lastX = X;
- this.lastY = Y;
- break;
- case LayerEvents.MoveTable:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveTable.moveFullTable(dx, dy, draggingItem.vectorId);
- this.lastX = X;
- this.lastY = Y;
- }
- break;
- case LayerEvents.AddSign:
- needAutoRedraw = true;
- if (draggingItem == null) {
- const signType = this.uiControl.getSignTypeForUI();
- const sign = signService.createSign(position, signType);
- if (sign.vectorId) {
- stateService.setSelectItem(
- sign.vectorId,
- signType,
- SelectState.All
- );
- stateService.setDraggingItem(stateService.selectItem);
- }
- } else {
- const sign = floorplanService.getSign(draggingItem.vectorId);
- mathUtil.clonePoint(sign.center, position);
- }
- break;
- case LayerEvents.MoveCustomImage:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveCustomImage.moveFullCustomImage(dx, dy, draggingItem.vectorId);
- this.lastX = X;
- this.lastY = Y;
- }
- break;
- case LayerEvents.MoveSign:
- needAutoRedraw = true;
- const sign = floorplanService.getSign(draggingItem.vectorId);
- mathUtil.clonePoint(sign.center, position);
- break;
- case LayerEvents.MoveBgImage:
- needAutoRedraw = true;
- if (draggingItem != null) {
- moveBgImage.moveFullBgImage(dx, dy, draggingItem.vectorId);
- this.lastX = X;
- this.lastY = Y;
- }
- break;
- }
- if (needAutoRedraw) {
- this.renderer.autoRedraw();
- }
- }
- onMouseUp(e) {
- const X = e.offsetX || e.layerX;
- const Y = e.offsetY || e.layerY;
- let eventName = stateService.getEventName();
- const draggingItem = stateService.getDraggingItem();
- let focusItem = null;
- if (draggingItem && draggingItem.vectorId) {
- if (
- mathUtil.getDistance(
- {
- x: this.startX,
- y: this.startY,
- },
- {
- x: X,
- y: Y,
- }
- ) < Constant.minMovePix
- ) {
- focusItem = {
- vectorId: draggingItem.vectorId,
- type: draggingItem.type,
- selectIndex: draggingItem.selectIndex,
- cursor: { x: this.lastX, y: this.lastY },
- };
- this.uiControl.showAttributes(focusItem);
- } else {
- focusItem = null;
- }
- stateService.setFocusItem(focusItem);
- //this.uiControl.clearUI();
- }
- 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.clearUI();
- break;
- case LayerEvents.MoveWallPoint:
- if (focusItem == null) {
- needAutoRedraw = true;
- let point = floorplanService.getPoint(draggingItem.vectorId);
- if (point) {
- listenLayer.start(point, draggingItem.vectorId, point.parent);
- if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.hasOwnProperty("linkedPointId")
- ) {
- wallService.moveTo(
- draggingItem.vectorId,
- listenLayer.modifyPoint.linkedPointId
- );
- } else if (
- listenLayer.modifyPoint &&
- (listenLayer.modifyPoint.linkedPointIdX ||
- listenLayer.modifyPoint.linkedPointIdY)
- ) {
- mathUtil.clonePoint(point, listenLayer.modifyPoint);
- } else if (
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.hasOwnProperty("linkedWallId")
- ) {
- point = wallService.createPoint(
- listenLayer.modifyPoint.x,
- listenLayer.modifyPoint.y
- );
- wallService.splitWall(
- listenLayer.modifyPoint.linkedWallId,
- point.vectorId,
- "start"
- );
- wallService.moveTo(draggingItem.vectorId, point.vectorId);
- } else if (moveWall.splitWallId != null) {
- wallService.splitWall(
- moveWall.splitWallId,
- draggingItem.vectorId,
- "start"
- );
- }
- //draggingItem.vectorId所在的墙面与其他墙角相交
- moveWall.updateForAbsorbWallPoints();
- history.save();
- }
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- elementService.hideAll();
- break;
- case LayerEvents.AddingWall:
- needAutoRedraw = true;
- if (addWall.startInfo && addWall.startInfo.linkedPointId) {
- let addWallStartPoint = floorplanService.getPoint(
- addWall.startInfo.linkedPointId
- );
- if (
- addWall.endInfo.position &&
- Object.keys(addWallStartPoint.parent).length > 1
- ) {
- stateService.clearEventName();
- addWall.clear();
- elementService.hideAll();
- this.uiControl.clearUI();
- history.save();
- }
- }
- break;
- case LayerEvents.MoveWall:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.AddingRectangle:
- needAutoRedraw = true;
- if (
- mathUtil.getDistance(addRectangle.start, addRectangle.end) <
- Constant.minAdsorb
- ) {
- floorplanService.deleteRectangle(addRectangle.currentVectorId);
- }
- stateService.clearEventName();
- elementService.hideAll();
- addRectangle.clear();
- history.save();
- this.uiControl.clearUI();
- break;
- case LayerEvents.MoveRectangle:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.MoveRectangleVertex:
- needAutoRedraw = true;
- elementService.hideAll();
- history.save();
- break;
- case LayerEvents.MoveRectangleSide:
- needAutoRedraw = true;
- history.save();
- break;
- case LayerEvents.AddingCircle:
- if (addCircle.end != null && addCircle.currentVectorId != null) {
- if (
- mathUtil.getDistance(addCircle.start, addCircle.end) <
- Constant.minAdsorb
- ) {
- floorplanService.deleteCircle(addCircle.currentVectorId);
- }
- needAutoRedraw = true;
- }
- stateService.clearEventName();
- elementService.hideAll();
- addCircle.clear();
- history.save();
- this.uiControl.clearUI();
- break;
- case LayerEvents.MoveCircle:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.MoveCircleVertex:
- needAutoRedraw = true;
- history.save();
- break;
- case LayerEvents.AddingIcon:
- if (addIcon.end != null && addIcon.currentVectorId != null) {
- if (
- mathUtil.getDistance(addIcon.start, addIcon.end) <
- Constant.minAdsorb
- ) {
- iconService.deleteIcon(addIcon.currentVectorId);
- }
- needAutoRedraw = true;
- }
- stateService.clearEventName();
- elementService.hideAll();
- addIcon.clear();
- history.save();
- this.uiControl.clearUI();
- break;
- case LayerEvents.MoveIcon:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.MoveIconVertex:
- needAutoRedraw = true;
- history.save();
- break;
- case LayerEvents.AddingArrow:
- if (addArrow.start != null && addArrow.currentVectorId != null) {
- if (
- mathUtil.getDistance(addArrow.start, addArrow.end) <
- Constant.minAdsorb
- ) {
- floorplanService.deleteArrow(addArrow.currentVectorId);
- }
- needAutoRedraw = true;
- }
- stateService.clearEventName();
- elementService.hideAll();
- addArrow.clear();
- history.save();
- this.uiControl.clearUI();
- break;
- case LayerEvents.MoveArrow:
- needAutoRedraw = true;
- history.save();
- break;
- case LayerEvents.MoveTag:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.AddTag:
- needAutoRedraw = true;
- this.uiControl.showAttributes(focusItem);
- history.save();
- break;
- case LayerEvents.MoveTable:
- if (focusItem == null) {
- needAutoRedraw = true;
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.AddTable:
- needAutoRedraw = true;
- this.uiControl.showAttributes(focusItem);
- history.save();
- break;
- case LayerEvents.AddSign:
- needAutoRedraw = true;
- this.uiControl.clearUI();
- this.uiControl.showAttributes(focusItem);
- history.save();
- break;
- case LayerEvents.MoveSign:
- if (focusItem != null && signService.isSign(focusItem.type)) {
- //history.save();
- this.uiControl.showAttributes(focusItem);
- } else {
- needAutoRedraw = true;
- history.save();
- }
- break;
- case LayerEvents.MoveCustomImage:
- if (focusItem == null) {
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- case LayerEvents.MoveBgImage:
- if (focusItem == null) {
- history.save();
- } else {
- this.uiControl.showAttributes(focusItem);
- }
- break;
- }
- this.lastX = null;
- this.lastY = null;
- 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) * 2 : (-(e.detail || 0) / 3) * 2
- // const zoom = coordinate.zoom + delta
- // if (zoom < 14) {
- // return
- // }
- // coordinate.updateZoom(zoom)
- // this.renderer.autoRedraw()
- // }
- }
- onKeydown(e) {
- if (!this.display) {
- return;
- }
- if (e.ctrlKey && e.code == "KeyZ") {
- this.revokeHistory();
- console.log("ctrl+z");
- } else if (e.ctrlKey && e.code == "KeyY") {
- this.recoveryHistory();
- console.log("ctrl+y");
- } else if (e.code == "Delete") {
- this.uiControl.deleteItem();
- this.uiControl.clearUI();
- history.save();
- this.renderer.autoRedraw();
- console.log("Delete");
- } else if (e.code == "Escape") {
- this.stopAddVector();
- this.renderer.autoRedraw();
- console.log("Esc");
- }
- }
- 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.Wall) {
- stateService.setEventName(LayerEvents.MoveWall);
- } else if (selectItem.type == VectorType.WallCorner) {
- stateService.setEventName(LayerEvents.MoveWallPoint);
- } else if (selectItem.type == VectorType.Tag) {
- stateService.setEventName(LayerEvents.MoveTag);
- } else if (signService.isSign(selectItem.type)) {
- stateService.setEventName(LayerEvents.MoveSign);
- } else if (selectItem.type == VectorType.Rectangle) {
- if (selectItem.selectIndex == SelectState.All) {
- stateService.setEventName(LayerEvents.MoveRectangle);
- } else if (selectItem.selectIndex.indexOf(SelectState.Vertex) > -1) {
- stateService.setEventName(LayerEvents.MoveRectangleVertex);
- } else if (selectItem.selectIndex.indexOf(SelectState.Side) > -1) {
- stateService.setEventName(LayerEvents.MoveRectangleSide);
- }
- } else if (selectItem.type == VectorType.Circle) {
- if (selectItem.selectIndex == SelectState.All) {
- stateService.setEventName(LayerEvents.MoveCircle);
- } else if (selectItem.selectIndex.indexOf(SelectState.Vertex) > -1) {
- stateService.setEventName(LayerEvents.MoveCircleVertex);
- }
- } else if (selectItem.type == VectorType.Icon) {
- if (selectItem.selectIndex == SelectState.All) {
- stateService.setEventName(LayerEvents.MoveIcon);
- } else if (selectItem.selectIndex.indexOf(SelectState.Vertex) > -1) {
- stateService.setEventName(LayerEvents.MoveIconVertex);
- }
- } else if (selectItem.type == VectorType.Arrow) {
- if (selectItem.selectIndex == SelectState.All) {
- stateService.setEventName(LayerEvents.MoveArrow);
- } else {
- stateService.setEventName(LayerEvents.moveArrowVertex);
- }
- } else if (selectItem.type == VectorType.Table) {
- stateService.setEventName(LayerEvents.MoveTable);
- } else if (selectItem.type == VectorType.Title) {
- stateService.setEventName(LayerEvents.MoveTitle);
- } else if (selectItem.type == VectorType.Compass) {
- stateService.setEventName(LayerEvents.MoveCompass);
- } else if (selectItem.type == VectorType.CustomImage) {
- stateService.setEventName(LayerEvents.MoveCustomImage);
- } else if (selectItem.type == VectorType.BgImage) {
- stateService.setEventName(LayerEvents.MoveBgImage);
- }
- } else if (eventName == LayerEvents.AddWall) {
- stateService.setEventName(LayerEvents.AddingWall);
- }
- } else if (eventType == "mouseUp") {
- if (eventName == LayerEvents.AddTag) {
- stateService.clearEventName();
- } else if (eventName == LayerEvents.AddRectangle) {
- stateService.setEventName(LayerEvents.AddingRectangle);
- } else if (eventName == LayerEvents.AddCircle) {
- stateService.setEventName(LayerEvents.AddingCircle);
- } else if (eventName == LayerEvents.AddIcon) {
- stateService.setEventName(LayerEvents.AddingIcon);
- } else if (eventName == LayerEvents.AddArrow) {
- stateService.setEventName(LayerEvents.AddingArrow);
- } else if (eventName == LayerEvents.AddTable) {
- stateService.clearEventName();
- }
- else if (
- eventName != LayerEvents.AddWall &&
- eventName != LayerEvents.AddingWall
- ) {
- //&& eventName != LayerEvents.AddRectangle && eventName != LayerEvents.AddingRectangle && eventName != LayerEvents.AddCircle && eventName != LayerEvents.AddingCircle && eventName != LayerEvents.AddArrow && eventName != LayerEvents.AddingArrow && eventName != LayerEvents.AddIcon && eventName != LayerEvents.AddingIcon
- stateService.clearEventName();
- }
- }
- }
- exit() {
- stateService.clearItems();
- stateService.clearEventName();
- this.uiControl.clearUI();
- }
- stopAddVector() {
- let eventName = stateService.getEventName();
- if (eventName != LayerEvents.AddingWall) {
- stateService.clearEventName();
- const draggingItem = stateService.getDraggingItem();
- if (eventName == LayerEvents.AddTag) {
- if (draggingItem && draggingItem.vectorId) {
- tagService.deleteTag(draggingItem.vectorId);
- this.uiControl.clearUI();
- stateService.clearItems();
- }
- } else if (eventName == LayerEvents.AddTable) {
- if (draggingItem && draggingItem.vectorId) {
- tableService.deleteTable(draggingItem.vectorId);
- this.uiControl.clearUI();
- stateService.clearItems();
- }
- } else if (eventName == LayerEvents.AddSign) {
- if (draggingItem && draggingItem.vectorId) {
- floorplanService.deleteSign(draggingItem.vectorId);
- stateService.clearItems();
- }
- }
- } else {
- stateService.setEventName(LayerEvents.AddWall);
- }
- this.uiControl.clearUI();
- elementService.hideAll();
- }
- }
|