Layer.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 { textService } from "./Service/TextService";
  6. import { historyService } from "./Service/HistoryService";
  7. import UIControl from "./Controls/UIControl";
  8. // import { moveRectangle } from "./Controls/MoveRectangle";
  9. import { moveText } from "./Controls/MoveText";
  10. import { moveSVG } from "./Controls/MoveSVG";
  11. import { moveMagnifier } from "./Controls/MoveMagnifier";
  12. import { addRoad } from "./Controls/AddRoad";
  13. import { addLine } from "./Controls/AddLine";
  14. import { addPoint } from "./Controls/AddPoint";
  15. import { addCircle } from "./Controls/AddCircle";
  16. import { addText } from "./Controls/AddText";
  17. import { addMagnifier } from "./Controls/AddMagnifier";
  18. import { addSVG } from "./Controls/AddSVG";
  19. import { moveRoad } from "./Controls/MoveRoad";
  20. import { moveLine } from "./Controls/MoveLine";
  21. import { movePoint } from "./Controls/MovePoint";
  22. import { moveCircle } from "./Controls/MoveCircle";
  23. import { coordinate } from "./Coordinate";
  24. import Render from "./Renderer/Render";
  25. import { draw } from "./Renderer/Draw";
  26. import { listenLayer } from "./ListenLayer";
  27. import LayerEvents from "./enum/LayerEvents.js";
  28. import UIEvents from "./enum/UIEvents.js";
  29. import SelectState from "./enum/SelectState.js";
  30. import VectorType from "./enum/VectorType";
  31. import { mathUtil } from "./Util/MathUtil";
  32. import History from "./History/History";
  33. import mitt from "mitt";
  34. import { roadService } from "./Service/RoadService";
  35. import { edgeService } from "./Service/EdgeService";
  36. import { roadPointService } from "./Service/RoadPointService";
  37. import { curveRoadService } from "./Service/CurveRoadService";
  38. import VectorCategory from "./enum/VectorCategory";
  39. import Settings from "./Settings";
  40. import { uiService } from "./Service/UIService";
  41. import { imageService } from "./Service/ImageService";
  42. const minDragDis = 10;
  43. const minZoom = 20;
  44. const maxZoom = 800;
  45. export default class Layer {
  46. constructor(canvas, newsletter, graphicState) {
  47. this.canvas = canvas;
  48. this.load = new Load(this);
  49. this.uiControl = new UIControl(this, newsletter, graphicState);
  50. this.renderer = new Render(this);
  51. this.history = new History(this);
  52. this.mousePosition = null;
  53. this.dragging = false; // 当前是否正在拖拽
  54. this.start();
  55. Object.setPrototypeOf(Object.getPrototypeOf(this), mitt());
  56. }
  57. start() {
  58. if (this.canvas) {
  59. this.canvas.width = this.canvas.clientWidth;
  60. this.canvas.height = this.canvas.clientHeight;
  61. coordinate.init(this.canvas);
  62. draw.initContext(this.canvas);
  63. dataService.initVectorData();
  64. this.bindEvents();
  65. }
  66. window.vectorData = dataService.vectorData;
  67. }
  68. bindEvents() {
  69. this.canvas.addEventListener("contextmenu", function (e) {
  70. e.preventDefault();
  71. });
  72. this.canvas.addEventListener("mousedown", this.onMouseDown.bind(this));
  73. this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this));
  74. this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
  75. this.canvas.addEventListener("touchstart", this.onMouseDown.bind(this));
  76. this.canvas.addEventListener("touchmove", this.onMouseMove.bind(this));
  77. this.canvas.addEventListener("touchend", this.onMouseUp.bind(this));
  78. this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
  79. this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
  80. this.canvas.addEventListener("resize", this.reSize.bind(this));
  81. document.addEventListener("keydown", this.onKeydown.bind(this));
  82. }
  83. reSize = function () {
  84. console.log("resize");
  85. coordinate.updateForCanvas();
  86. this.renderer.autoRedraw();
  87. };
  88. onMouseDown(e) {
  89. if (e instanceof TouchEvent) {
  90. this.startX = e.touches[0].pageX;
  91. this.startY = e.touches[0].pageY;
  92. this.lastX = e.touches[0].pageX;
  93. this.lastY = e.touches[0].pageY;
  94. } else {
  95. this.startX = e.offsetX || e.layerX;
  96. this.startY = e.offsetY || e.layerY;
  97. this.lastX = e.offsetX || e.layerX;
  98. this.lastY = e.offsetY || e.layerY;
  99. }
  100. let position = coordinate.getXYFromScreen({
  101. x: this.startX,
  102. y: this.startY,
  103. });
  104. // 右键
  105. if (e.button == 2) {
  106. this.stopAddVector();
  107. return;
  108. }
  109. this.dragging = false;
  110. //用于支持平板电脑
  111. listenLayer.start(position);
  112. this.setEventName("mouseDown");
  113. const eventName = stateService.getEventName();
  114. switch (eventName) {
  115. case LayerEvents.AddRoad:
  116. stateService.setEventName(LayerEvents.AddingRoad);
  117. addRoad.setNewRoadPoint("start", position);
  118. break;
  119. case LayerEvents.AddCurveRoad:
  120. stateService.setEventName(LayerEvents.AddingCurveRoad);
  121. addRoad.setNewRoadPoint("start", position);
  122. break;
  123. case LayerEvents.AddLine:
  124. stateService.setEventName(LayerEvents.AddingLine);
  125. addLine.setNewLinePoint(position);
  126. break;
  127. case LayerEvents.AddCurveLine:
  128. stateService.setEventName(LayerEvents.AddingCurveLine);
  129. addLine.setNewLinePoint(position);
  130. break;
  131. case LayerEvents.AddPoint:
  132. stateService.setEventName(LayerEvents.MovePoint);
  133. const newPoint = addPoint.buildPoint(position);
  134. if (newPoint) {
  135. stateService.setSelectItem(
  136. newPoint.vectorId,
  137. VectorType.Point,
  138. SelectState.Select
  139. );
  140. } else {
  141. this.uiControl.prompt({ msg: "请先添加基准点", time: 1000 });
  142. }
  143. break;
  144. case LayerEvents.AddCircle:
  145. stateService.setEventName(LayerEvents.AddingCircle);
  146. addCircle.setCenter(position);
  147. break;
  148. case LayerEvents.AddText:
  149. stateService.setEventName(LayerEvents.MoveText);
  150. addText.buildText(position);
  151. stateService.setSelectItem(
  152. addText.newText.vectorId,
  153. VectorType.Text,
  154. SelectState.Select
  155. );
  156. addText.clear();
  157. break;
  158. case LayerEvents.AddSVG:
  159. stateService.setEventName(LayerEvents.MoveSVG);
  160. addSVG.buildSVG(position);
  161. stateService.setSelectItem(addSVG.newSVG.vectorId, VectorType.SVG, -1);
  162. addSVG.clear();
  163. break;
  164. case LayerEvents.AddMagnifier:
  165. stateService.setEventName(LayerEvents.MoveMagnifier);
  166. addMagnifier.buildMagnifier(position);
  167. stateService.setSelectItem(
  168. addMagnifier.newMagnifier.vectorId,
  169. VectorType.Magnifier,
  170. SelectState.Select
  171. );
  172. addMagnifier.clear();
  173. break;
  174. }
  175. const selectItem = stateService.getSelectItem();
  176. stateService.setDraggingItem(selectItem);
  177. // 清除上一个状态
  178. // 设置当前事件名称
  179. e.preventDefault();
  180. e.stopPropagation();
  181. }
  182. onMouseMove(e) {
  183. let X = e.offsetX || e.layerX;
  184. let Y = e.offsetY || e.layerY;
  185. if (e instanceof TouchEvent) {
  186. X = e.touches[0].pageX;
  187. Y = e.touches[0].pageY;
  188. //切换到缩放
  189. if (e.touches.length > 1) {
  190. //记录开始的两个触摸点的坐标
  191. if (!this.StorePage1 || !this.StorePage2) {
  192. this.onMouseUp(e);
  193. this.StorePage1 = { x: e.touches[0].pageX, y: e.touches[0].pageY };
  194. this.StorePage2 = { x: e.touches[1].pageX, y: e.touches[1].pageY };
  195. this.StoreMidePage = {
  196. x: (this.StorePage1.x + this.StorePage2.x) / 2,
  197. y: (this.StorePage1.y + this.StorePage2.y) / 2,
  198. };
  199. return;
  200. }
  201. const point1 = {
  202. x: e.touches[0].pageX,
  203. y: e.touches[0].pageY,
  204. };
  205. const point2 = {
  206. x: e.touches[1].pageX,
  207. y: e.touches[1].pageY,
  208. };
  209. let dis1 = mathUtil.getDistance(point1, point2) / 100;
  210. let dis2 = mathUtil.getDistance(this.StorePage1, this.StorePage2) / 100;
  211. let zoom = (coordinate.zoom * dis1) / dis2;
  212. this.zoomVector(this.StoreMidePage, zoom);
  213. mathUtil.clonePoint(this.StorePage1, point1);
  214. mathUtil.clonePoint(this.StorePage2, point2);
  215. return;
  216. }
  217. }
  218. let dx = X - this.lastX;
  219. let dy = Y - this.lastY;
  220. dx = dx * coordinate.ratio;
  221. dy = dy * coordinate.ratio;
  222. let position = coordinate.getXYFromScreen({
  223. x: X,
  224. y: Y,
  225. });
  226. this.mousePosition = {
  227. x: position.x,
  228. y: position.y,
  229. };
  230. const eventName = stateService.getEventName();
  231. if (
  232. !this.dragging &&
  233. Math.abs(X - this.startX) < minDragDis &&
  234. Math.abs(Y - this.startY) < minDragDis
  235. ) {
  236. return;
  237. }
  238. this.dragging = true;
  239. if (
  240. Math.abs(X - this.startX) > minDragDis ||
  241. Math.abs(Y - this.startY) > minDragDis
  242. ) {
  243. // 是否拖拽了
  244. if (eventName != null) {
  245. stateService.clearFocusItem();
  246. this.uiControl.focusVector = null;
  247. }
  248. }
  249. // 是否需要重绘
  250. let needAutoRedraw = false;
  251. let point = null;
  252. this.lastX = X;
  253. this.lastY = Y;
  254. const draggingItem = stateService.getDraggingItem();
  255. switch (eventName) {
  256. case null:
  257. //监控
  258. needAutoRedraw = listenLayer.start(position);
  259. let seleteItem = stateService.getSelectItem();
  260. if (seleteItem != null) {
  261. console.log("选中:" + seleteItem.vectorId);
  262. } else {
  263. }
  264. break;
  265. case LayerEvents.PanBackGround:
  266. stateService.clearItems();
  267. let center = {};
  268. center.x =
  269. coordinate.center.x - (dx * coordinate.defaultZoom) / coordinate.zoom;
  270. center.y =
  271. coordinate.center.y + (dy * coordinate.defaultZoom) / coordinate.zoom;
  272. let tempCenter = {};
  273. mathUtil.clonePoint(tempCenter, coordinate.center);
  274. mathUtil.clonePoint(coordinate.center, center);
  275. let inScreen = imageService.backgroundImgVertexsInScreenXY();
  276. if (!inScreen) {
  277. dataService.setGridForPan();
  278. needAutoRedraw = true;
  279. } else {
  280. mathUtil.clonePoint(coordinate.center, tempCenter);
  281. }
  282. break;
  283. case LayerEvents.AddRoad:
  284. needAutoRedraw = true;
  285. listenLayer.start(position);
  286. if (listenLayer.modifyPoint) {
  287. position = {
  288. x: listenLayer.modifyPoint.x,
  289. y: listenLayer.modifyPoint.y,
  290. };
  291. }
  292. elementService.hideAll();
  293. elementService.setPoint(position);
  294. elementService.showPoint();
  295. if (listenLayer.modifyPoint) {
  296. elementService.execute(listenLayer.modifyPoint, position);
  297. }
  298. break;
  299. case LayerEvents.AddLine:
  300. needAutoRedraw = true;
  301. listenLayer.start(position);
  302. if (listenLayer.modifyPoint) {
  303. position = {
  304. x: listenLayer.modifyPoint.x,
  305. y: listenLayer.modifyPoint.y,
  306. };
  307. }
  308. elementService.hideAll();
  309. elementService.setPoint(position);
  310. elementService.showPoint();
  311. if (listenLayer.modifyPoint) {
  312. elementService.execute(listenLayer.modifyPoint, position);
  313. }
  314. break;
  315. case LayerEvents.AddCurveLine:
  316. needAutoRedraw = true;
  317. listenLayer.start(position);
  318. if (listenLayer.modifyPoint) {
  319. position = {
  320. x: listenLayer.modifyPoint.x,
  321. y: listenLayer.modifyPoint.y,
  322. };
  323. }
  324. elementService.hideAll();
  325. elementService.setPoint(position);
  326. elementService.showPoint();
  327. if (listenLayer.modifyPoint) {
  328. elementService.execute(listenLayer.modifyPoint, position);
  329. }
  330. break;
  331. case LayerEvents.AddCircle:
  332. needAutoRedraw = true;
  333. listenLayer.start(position);
  334. if (listenLayer.modifyPoint) {
  335. position = {
  336. x: listenLayer.modifyPoint.x,
  337. y: listenLayer.modifyPoint.y,
  338. };
  339. }
  340. elementService.hideAll();
  341. elementService.setPoint(position);
  342. elementService.showPoint();
  343. if (listenLayer.modifyPoint) {
  344. elementService.execute(listenLayer.modifyPoint, position);
  345. }
  346. break;
  347. case LayerEvents.AddingRoad:
  348. needAutoRedraw = true;
  349. listenLayer.start(position);
  350. if (listenLayer.modifyPoint) {
  351. position = {
  352. x: listenLayer.modifyPoint.x,
  353. y: listenLayer.modifyPoint.y,
  354. };
  355. }
  356. elementService.execute(addRoad.startInfo.position, position);
  357. elementService.setPoint(position);
  358. elementService.setNewRoad(addRoad.startInfo.position, position);
  359. elementService.showNewRoad();
  360. addRoad.setNewRoadPoint("end", position);
  361. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  362. if (!addRoad.canAdd) {
  363. elementService.setNewRoadState("error");
  364. } else {
  365. elementService.setNewRoadState("normal");
  366. }
  367. break;
  368. case LayerEvents.AddingLine:
  369. needAutoRedraw = true;
  370. let exceptLineId = null;
  371. let exceptPointId = null;
  372. if (addLine.newLine != null) {
  373. exceptLineId = addLine.newLine.vectorId;
  374. exceptPointId = addLine.newLine.endId;
  375. }
  376. listenLayer.start(position, {
  377. exceptLineId: exceptLineId,
  378. exceptPointId: exceptPointId,
  379. });
  380. if (listenLayer.modifyPoint) {
  381. position = {
  382. x: listenLayer.modifyPoint.x,
  383. y: listenLayer.modifyPoint.y,
  384. };
  385. }
  386. elementService.execute(addLine.startInfo.position, position);
  387. elementService.setPoint(position);
  388. if (addLine.newLine == null) {
  389. addLine.buildLine(position);
  390. } else {
  391. addLine.updateLine(position);
  392. }
  393. break;
  394. case LayerEvents.AddingCurveLine:
  395. needAutoRedraw = true;
  396. let exceptCurveLineId = null;
  397. let exceptCurvePointId = null;
  398. if (addLine.newLine != null) {
  399. exceptCurveLineId = addLine.newLine.vectorId;
  400. exceptCurvePointId = addLine.newLine.endId;
  401. }
  402. listenLayer.start(position, {
  403. exceptCurveLineId: exceptCurveLineId,
  404. exceptCurvePointId: exceptCurvePointId,
  405. });
  406. if (listenLayer.modifyPoint) {
  407. position = {
  408. x: listenLayer.modifyPoint.x,
  409. y: listenLayer.modifyPoint.y,
  410. };
  411. }
  412. elementService.execute(addLine.startInfo.position, position);
  413. elementService.setPoint(position);
  414. if (addLine.newLine == null) {
  415. addLine.buildCurveLine(position);
  416. } else {
  417. addLine.updateCurveLine(position);
  418. }
  419. break;
  420. case LayerEvents.AddingCircle:
  421. needAutoRedraw = true;
  422. let exceptCircleId = null;
  423. if (addCircle.newCircle != null) {
  424. exceptCircleId = addCircle.newCircle.vectorId;
  425. }
  426. listenLayer.start(position, { exceptCircleId: exceptCircleId });
  427. if (listenLayer.modifyPoint) {
  428. position = {
  429. x: listenLayer.modifyPoint.x,
  430. y: listenLayer.modifyPoint.y,
  431. };
  432. }
  433. elementService.execute(addCircle.center, position);
  434. elementService.setPoint(position);
  435. if (addCircle.newCircle == null) {
  436. addCircle.buildCircle(position);
  437. } else {
  438. addCircle.updateCircle(position);
  439. }
  440. break;
  441. case LayerEvents.MoveRoad:
  442. needAutoRedraw = true;
  443. //只允许拖拽一条公路
  444. let road = dataService.getRoad(draggingItem.vectorId);
  445. let start = dataService.getRoadPoint(road.startId);
  446. let end = dataService.getRoadPoint(road.endId);
  447. if (
  448. Object.keys(start.getParent()).length == 1 &&
  449. Object.keys(end.getParent()).length == 1
  450. ) {
  451. //拖拽的路只有一条
  452. moveRoad.moveRoad(
  453. draggingItem.vectorId,
  454. (dx * coordinate.defaultZoom) / coordinate.zoom,
  455. (dy * coordinate.defaultZoom) / coordinate.zoom
  456. );
  457. }
  458. break;
  459. case LayerEvents.MoveRoadPoint:
  460. point = dataService.getRoadPoint(draggingItem.vectorId);
  461. listenLayer.start(position, {
  462. exceptRoadPointId: draggingItem.vectorId,
  463. exceptRoadIds: point.parent,
  464. });
  465. if (listenLayer.modifyPoint) {
  466. position = {
  467. x: listenLayer.modifyPoint.x,
  468. y: listenLayer.modifyPoint.y,
  469. };
  470. }
  471. let flag = moveRoad.moveingRoadPoint(
  472. draggingItem.vectorId,
  473. position,
  474. listenLayer.modifyPoint
  475. );
  476. if (!flag) {
  477. elementService.hideAll();
  478. } else {
  479. // point = dataService.getRoadPoint(draggingItem.vectorId);
  480. // listenLayer.start(point, {
  481. // exceptRoadPointId: draggingItem.vectorId,
  482. // exceptRoadIds: point.parent,
  483. // });
  484. let otherPoint = null;
  485. if (
  486. listenLayer.modifyPoint &&
  487. listenLayer.modifyPoint.linkedRoadPointId
  488. ) {
  489. otherPoint = dataService.getRoadPoint(
  490. listenLayer.modifyPoint.linkedRoadPointId
  491. );
  492. } else if (
  493. listenLayer.modifyPoint &&
  494. listenLayer.modifyPoint.linkedRoadPointIdX
  495. ) {
  496. otherPoint = dataService.getRoadPoint(
  497. listenLayer.modifyPoint.linkedRoadPointIdX
  498. );
  499. } else if (
  500. listenLayer.modifyPoint &&
  501. listenLayer.modifyPoint.linkedRoadPointIdY
  502. ) {
  503. otherPoint = dataService.getRoadPoint(
  504. listenLayer.modifyPoint.linkedRoadPointIdY
  505. );
  506. }
  507. elementService.execute(otherPoint, point);
  508. }
  509. needAutoRedraw = true;
  510. break;
  511. case LayerEvents.AddCurveRoad:
  512. needAutoRedraw = true;
  513. listenLayer.start(position);
  514. if (listenLayer.modifyPoint) {
  515. position = {
  516. x: listenLayer.modifyPoint.x,
  517. y: listenLayer.modifyPoint.y,
  518. };
  519. }
  520. elementService.hideAll();
  521. elementService.setPoint(position);
  522. elementService.showPoint();
  523. if (listenLayer.modifyPoint) {
  524. elementService.execute(listenLayer.modifyPoint, position);
  525. }
  526. break;
  527. case LayerEvents.AddingCurveRoad:
  528. needAutoRedraw = true;
  529. listenLayer.start(position);
  530. if (listenLayer.modifyPoint) {
  531. position = {
  532. x: listenLayer.modifyPoint.x,
  533. y: listenLayer.modifyPoint.y,
  534. };
  535. }
  536. elementService.execute(addRoad.startInfo.position, position);
  537. elementService.setPoint(position);
  538. elementService.setNewRoad(addRoad.startInfo.position, position);
  539. elementService.showNewRoad();
  540. addRoad.setNewRoadPoint("end", position);
  541. addRoad.canAdd = addRoad.canAddRoadForEnd(position);
  542. if (!addRoad.canAdd) {
  543. elementService.setNewRoadState("error");
  544. } else {
  545. elementService.setNewRoadState("normal");
  546. }
  547. break;
  548. case LayerEvents.MoveCurveRoad:
  549. needAutoRedraw = true;
  550. moveRoad.moveCurveRoad(
  551. draggingItem.vectorId,
  552. (dx * coordinate.defaultZoom) / coordinate.zoom,
  553. (dy * coordinate.defaultZoom) / coordinate.zoom
  554. );
  555. break;
  556. case LayerEvents.MoveCurveRoadPoint:
  557. if (!draggingItem || !draggingItem.vectorId) {
  558. return;
  559. }
  560. point = dataService.getCurveRoadPoint(draggingItem.vectorId);
  561. listenLayer.start(position, {
  562. exceptRoadPointId: draggingItem.vectorId,
  563. exceptCurveRoadId: point.parent, //不会融合,所以parent只有一个
  564. });
  565. if (listenLayer.modifyPoint) {
  566. position = {
  567. x: listenLayer.modifyPoint.x,
  568. y: listenLayer.modifyPoint.y,
  569. };
  570. }
  571. moveRoad.moveCurveRoadPoint(draggingItem.vectorId, position);
  572. needAutoRedraw = true;
  573. break;
  574. case LayerEvents.MoveCrossPoint:
  575. if (!draggingItem || !draggingItem.vectorId) {
  576. return;
  577. }
  578. moveRoad.moveCrossPoint(draggingItem.vectorId, position);
  579. needAutoRedraw = true;
  580. break;
  581. case LayerEvents.MoveEdge:
  582. moveRoad.moveEdge(draggingItem.vectorId, position);
  583. needAutoRedraw = true;
  584. break;
  585. case LayerEvents.MoveCurveEdge:
  586. if (listenLayer.modifyPoint) {
  587. moveRoad.moveCurveEdge(
  588. draggingItem.vectorId,
  589. listenLayer.modifyPoint.selectIndex,
  590. position
  591. );
  592. }
  593. needAutoRedraw = true;
  594. break;
  595. case LayerEvents.MoveLine:
  596. if (draggingItem != null) {
  597. moveLine.moveLine(
  598. draggingItem.vectorId,
  599. (dx * coordinate.defaultZoom) / coordinate.zoom,
  600. (dy * coordinate.defaultZoom) / coordinate.zoom
  601. );
  602. needAutoRedraw = true;
  603. }
  604. break;
  605. case LayerEvents.MovePoint:
  606. if (draggingItem != null) {
  607. point = dataService.getPoint(draggingItem.vectorId);
  608. listenLayer.start(position, {
  609. exceptPointId: draggingItem.vectorId,
  610. exceptLineId: point.parent,
  611. });
  612. if (listenLayer.modifyPoint) {
  613. position = {
  614. x: listenLayer.modifyPoint.x,
  615. y: listenLayer.modifyPoint.y,
  616. };
  617. }
  618. movePoint.movePoint(position, draggingItem.vectorId);
  619. needAutoRedraw = true;
  620. }
  621. break;
  622. case LayerEvents.MoveCurvePoint:
  623. if (draggingItem != null) {
  624. let curvePoint = dataService.getCurvePoint(draggingItem.vectorId);
  625. listenLayer.start(position, {
  626. exceptCurvePointId: draggingItem.vectorId,
  627. exceptCurveLineId: curvePoint.parent,
  628. });
  629. if (listenLayer.modifyPoint) {
  630. position = {
  631. x: listenLayer.modifyPoint.x,
  632. y: listenLayer.modifyPoint.y,
  633. };
  634. }
  635. movePoint.moveCurvePoint(position, draggingItem.vectorId);
  636. needAutoRedraw = true;
  637. }
  638. break;
  639. case LayerEvents.MoveCurveLine:
  640. if (draggingItem != null) {
  641. moveLine.moveCurveLine(
  642. draggingItem.vectorId,
  643. (dx * coordinate.defaultZoom) / coordinate.zoom,
  644. (dy * coordinate.defaultZoom) / coordinate.zoom
  645. );
  646. needAutoRedraw = true;
  647. }
  648. break;
  649. case LayerEvents.MoveCircle:
  650. if (draggingItem != null) {
  651. if (draggingItem.state == -1) {
  652. moveCircle.moveFull(
  653. draggingItem.vectorId,
  654. (dx * coordinate.defaultZoom) / coordinate.zoom,
  655. (dy * coordinate.defaultZoom) / coordinate.zoom
  656. );
  657. } else if (
  658. draggingItem.state == 0 ||
  659. draggingItem.state == 1 ||
  660. draggingItem.state == 2 ||
  661. draggingItem.state == 3
  662. ) {
  663. moveCircle.movePoint(
  664. position,
  665. draggingItem.vectorId,
  666. draggingItem.state
  667. );
  668. } else {
  669. debugger;
  670. }
  671. needAutoRedraw = true;
  672. }
  673. break;
  674. case LayerEvents.MoveText:
  675. needAutoRedraw = true;
  676. if (draggingItem != null) {
  677. moveText.moveFullText(position, draggingItem.vectorId);
  678. }
  679. break;
  680. case LayerEvents.MoveSVG:
  681. needAutoRedraw = true;
  682. if (draggingItem != null) {
  683. if (draggingItem.state == -1) {
  684. moveSVG.moveFullSVG(position, draggingItem.vectorId);
  685. } else {
  686. moveSVG.movePoint(
  687. position,
  688. draggingItem.vectorId,
  689. draggingItem.state
  690. );
  691. }
  692. }
  693. break;
  694. case LayerEvents.MoveMagnifier:
  695. needAutoRedraw = true;
  696. if (draggingItem != null) {
  697. moveMagnifier.moveFullMagnifier(position, draggingItem.vectorId);
  698. }
  699. break;
  700. }
  701. if (needAutoRedraw) {
  702. this.renderer.autoRedraw();
  703. }
  704. }
  705. onMouseUp(e) {
  706. // 右键
  707. if (e.button == 2) {
  708. this.dragging = false;
  709. return;
  710. }
  711. let X = e.offsetX || e.layerX;
  712. let Y = e.offsetY || e.layerY;
  713. if (e instanceof TouchEvent) {
  714. X = this.lastX;
  715. Y = this.lastY;
  716. this.StorePage1 = null;
  717. this.StorePage2 = null;
  718. this.StoreMidePage = null;
  719. if (e.touches.length > 1) {
  720. this.dragging = false;
  721. return;
  722. }
  723. }
  724. let eventName = stateService.getEventName();
  725. const draggingItem = stateService.getDraggingItem();
  726. const selectItem = stateService.getSelectItem();
  727. let focusItem = null;
  728. if (!this.dragging && selectItem) {
  729. focusItem = {
  730. vectorId: selectItem.vectorId,
  731. type: selectItem.type,
  732. cursor: { x: this.lastX, y: this.lastY },
  733. };
  734. stateService.setFocusItem(focusItem);
  735. this.uiControl.focusVector = focusItem;
  736. stateService.clearDraggingItem();
  737. } else {
  738. this.uiControl.focusVector = null;
  739. }
  740. this.dragging = false;
  741. let position = coordinate.getXYFromScreen({
  742. x: X,
  743. y: Y,
  744. });
  745. let needAutoRedraw = false;
  746. switch (eventName) {
  747. case null:
  748. return;
  749. case LayerEvents.PanBackGround:
  750. needAutoRedraw = true;
  751. stateService.clearFocusItem();
  752. this.uiControl.focusVector = null;
  753. this.uiControl.currentUI = null;
  754. break;
  755. case LayerEvents.MoveRoadPoint:
  756. if (!draggingItem || !draggingItem.vectorId) {
  757. break;
  758. }
  759. needAutoRedraw = true;
  760. elementService.hideAll();
  761. let point = dataService.getRoadPoint(draggingItem.vectorId);
  762. if (point) {
  763. listenLayer.start(point, {
  764. exceptPointId: draggingItem.vectorId,
  765. exceptRoadIds: point.parent,
  766. });
  767. if (
  768. listenLayer.modifyPoint &&
  769. listenLayer.modifyPoint.hasOwnProperty("linkedRoadPointId")
  770. ) {
  771. moveRoad.moveTo(
  772. draggingItem.vectorId,
  773. listenLayer.modifyPoint.linkedRoadPointId
  774. );
  775. } else if (
  776. listenLayer.modifyPoint &&
  777. (listenLayer.modifyPoint.linkedRoadPointIdX ||
  778. listenLayer.modifyPoint.linkedRoadPointIdY)
  779. ) {
  780. mathUtil.clonePoint(point, listenLayer.modifyPoint);
  781. } else if (
  782. listenLayer.modifyPoint &&
  783. listenLayer.modifyPoint.hasOwnProperty("linkedRoadId")
  784. ) {
  785. point = roadPointService.create({
  786. x: listenLayer.modifyPoint.x,
  787. y: listenLayer.modifyPoint.y,
  788. });
  789. roadService.splitRoad(
  790. listenLayer.modifyPoint.linkedRoadId,
  791. point.vectorId,
  792. "start"
  793. );
  794. moveRoad.moveTo(draggingItem.vectorId, point.vectorId);
  795. } else if (moveRoad.splitRoadId != null) {
  796. roadService.splitRoad(
  797. moveRoad.splitRoadId,
  798. draggingItem.vectorId,
  799. "start"
  800. );
  801. }
  802. //draggingItem.vectorId所在的墙面与其他墙角相交
  803. moveRoad.updateForAbsorbRoadPoints();
  804. let parent = point.getParent();
  805. for (let key in parent) {
  806. roadService.setLanes(key);
  807. }
  808. this.history.save();
  809. }
  810. break;
  811. // case LayerEvents.AddRoad:
  812. // addRoad.setNewRoadPoint("start", position);
  813. // break;
  814. case LayerEvents.AddingRoad:
  815. needAutoRedraw = true;
  816. if (addRoad.canAdd) {
  817. addRoad.buildRoad();
  818. this.history.save();
  819. elementService.hideAll();
  820. }
  821. break;
  822. case LayerEvents.AddingLine:
  823. needAutoRedraw = true;
  824. addLine.finish(position);
  825. this.updateForLocation();
  826. addLine.clearVectorData();
  827. this.history.save();
  828. elementService.hideAll();
  829. break;
  830. case LayerEvents.AddingCurveLine:
  831. needAutoRedraw = true;
  832. addLine.finishCurveLine(position);
  833. addLine.clearVectorData();
  834. this.history.save();
  835. elementService.hideAll();
  836. break;
  837. case LayerEvents.AddingCircle:
  838. needAutoRedraw = true;
  839. addCircle.finish(position);
  840. addCircle.clear();
  841. this.history.save();
  842. elementService.hideAll();
  843. break;
  844. case LayerEvents.MoveText:
  845. needAutoRedraw = true;
  846. this.history.save();
  847. elementService.hideAll();
  848. break;
  849. case LayerEvents.MoveSVG:
  850. needAutoRedraw = true;
  851. this.history.save();
  852. elementService.hideAll();
  853. break;
  854. case LayerEvents.MoveMagnifier:
  855. needAutoRedraw = true;
  856. this.history.save();
  857. elementService.hideAll();
  858. break;
  859. case LayerEvents.MoveSVG:
  860. needAutoRedraw = true;
  861. this.history.save();
  862. elementService.hideAll();
  863. break;
  864. case LayerEvents.AddingCurveRoad:
  865. needAutoRedraw = true;
  866. if (addRoad.canAdd) {
  867. addRoad.buildCurveRoad();
  868. this.history.save();
  869. elementService.hideAll();
  870. }
  871. break;
  872. case LayerEvents.MoveRoad:
  873. needAutoRedraw = true;
  874. this.history.save();
  875. break;
  876. case LayerEvents.MoveCurveRoad:
  877. needAutoRedraw = true;
  878. this.history.save();
  879. break;
  880. case LayerEvents.MoveCurveRoadPoint:
  881. needAutoRedraw = true;
  882. this.history.save();
  883. break;
  884. case LayerEvents.MoveCrossPoint:
  885. needAutoRedraw = true;
  886. this.history.save();
  887. break;
  888. case LayerEvents.MoveEdge:
  889. needAutoRedraw = true;
  890. this.history.save();
  891. break;
  892. case LayerEvents.MoveCurveEdge:
  893. needAutoRedraw = true;
  894. this.history.save();
  895. break;
  896. case LayerEvents.MoveLine:
  897. needAutoRedraw = true;
  898. this.history.save();
  899. break;
  900. case LayerEvents.MovePoint:
  901. needAutoRedraw = true;
  902. if (draggingItem && draggingItem.vectorId) {
  903. movePoint.finish(draggingItem.vectorId);
  904. uiService.setPointCategory(VectorCategory.Point.NormalPoint);
  905. }
  906. this.history.save();
  907. break;
  908. case LayerEvents.MoveCurvePoint:
  909. needAutoRedraw = true;
  910. this.history.save();
  911. break;
  912. case LayerEvents.MoveCurveLine:
  913. needAutoRedraw = true;
  914. this.history.save();
  915. break;
  916. case LayerEvents.MoveCircle:
  917. needAutoRedraw = true;
  918. this.history.save();
  919. break;
  920. }
  921. this.setEventName("mouseUp");
  922. stateService.clearDraggingItem();
  923. if (needAutoRedraw) {
  924. this.renderer.autoRedraw();
  925. }
  926. }
  927. onWheel(e) {
  928. e.preventDefault();
  929. const type = e.type;
  930. if (type == "DOMMouseScroll" || type == "mousewheel") {
  931. // 当在canvas用滚轮滚动时
  932. const delta = e.wheelDelta
  933. ? (e.wheelDelta / 120) * 20
  934. : (-(e.detail || 0) / 3) * 20;
  935. const zoom = coordinate.zoom + delta;
  936. let X = e.offsetX || e.layerX;
  937. let Y = e.offsetY || e.layerY;
  938. this.zoomVector(
  939. {
  940. x: X,
  941. y: Y,
  942. },
  943. zoom
  944. );
  945. }
  946. }
  947. zoomVector(position, zoom) {
  948. if (zoom < minZoom || zoom > maxZoom) {
  949. return;
  950. }
  951. let tempCenter = {};
  952. mathUtil.clonePoint(tempCenter, coordinate.center);
  953. let tempZoom = coordinate.zoom;
  954. coordinate.updateZoom(position, zoom);
  955. let inScreen = imageService.backgroundImgVertexsInScreenXY();
  956. if (!inScreen) {
  957. dataService.setGridForZoom();
  958. this.renderer.autoRedraw();
  959. } else {
  960. mathUtil.clonePoint(coordinate.center, tempCenter);
  961. coordinate.zoom = tempZoom;
  962. }
  963. }
  964. //测试用
  965. onKeydown(e) {
  966. let focusItem = stateService.getFocusItem();
  967. let dir = "left";
  968. if (focusItem) {
  969. console.log("键盘(foucus有效):" + e.code);
  970. if (e.code == "Delete") {
  971. //删除
  972. const road = dataService.getRoad(focusItem.vectorId);
  973. roadService.subtraRoadFromIntersect(road.startId, focusItem.vectorId);
  974. roadService.subtraRoadFromIntersect(road.endId, focusItem.vectorId);
  975. //dataService.deleteCrossPoint()
  976. dataService.deleteRoad(focusItem.vectorId);
  977. this.renderer.autoRedraw();
  978. this.history.save();
  979. }
  980. //加宽
  981. else if (e.code == "KeyA") {
  982. let road = dataService.getRoad(focusItem.vectorId);
  983. if (road) {
  984. roadService.updateForWidth(road.vectorId, road.leftWidth + 50, dir);
  985. } else {
  986. road = dataService.getCurveRoad(focusItem.vectorId);
  987. curveRoadService.updateForWidth(
  988. road.vectorId,
  989. road.leftWidth + 50,
  990. dir
  991. );
  992. }
  993. this.renderer.autoRedraw();
  994. this.history.save();
  995. }
  996. //变窄
  997. else if (e.code == "KeyB") {
  998. let road = dataService.getRoad(focusItem.vectorId);
  999. if (road) {
  1000. roadService.updateForWidth(road.vectorId, road.leftWidth - 25, dir);
  1001. } else {
  1002. road = dataService.getCurveRoad(focusItem.vectorId);
  1003. curveRoadService.updateForWidth(
  1004. road.vectorId,
  1005. road.leftWidth - 25,
  1006. dir
  1007. );
  1008. }
  1009. this.renderer.autoRedraw();
  1010. this.history.save();
  1011. }
  1012. //添加左车道
  1013. else if (e.code == "KeyQ") {
  1014. let road = dataService.getRoad(focusItem.vectorId);
  1015. if (road) {
  1016. roadService.updateForAddSubtractLanesCount(
  1017. focusItem.vectorId,
  1018. road.leftDrivewayCount + 1,
  1019. "left"
  1020. );
  1021. } else {
  1022. road = dataService.getCurveRoad(focusItem.vectorId);
  1023. curveRoadService.updateForAddSubtractLanesCount(
  1024. road,
  1025. road.leftDrivewayCount + 1, //rightDrivewayCount
  1026. "left"
  1027. );
  1028. }
  1029. this.renderer.autoRedraw();
  1030. this.history.save();
  1031. }
  1032. //减少左车道
  1033. else if (e.code == "KeyW") {
  1034. let road = dataService.getRoad(focusItem.vectorId);
  1035. if (road) {
  1036. roadService.updateForAddSubtractLanesCount(
  1037. focusItem.vectorId,
  1038. road.leftDrivewayCount - 1,
  1039. "left"
  1040. );
  1041. } else {
  1042. road = dataService.getCurveRoad(focusItem.vectorId);
  1043. curveRoadService.updateForAddSubtractLanesCount(
  1044. road,
  1045. road.leftDrivewayCount - 1, //rightDrivewayCount
  1046. "left"
  1047. );
  1048. }
  1049. this.renderer.autoRedraw();
  1050. this.history.save();
  1051. }
  1052. //添加右车道
  1053. else if (e.code == "KeyE") {
  1054. let road = dataService.getRoad(focusItem.vectorId);
  1055. if (road) {
  1056. roadService.updateForAddSubtractLanesCount(
  1057. focusItem.vectorId,
  1058. road.rightDrivewayCount + 1,
  1059. "right"
  1060. );
  1061. } else {
  1062. road = dataService.getCurveRoad(focusItem.vectorId);
  1063. curveRoadService.updateForAddSubtractLanesCount(
  1064. road,
  1065. road.rightDrivewayCount + 1, //rightDrivewayCount
  1066. "right"
  1067. );
  1068. }
  1069. this.renderer.autoRedraw();
  1070. this.history.save();
  1071. }
  1072. //减少右车道
  1073. else if (e.code == "KeyR") {
  1074. let road = dataService.getRoad(focusItem.vectorId);
  1075. if (road) {
  1076. roadService.updateForAddSubtractLanesCount(
  1077. focusItem.vectorId,
  1078. road.rightDrivewayCount - 1,
  1079. "right"
  1080. );
  1081. } else {
  1082. road = dataService.getCurveRoad(focusItem.vectorId);
  1083. curveRoadService.updateForAddSubtractLanesCount(
  1084. road,
  1085. road.rightDrivewayCount - 1, //rightDrivewayCount
  1086. "right"
  1087. );
  1088. }
  1089. this.renderer.autoRedraw();
  1090. this.history.save();
  1091. }
  1092. //弯路添加控制点
  1093. else if (e.code == "KeyT") {
  1094. const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
  1095. let index = mathUtil.getIndexForCurvesPoints(
  1096. this.mousePosition,
  1097. curveRoad.points
  1098. );
  1099. if (index != -1) {
  1100. curveRoadService.addCPoint(curveRoad, this.mousePosition, index);
  1101. } else {
  1102. const dis1 = mathUtil.getDistance(
  1103. curveRoad.points[0],
  1104. this.mousePosition
  1105. );
  1106. const dis2 = mathUtil.getDistance(
  1107. curveRoad.points[curveRoad.points.length - 1],
  1108. this.mousePosition
  1109. );
  1110. if (dis1 > dis2) {
  1111. curveRoadService.addCPoint(
  1112. curveRoad,
  1113. this.mousePosition,
  1114. curveRoad.points.length - 2
  1115. );
  1116. } else {
  1117. curveRoadService.addCPoint(curveRoad, this.mousePosition, 1);
  1118. }
  1119. }
  1120. this.renderer.autoRedraw();
  1121. this.history.save();
  1122. }
  1123. //弯路删除控制点
  1124. else if (e.code == "KeyY") {
  1125. const curvePoint = dataService.getCurveRoadPoint(focusItem.vectorId);
  1126. const curveRoad = dataService.getCurveRoad(curvePoint.parent);
  1127. curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
  1128. this.renderer.autoRedraw();
  1129. this.history.save();
  1130. }
  1131. } else {
  1132. console.log("键盘(foucus无效):" + e.code);
  1133. }
  1134. }
  1135. setEventName(eventType) {
  1136. let eventName = stateService.getEventName();
  1137. if (eventType == "mouseDown") {
  1138. if (eventName == null) {
  1139. const selectItem = stateService.getSelectItem();
  1140. if (selectItem == null) {
  1141. stateService.setEventName(LayerEvents.PanBackGround);
  1142. } else if (selectItem.type == VectorType.Road) {
  1143. stateService.setEventName(LayerEvents.MoveRoad);
  1144. } else if (selectItem.type == VectorType.RoadPoint) {
  1145. stateService.setEventName(LayerEvents.MoveRoadPoint);
  1146. } else if (selectItem.type == VectorType.CurveRoad) {
  1147. stateService.setEventName(LayerEvents.MoveCurveRoad);
  1148. } else if (selectItem.type == VectorType.CurveRoadPoint) {
  1149. stateService.setEventName(LayerEvents.MoveCurveRoadPoint);
  1150. } else if (selectItem.type == VectorType.CrossPoint) {
  1151. stateService.setEventName(LayerEvents.MoveCrossPoint);
  1152. } else if (selectItem.type == VectorType.RoadEdge) {
  1153. stateService.setEventName(LayerEvents.MoveEdge);
  1154. } else if (selectItem.type == VectorType.CurveRoadEdge) {
  1155. stateService.setEventName(LayerEvents.MoveCurveEdge);
  1156. } else if (selectItem.type == VectorType.Point) {
  1157. stateService.setEventName(LayerEvents.MovePoint);
  1158. } else if (selectItem.type == VectorType.Line) {
  1159. stateService.setEventName(LayerEvents.MoveLine);
  1160. } else if (selectItem.type == VectorType.CurvePoint) {
  1161. stateService.setEventName(LayerEvents.MoveCurvePoint);
  1162. } else if (selectItem.type == VectorType.CurveLine) {
  1163. stateService.setEventName(LayerEvents.MoveCurveLine);
  1164. } else if (selectItem.type == VectorType.Circle) {
  1165. stateService.setEventName(LayerEvents.MoveCircle);
  1166. } else if (selectItem.type == VectorType.Text) {
  1167. stateService.setEventName(LayerEvents.MoveText);
  1168. } else if (selectItem.type == VectorType.Magnifier) {
  1169. stateService.setEventName(LayerEvents.MoveMagnifier);
  1170. } else if (selectItem.type == VectorType.SVG) {
  1171. stateService.setEventName(LayerEvents.MoveSVG);
  1172. }
  1173. }
  1174. } else if (eventType == "mouseUp") {
  1175. if (eventName == LayerEvents.AddingRoad) {
  1176. if (Settings.isMobile) {
  1177. stateService.clearEventName();
  1178. this.exit();
  1179. } else {
  1180. stateService.setEventName(LayerEvents.AddRoad);
  1181. }
  1182. } else if (eventName == LayerEvents.AddingLine) {
  1183. if (Settings.isMobile) {
  1184. stateService.clearEventName();
  1185. this.exit();
  1186. uiService.setLineCategory(VectorCategory.Line.NormalLine);
  1187. } else {
  1188. stateService.setEventName(LayerEvents.AddLine);
  1189. }
  1190. } else if (eventName == LayerEvents.AddingCurveRoad) {
  1191. if (Settings.isMobile) {
  1192. stateService.clearEventName();
  1193. this.exit();
  1194. } else {
  1195. stateService.setEventName(LayerEvents.AddCurveRoad);
  1196. }
  1197. } else if (eventName == LayerEvents.AddLine) {
  1198. stateService.setEventName(LayerEvents.AddingLine);
  1199. } else {
  1200. stateService.clearEventName();
  1201. }
  1202. }
  1203. }
  1204. exit() {
  1205. stateService.clear();
  1206. this.uiControl.clearUI();
  1207. this.uiControl.focusVector = null;
  1208. this.uiControl.currentUI = null;
  1209. }
  1210. stopAddVector() {
  1211. let eventName = stateService.getEventName();
  1212. if (
  1213. eventName != LayerEvents.AddingRoad &&
  1214. eventName != LayerEvents.AddingLine
  1215. ) {
  1216. stateService.clearEventName();
  1217. } else if (eventName == LayerEvents.AddingRoad) {
  1218. stateService.setEventName(LayerEvents.AddRoad);
  1219. } else if (eventName == LayerEvents.AddingLine) {
  1220. stateService.setEventName(LayerEvents.AddLine);
  1221. }
  1222. addLine.clear(); //之前会保留category
  1223. this.uiControl.clearUI();
  1224. elementService.hideAll();
  1225. this.renderer.autoRedraw();
  1226. }
  1227. initLocation() {
  1228. Settings.baseLineId = null;
  1229. this.uiControl.graphicStateUI.canAngleLocationMode = false;
  1230. this.uiControl.graphicStateUI.canAllLocationMode = false;
  1231. this.uiControl.graphicStateUI.existsBaseLine = false;
  1232. }
  1233. //更新定位信息
  1234. updateForLocation() {
  1235. if (Settings.baseLineId) {
  1236. this.uiControl.graphicStateUI.canAngleLocationMode = true;
  1237. this.uiControl.graphicStateUI.canAllLocationMode = true;
  1238. this.uiControl.graphicStateUI.existsBaseLine = true;
  1239. } else {
  1240. this.uiControl.graphicStateUI.canAngleLocationMode = false;
  1241. this.uiControl.graphicStateUI.canAllLocationMode = false;
  1242. this.uiControl.graphicStateUI.existsBaseLine = false;
  1243. }
  1244. }
  1245. }