Layer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. import Load from "./Load";
  2. import { stateService } from "./Service/StateService";
  3. import { elementService } from "./Service/ElementService";
  4. import { dataService } from "./Service/DataService";
  5. import { measureService } from "./Service/MeasureService";
  6. import { tagService } from "./Service/TagService";
  7. import { historyService } from "./Service/HistoryService";
  8. import UIControl from "./Controls/UIControl";
  9. // import { moveRectangle } from "./Controls/MoveRectangle";
  10. import { moveTag } from "./Controls/MoveTag";
  11. import { addRoad } from "./Controls/AddRoad";
  12. import { moveRoad } from "./Controls/MoveRoad";
  13. import { coordinate } from "./Coordinate";
  14. import Render from "./Renderer/Render";
  15. import { draw } from "./Renderer/Draw";
  16. import { listenLayer } from "./ListenLayer";
  17. import LayerEvents from "./enum/LayerEvents.js";
  18. import UIEvents from "./enum/UIEvents.js";
  19. import SelectState from "./enum/SelectState.js";
  20. import VectorType from "./enum/VectorType";
  21. import { mathUtil } from "./Util/MathUtil";
  22. import History from "./History/History";
  23. import mitt from "mitt";
  24. import { roadService } from "./Service/RoadService";
  25. import { edgeService } from "./Service/EdgeService";
  26. import { pointService } from "./Service/PointService";
  27. import { curveRoadService } from "./Service/CurveRoadService";
  28. const minDragDis = 10;
  29. export default class Layer {
  30. constructor(canvas) {
  31. this.canvas = canvas;
  32. this.load = new Load(this);
  33. this.uiControl = new UIControl(this);
  34. this.renderer = new Render(this);
  35. this.history = new History(this);
  36. this.dragging = false; // 当前是否正在拖拽
  37. this.start();
  38. Object.setPrototypeOf(Object.getPrototypeOf(this), mitt());
  39. }
  40. start() {
  41. if (this.canvas) {
  42. this.canvas.width = this.canvas.clientWidth;
  43. this.canvas.height = this.canvas.clientHeight;
  44. coordinate.init(this.canvas);
  45. draw.initContext(this.canvas);
  46. dataService.initVectorData();
  47. this.history.init();
  48. this.bindEvents();
  49. }
  50. window.vectorData = dataService.vectorData;
  51. }
  52. bindEvents() {
  53. this.canvas.addEventListener("contextmenu", function (e) {
  54. e.preventDefault();
  55. });
  56. this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
  57. this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this));
  58. this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
  59. this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
  60. this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
  61. this.canvas.addEventListener("resize", this.reSize.bind(this));
  62. document.addEventListener("keydown", this.onKeydown.bind(this));
  63. }
  64. reSize = function () {
  65. console.log("resize");
  66. coordinate.updateForCanvas();
  67. this.renderer.autoRedraw();
  68. };
  69. onMouseDown(e) {
  70. this.startX = e.offsetX || e.layerX;
  71. this.startY = e.offsetY || e.layerY;
  72. this.lastX = e.offsetX || e.layerX;
  73. this.lastY = e.offsetY || e.layerY;
  74. // 右键
  75. if (e.button == 2) {
  76. this.stopAddVector();
  77. this.uiControl.currentUI = null;
  78. this.renderer.autoRedraw();
  79. return;
  80. }
  81. this.dragging = false;
  82. this.setEventName("mouseDown");
  83. const selectItem = stateService.getSelectItem();
  84. const eventName = stateService.getEventName();
  85. stateService.setDraggingItem(selectItem);
  86. // 清除上一个状态
  87. // 设置当前事件名称
  88. e.preventDefault();
  89. e.stopPropagation();
  90. }
  91. onMouseMove(e) {
  92. const X = e.offsetX || e.layerX;
  93. const Y = e.offsetY || e.layerY;
  94. let dx = X - this.lastX;
  95. let dy = Y - this.lastY;
  96. let position = coordinate.getXYFromScreen({
  97. x: X,
  98. y: Y,
  99. });
  100. if (
  101. Math.abs(X - this.startX) > minDragDis ||
  102. Math.abs(Y - this.startY) > minDragDis
  103. ) {
  104. // 是否拖拽了
  105. this.dragging = true;
  106. }
  107. const eventName = stateService.getEventName();
  108. // 是否需要重绘
  109. let needAutoRedraw = false;
  110. let point = null;
  111. const draggingItem = stateService.getDraggingItem();
  112. switch (eventName) {
  113. case null:
  114. //监控
  115. needAutoRedraw = listenLayer.start(position);
  116. break;
  117. case LayerEvents.PanBackGround:
  118. stateService.clearItems();
  119. coordinate.center.x =
  120. coordinate.center.x - (dx * coordinate.defaultZoom) / coordinate.zoom;
  121. coordinate.center.y =
  122. coordinate.center.y + (dy * coordinate.defaultZoom) / coordinate.zoom;
  123. this.lastX = X;
  124. this.lastY = Y;
  125. needAutoRedraw = true;
  126. break;
  127. case LayerEvents.AddRoad:
  128. needAutoRedraw = true;
  129. listenLayer.start(position);
  130. if (listenLayer.modifyPoint) {
  131. position = {
  132. x: listenLayer.modifyPoint.x,
  133. y: listenLayer.modifyPoint.y,
  134. };
  135. }
  136. elementService.hideAll();
  137. elementService.setPoint(position);
  138. elementService.showPoint();
  139. if (listenLayer.modifyPoint) {
  140. elementService.execute(listenLayer.modifyPoint, position);
  141. }
  142. break;
  143. case LayerEvents.AddingRoad:
  144. needAutoRedraw = true;
  145. listenLayer.start(position);
  146. if (listenLayer.modifyPoint) {
  147. position = {
  148. x: listenLayer.modifyPoint.x,
  149. y: listenLayer.modifyPoint.y,
  150. };
  151. }
  152. elementService.execute(addRoad.startInfo.position, position);
  153. elementService.setPoint(position);
  154. elementService.setNewRoad(addRoad.startInfo.position, position);
  155. elementService.showNewRoad();
  156. elementService.setNewRoadGeoType(VectorType.Road);
  157. addRoad.setNewRoadPoint("end", position);
  158. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  159. if (!addRoad.canAdd) {
  160. elementService.setNewRoadState("error");
  161. } else {
  162. elementService.setNewRoadState("normal");
  163. }
  164. break;
  165. case LayerEvents.MoveRoad:
  166. needAutoRedraw = true;
  167. //只允许拖拽一条公路
  168. let road = dataService.getRoad(draggingItem.vectorId);
  169. let start = dataService.getPoint(road.startId);
  170. let end = dataService.getPoint(road.endId);
  171. if (
  172. Object.keys(start.getParent()).length == 1 &&
  173. Object.keys(end.getParent()).length == 1
  174. ) {
  175. //拖拽的路只有一条
  176. moveRoad.moveRoad(
  177. draggingItem.vectorId,
  178. (dx * coordinate.defaultZoom) / coordinate.zoom,
  179. (dy * coordinate.defaultZoom) / coordinate.zoom
  180. );
  181. }
  182. this.lastX = X;
  183. this.lastY = Y;
  184. break;
  185. case LayerEvents.MoveRoadPoint:
  186. point = dataService.getPoint(draggingItem.vectorId);
  187. //listenLayer.start(position, draggingItem.vectorId, point.parent);
  188. listenLayer.start(position, draggingItem.vectorId, point.parent);
  189. if (listenLayer.modifyPoint) {
  190. position = {
  191. x: listenLayer.modifyPoint.x,
  192. y: listenLayer.modifyPoint.y,
  193. };
  194. }
  195. let flag = moveRoad.moveingRoadPoint(
  196. draggingItem.vectorId,
  197. position,
  198. listenLayer.modifyPoint
  199. );
  200. if (!flag) {
  201. elementService.hideAll();
  202. } else {
  203. point = dataService.getPoint(draggingItem.vectorId);
  204. listenLayer.start(point, draggingItem.vectorId, point.parent);
  205. let otherPoint = null;
  206. if (
  207. listenLayer.modifyPoint &&
  208. listenLayer.modifyPoint.linkedPointId
  209. ) {
  210. otherPoint = dataService.getPoint(
  211. listenLayer.modifyPoint.linkedPointId
  212. );
  213. } else if (
  214. listenLayer.modifyPoint &&
  215. listenLayer.modifyPoint.linkedPointIdX
  216. ) {
  217. otherPoint = dataService.getPoint(
  218. listenLayer.modifyPoint.linkedPointIdX
  219. );
  220. } else if (
  221. listenLayer.modifyPoint &&
  222. listenLayer.modifyPoint.linkedPointIdY
  223. ) {
  224. otherPoint = dataService.getPoint(
  225. listenLayer.modifyPoint.linkedPointIdY
  226. );
  227. }
  228. elementService.execute(otherPoint, point);
  229. }
  230. needAutoRedraw = true;
  231. break;
  232. case LayerEvents.AddCurveRoad:
  233. needAutoRedraw = true;
  234. listenLayer.start(position);
  235. if (listenLayer.modifyPoint) {
  236. position = {
  237. x: listenLayer.modifyPoint.x,
  238. y: listenLayer.modifyPoint.y,
  239. };
  240. }
  241. elementService.hideAll();
  242. elementService.setPoint(position);
  243. elementService.showPoint();
  244. if (listenLayer.modifyPoint) {
  245. elementService.execute(listenLayer.modifyPoint, position);
  246. }
  247. break;
  248. case LayerEvents.AddingCurveRoad:
  249. needAutoRedraw = true;
  250. listenLayer.start(position);
  251. if (listenLayer.modifyPoint) {
  252. position = {
  253. x: listenLayer.modifyPoint.x,
  254. y: listenLayer.modifyPoint.y,
  255. };
  256. }
  257. elementService.execute(addRoad.startInfo.position, position);
  258. elementService.setPoint(position);
  259. elementService.setNewRoad(addRoad.startInfo.position, position);
  260. elementService.showNewRoad();
  261. elementService.setNewRoadGeoType(VectorType.Road);
  262. addRoad.setNewRoadPoint("end", position);
  263. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  264. if (!addRoad.canAdd) {
  265. elementService.setNewRoadState("error");
  266. } else {
  267. elementService.setNewRoadState("normal");
  268. }
  269. break;
  270. case LayerEvents.AddMeasureLine:
  271. needAutoRedraw = true;
  272. listenLayer.start(position);
  273. if (listenLayer.modifyPoint) {
  274. position = {
  275. x: listenLayer.modifyPoint.x,
  276. y: listenLayer.modifyPoint.y,
  277. };
  278. }
  279. elementService.setPoint(position);
  280. elementService.showPoint();
  281. addRoad.setNewRoadPoint("start", position);
  282. break;
  283. case LayerEvents.MoveCurveRoadPoint:
  284. point = dataService.getCurvePoint(draggingItem.vectorId);
  285. listenLayer.start(position, draggingItem.vectorId, null, point.parent);
  286. if (listenLayer.modifyPoint) {
  287. position = {
  288. x: listenLayer.modifyPoint.x,
  289. y: listenLayer.modifyPoint.y,
  290. };
  291. }
  292. if (draggingItem) {
  293. moveRoad.moveCurveRoadPoint(draggingItem.vectorId, position);
  294. needAutoRedraw = true;
  295. }
  296. break;
  297. case LayerEvents.AddTag:
  298. needAutoRedraw = true;
  299. if (draggingItem == null) {
  300. const tag = tagService.createTag(position);
  301. if (tag.vectorId) {
  302. stateService.setSelectItem(
  303. tag.vectorId,
  304. VectorType.Tag,
  305. SelectState.All
  306. );
  307. stateService.setDraggingItem(stateService.selectItem);
  308. }
  309. } else {
  310. moveTag.moveFullTag(position, draggingItem.vectorId);
  311. }
  312. break;
  313. case LayerEvents.MoveTag:
  314. needAutoRedraw = true;
  315. if (draggingItem != null) {
  316. moveTag.moveFullTag(position, draggingItem.vectorId);
  317. }
  318. break;
  319. }
  320. if (needAutoRedraw) {
  321. this.renderer.autoRedraw();
  322. }
  323. }
  324. onMouseUp(e) {
  325. // 右键
  326. if (e.button == 2) {
  327. return;
  328. }
  329. const X = e.offsetX || e.layerX;
  330. const Y = e.offsetY || e.layerY;
  331. let eventName = stateService.getEventName();
  332. const draggingItem = stateService.getDraggingItem();
  333. const selectItem = stateService.getSelectItem();
  334. let focusItem = null;
  335. if (!this.dragging && selectItem) {
  336. focusItem = {
  337. vectorId: selectItem.vectorId,
  338. type: selectItem.type,
  339. cursor: { x: this.lastX, y: this.lastY },
  340. };
  341. stateService.setFocusItem(focusItem);
  342. stateService.clearDraggingItem();
  343. }
  344. let position = coordinate.getXYFromScreen({
  345. x: X,
  346. y: Y,
  347. });
  348. let needAutoRedraw = false;
  349. switch (eventName) {
  350. case null:
  351. return;
  352. case LayerEvents.PanBackGround:
  353. needAutoRedraw = true;
  354. stateService.clearFocusItem();
  355. this.uiControl.currentUI = null;
  356. break;
  357. case LayerEvents.MoveRoadPoint:
  358. needAutoRedraw = true;
  359. elementService.hideAll();
  360. let point = dataService.getPoint(draggingItem.vectorId);
  361. if (point) {
  362. listenLayer.start(point, draggingItem.vectorId, point.parent);
  363. if (
  364. listenLayer.modifyPoint &&
  365. listenLayer.modifyPoint.hasOwnProperty("linkedPointId")
  366. ) {
  367. moveRoad.moveTo(
  368. draggingItem.vectorId,
  369. listenLayer.modifyPoint.linkedPointId
  370. );
  371. } else if (
  372. listenLayer.modifyPoint &&
  373. (listenLayer.modifyPoint.linkedPointIdX ||
  374. listenLayer.modifyPoint.linkedPointIdY)
  375. ) {
  376. mathUtil.clonePoint(point, listenLayer.modifyPoint);
  377. } else if (
  378. listenLayer.modifyPoint &&
  379. listenLayer.modifyPoint.hasOwnProperty("linkedRoadId")
  380. ) {
  381. point = pointService.create({
  382. x: listenLayer.modifyPoint.x,
  383. y: listenLayer.modifyPoint.y,
  384. });
  385. roadService.splitRoad(
  386. listenLayer.modifyPoint.linkedRoadId,
  387. point.vectorId,
  388. "start"
  389. );
  390. moveRoad.moveTo(draggingItem.vectorId, point.vectorId);
  391. } else if (moveRoad.splitRoadId != null) {
  392. roadService.splitRoad(
  393. moveRoad.splitRoadId,
  394. draggingItem.vectorId,
  395. "start"
  396. );
  397. }
  398. //draggingItem.vectorId所在的墙面与其他墙角相交
  399. moveRoad.updateForAbsorbRoadPoints();
  400. let parent = point.getParent();
  401. for (let key in parent) {
  402. roadService.setLanes(key);
  403. }
  404. this.history.save();
  405. }
  406. break;
  407. case LayerEvents.AddRoad:
  408. addRoad.setNewRoadPoint("start", position);
  409. break;
  410. case LayerEvents.AddingRoad:
  411. needAutoRedraw = true;
  412. if (addRoad.canAdd) {
  413. addRoad.buildRoad();
  414. addRoad.clear();
  415. this.history.save();
  416. elementService.hideAll();
  417. }
  418. break;
  419. case LayerEvents.AddCurveRoad:
  420. addRoad.setNewRoadPoint("start", position);
  421. break;
  422. case LayerEvents.AddingCurveRoad:
  423. needAutoRedraw = true;
  424. if (addRoad.canAdd) {
  425. addRoad.buildCurveRoad();
  426. addRoad.clear();
  427. this.history.save();
  428. elementService.hideAll();
  429. }
  430. break;
  431. case LayerEvents.MoveRoad:
  432. needAutoRedraw = true;
  433. if (focusItem != null && focusItem.type == VectorType.Road) {
  434. const road = dataService.getRoad(focusItem.vectorId);
  435. this.uiControl.currentUI = focusItem.type;
  436. }
  437. this.history.save();
  438. moveRoad.setStartMoving(false);
  439. break;
  440. case LayerEvents.MoveTag:
  441. needAutoRedraw = true;
  442. if (focusItem != null && focusItem.type == VectorType.Tag) {
  443. this.uiControl.currentUI = focusItem.type;
  444. }
  445. this.history.save();
  446. break;
  447. case LayerEvents.AddTag:
  448. needAutoRedraw = true;
  449. let tag = dataService.getTag(draggingItem.vectorId);
  450. tag.setAdding(false);
  451. focusItem = {
  452. vectorId: draggingItem.vectorId,
  453. type: draggingItem.type,
  454. cursor: { x: this.lastX, y: this.lastY },
  455. };
  456. stateService.setFocusItem(focusItem);
  457. this.history.save();
  458. this.uiControl.currentUI = focusItem.type;
  459. break;
  460. }
  461. this.setEventName("mouseUp");
  462. stateService.clearDraggingItem();
  463. this.renderer.autoRedraw();
  464. }
  465. onWheel(e) {
  466. e.preventDefault();
  467. const type = e.type;
  468. if (type == "DOMMouseScroll" || type == "mousewheel") {
  469. // 当在canvas用滚轮滚动时
  470. const delta = e.wheelDelta
  471. ? (e.wheelDelta / 120) * 20
  472. : (-(e.detail || 0) / 3) * 20;
  473. const zoom = coordinate.zoom + delta;
  474. if (zoom < 14) {
  475. return;
  476. }
  477. coordinate.updateZoom(zoom);
  478. this.renderer.autoRedraw();
  479. }
  480. }
  481. //测试用
  482. onKeydown(e) {
  483. let focusItem = stateService.getFocusItem();
  484. if (focusItem) {
  485. console.log("键盘(foucus有效):" + e.code);
  486. if (e.code == "Delete") {
  487. //删除
  488. const road = dataService.getRoad(focusItem.vectorId);
  489. roadService.subtraRoadFromIntersect(road.startId, focusItem.vectorId);
  490. roadService.subtraRoadFromIntersect(road.endId, focusItem.vectorId);
  491. //dataService.deleteControlPoint()
  492. dataService.deleteRoad(focusItem.vectorId);
  493. this.renderer.autoRedraw();
  494. this.history.save();
  495. }
  496. //加宽
  497. else if (e.code == "KeyA") {
  498. const road = dataService.getRoad(focusItem.vectorId);
  499. road.width += 100;
  500. edgeService.updateEdgeForMovePoint(road.startId);
  501. edgeService.updateEdgeForMovePoint(road.endId);
  502. roadService.setLanes(road.vectorId);
  503. this.renderer.autoRedraw();
  504. this.history.save();
  505. }
  506. //变窄
  507. else if (e.code == "KeyB") {
  508. const road = dataService.getRoad(focusItem.vectorId);
  509. road.width -= 50;
  510. edgeService.updateEdgeForMovePoint(road.startId);
  511. edgeService.updateEdgeForMovePoint(road.endId);
  512. roadService.setLanes(road.vectorId);
  513. this.renderer.autoRedraw();
  514. this.history.save();
  515. }
  516. //添加左车道
  517. else if (e.code == "KeyQ") {
  518. let road = dataService.getRoad(focusItem.vectorId);
  519. if (road) {
  520. roadService.updateForAddSubtractLanesCount(
  521. focusItem.vectorId,
  522. road.leftDrivewayCount + 1,
  523. "left"
  524. );
  525. } else {
  526. road = dataService.getCurveRoad(focusItem.vectorId);
  527. curveRoadService.updateForAddSubtractLanesCount(
  528. road,
  529. road.leftDrivewayCount + 1, //rightDrivewayCount
  530. "left"
  531. );
  532. }
  533. this.renderer.autoRedraw();
  534. this.history.save();
  535. }
  536. //减少左车道
  537. else if (e.code == "KeyW") {
  538. let road = dataService.getRoad(focusItem.vectorId);
  539. if (road) {
  540. roadService.updateForAddSubtractLanesCount(
  541. focusItem.vectorId,
  542. road.leftDrivewayCount - 1,
  543. "left"
  544. );
  545. } else {
  546. road = dataService.getCurveRoad(focusItem.vectorId);
  547. curveRoadService.updateForAddSubtractLanesCount(
  548. road,
  549. road.leftDrivewayCount - 1, //rightDrivewayCount
  550. "left"
  551. );
  552. }
  553. this.renderer.autoRedraw();
  554. this.history.save();
  555. }
  556. //添加右车道
  557. else if (e.code == "KeyE") {
  558. let road = dataService.getRoad(focusItem.vectorId);
  559. if (road) {
  560. roadService.updateForAddSubtractLanesCount(
  561. focusItem.vectorId,
  562. road.rightDrivewayCount + 1,
  563. "right"
  564. );
  565. } else {
  566. road = dataService.getCurveRoad(focusItem.vectorId);
  567. curveRoadService.updateForAddSubtractLanesCount(
  568. road,
  569. road.rightDrivewayCount + 1, //rightDrivewayCount
  570. "right"
  571. );
  572. }
  573. this.renderer.autoRedraw();
  574. this.history.save();
  575. }
  576. //减少右车道
  577. else if (e.code == "KeyR") {
  578. let road = dataService.getRoad(focusItem.vectorId);
  579. if (road) {
  580. roadService.updateForAddSubtractLanesCount(
  581. focusItem.vectorId,
  582. road.rightDrivewayCount - 1,
  583. "right"
  584. );
  585. } else {
  586. road = dataService.getCurveRoad(focusItem.vectorId);
  587. curveRoadService.updateForAddSubtractLanesCount(
  588. road,
  589. road.rightDrivewayCount - 1, //rightDrivewayCount
  590. "right"
  591. );
  592. }
  593. this.renderer.autoRedraw();
  594. this.history.save();
  595. }
  596. } else {
  597. console.log("键盘(foucus无效):" + e.code);
  598. }
  599. }
  600. setEventName(eventType) {
  601. let eventName = stateService.getEventName();
  602. if (eventType == "mouseDown") {
  603. if (eventName == null) {
  604. const selectItem = stateService.getSelectItem();
  605. if (selectItem == null) {
  606. stateService.setEventName(LayerEvents.PanBackGround);
  607. } else if (selectItem.type == VectorType.Road) {
  608. stateService.setEventName(LayerEvents.MoveRoad);
  609. } else if (selectItem.type == VectorType.Point) {
  610. stateService.setEventName(LayerEvents.MoveRoadPoint);
  611. } else if (selectItem.type == VectorType.CurveRoad) {
  612. stateService.setEventName(LayerEvents.MoveCurveRoad);
  613. } else if (selectItem.type == VectorType.CurvePoint) {
  614. stateService.setEventName(LayerEvents.MoveCurveRoadPoint);
  615. } else if (selectItem.type == VectorType.Tag) {
  616. stateService.setEventName(LayerEvents.MoveTag);
  617. } else if (selectItem.type == VectorType.MeasureLine) {
  618. stateService.setEventName(LayerEvents.MoveMeasureLine);
  619. } else if (selectItem.type == VectorType.MeasureArrow) {
  620. stateService.setEventName(LayerEvents.MoveMeasureArrow);
  621. }
  622. }
  623. } else if (eventType == "mouseUp") {
  624. if (eventName == LayerEvents.AddTag) {
  625. //可连续添加
  626. //stateService.clearEventName()
  627. } else if (eventName == LayerEvents.AddRoad) {
  628. stateService.setEventName(LayerEvents.AddingRoad);
  629. } else if (eventName == LayerEvents.AddingRoad) {
  630. stateService.setEventName(LayerEvents.AddRoad);
  631. } else if (eventName == LayerEvents.AddCurveRoad) {
  632. stateService.setEventName(LayerEvents.AddingCurveRoad);
  633. } else if (eventName == LayerEvents.AddingCurveRoad) {
  634. stateService.setEventName(LayerEvents.AddCurveRoad);
  635. } else if (eventName == LayerEvents.AddMeasureLine) {
  636. stateService.setEventName(LayerEvents.AddingMeasureLine);
  637. } else if (eventName == LayerEvents.AddingMeasureLine) {
  638. stateService.setEventName(LayerEvents.AddMeasureLine);
  639. } else {
  640. stateService.clearEventName();
  641. }
  642. }
  643. }
  644. exit() {
  645. stateService.clear();
  646. this.uiControl.clearUI();
  647. }
  648. stopAddVector() {
  649. let eventName = stateService.getEventName();
  650. if (eventName != LayerEvents.AddingRoad) {
  651. stateService.clearEventName();
  652. const draggingItem = stateService.getDraggingItem();
  653. if (eventName == LayerEvents.AddTag) {
  654. if (draggingItem && draggingItem.vectorId) {
  655. dataService.deleteTag(draggingItem.vectorId);
  656. this.uiControl.currentUI = null;
  657. }
  658. }
  659. } else {
  660. stateService.setEventName(LayerEvents.AddRoad);
  661. }
  662. this.uiControl.clearUI();
  663. elementService.hideAll();
  664. }
  665. update() {}
  666. revokeHistory() {
  667. this.history.goPreState();
  668. this.renderer.autoRedraw();
  669. }
  670. recoveryHistory() {
  671. this.history.goNextState();
  672. this.renderer.autoRedraw();
  673. }
  674. deleteItem() {
  675. let item = stateService.getFocusItem();
  676. if (item) {
  677. if (item.type == VectorType.Road) {
  678. dataService.deleteRoad(item.vectorId);
  679. } else if (item.type == VectorType.Tag) {
  680. dataService.deleteTag(item.vectorId);
  681. } else if (item.type == VectorType.Point) {
  682. //这个比较复杂,参考deleteRoadCorner
  683. //dataService.deletePoint(item.vectorId);
  684. }
  685. this.history.save();
  686. this.renderer.autoRedraw();
  687. }
  688. }
  689. }