UIControl.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. import { coordinate } from "../Coordinate.js";
  2. import LayerEvents from "../enum/LayerEvents.js";
  3. import UIEvents from "../enum/UIEvents.js";
  4. import RoadTemplate from "../enum/RoadTemplate.js";
  5. import VectorType from "../enum/VectorType.js";
  6. import VectorStyle from "../enum/VectorStyle.js";
  7. import VectorWeight from "../enum/VectorWeight.js";
  8. import GeoActions from "../enum/GeoActions.js";
  9. import VectorEvents from "../enum/VectorEvents.js";
  10. import SVGType from "../enum/SVGType.js";
  11. import { stateService } from "../Service/StateService.js";
  12. import { uiService } from "../Service/UIService.js";
  13. import { dataService } from "../Service/DataService.js";
  14. import { historyService } from "../Service/HistoryService.js";
  15. import { elementService } from "../Service/ElementService";
  16. import { lineService } from "../Service/LineService.js";
  17. import { circleService } from "../Service/CircleService.js";
  18. import { textService } from "../Service/TextService.js";
  19. import { svgService } from "../Service/SVGService.js";
  20. import { magnifierService } from "../Service/MagnifierService.js";
  21. import { mathUtil } from "../Util/MathUtil";
  22. import Constant from "../Constant";
  23. // import { roomsUtil } from "../Room/RoomsUtil.js";
  24. import { addRoad } from "../Controls/AddRoad";
  25. import { addLine } from "./AddLine.js";
  26. import VectorCategory from "../enum/VectorCategory.js";
  27. // import { floorplanData } from "../VectorData.js";
  28. import { pointService } from "../Service/PointService.js";
  29. import Settings from "../Settings.js";
  30. import { addPoint } from "./AddPoint.js";
  31. import { locationModeControl } from "./LocationModeControl.js";
  32. import { curveRoadPointService } from "../Service/CurveRoadPointService.js";
  33. import { roadService } from "../Service/RoadService.js";
  34. import { curveRoadService } from "../Service/CurveRoadService.js";
  35. import Msg from "../enum/Msg.js";
  36. import RoadStructure from "../enum/RoadStructure";
  37. export default class UIControl {
  38. constructor(layer, newsletter, graphicStateUI) {
  39. this._prompts = [];
  40. this.layer = layer;
  41. this.newsletter = newsletter;
  42. this.graphicStateUI = graphicStateUI;
  43. }
  44. get selectUI() {
  45. return this.newsletter.selectUI;
  46. }
  47. set selectUI(selectUI) {
  48. this.updateEventNameForSelectUI(selectUI);
  49. this.newsletter.selectUI = selectUI;
  50. }
  51. get focusVector() {
  52. return this.newsletter.focusVector;
  53. }
  54. set focusVector(focusVector) {
  55. this.newsletter.focusVector = focusVector;
  56. }
  57. /**
  58. * 获取选中要操作的UI
  59. */
  60. get currentUI() {}
  61. /**
  62. * 设置选中要操作的UI
  63. */
  64. set currentUI(value) {
  65. this.selectUI = value;
  66. }
  67. clearUI() {
  68. this.clearCurrentUI();
  69. this.clearSelectUI();
  70. }
  71. clearFocusVector() {
  72. this.focusVector = null;
  73. }
  74. clearSelectUI() {
  75. this.selectUI = null;
  76. }
  77. clearCurrentUI() {
  78. this.currentUI = null;
  79. }
  80. //点击左侧栏后,更新事件
  81. updateEventNameForSelectUI(selectUI) {
  82. console.log(this.selectUI, selectUI);
  83. if (selectUI != null) {
  84. if (this.selectUI == selectUI) {
  85. return;
  86. } else if (this.selectUI != selectUI) {
  87. if (this.selectUI != null) {
  88. //先取消当前事件和进程
  89. this.layer.exit();
  90. }
  91. //恢复默认
  92. uiService.setSelectLocationMode(null);
  93. uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
  94. uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
  95. //执行新的事件
  96. if (uiService.isBelongRoad(selectUI) || selectUI == "road") {
  97. stateService.setEventName(LayerEvents.AddRoad);
  98. } else if (selectUI == UIEvents.CurveRoad) {
  99. stateService.setEventName(LayerEvents.AddCurveRoad);
  100. } else if (uiService.isBelongLine(selectUI)) {
  101. if (Settings.selectSVGType == RoadStructure.ZebraCrossing) {
  102. uiService.setSelectSVGType(null);
  103. }
  104. stateService.setEventName(LayerEvents.AddLine);
  105. }
  106. // else if (selectUI == UIEvents.CurveLine) {
  107. // stateService.setEventName(LayerEvents.AddCurveLine);
  108. // }
  109. else if (uiService.isBelongPoint(selectUI)) {
  110. stateService.setEventName(LayerEvents.AddPoint);
  111. } else if (selectUI == UIEvents.Circle) {
  112. stateService.setEventName(LayerEvents.AddCircle);
  113. } else if (selectUI == UIEvents.Text) {
  114. stateService.setEventName(LayerEvents.AddText);
  115. } else if (selectUI == UIEvents.Magnifier) {
  116. stateService.setEventName(LayerEvents.AddMagnifier);
  117. } else if (SVGType[selectUI]) {
  118. uiService.setSelectSVGType(selectUI);
  119. if (selectUI == RoadStructure.ZebraCrossing) {
  120. stateService.setEventName(LayerEvents.AddLine);
  121. } else {
  122. stateService.setEventName(LayerEvents.AddSVG);
  123. }
  124. } else if (selectUI == UIEvents.Img) {
  125. stateService.setEventName(LayerEvents.Img);
  126. } else if (uiService.isBelongRoadTemplate(selectUI)) {
  127. stateService.setEventName(LayerEvents.AddRoadTemplate);
  128. } else if (uiService.isBelongRoadStructure(selectUI)) {
  129. } else if (selectUI == Constant.angleLocationMode) {
  130. uiService.setSelectLocationMode(Constant.angleLocationMode);
  131. let msg = locationModeControl.setAngle();
  132. if (msg != Msg.OK) {
  133. uiService.prompt({ msg: msg, time: 1000 });
  134. } else {
  135. this.layer.history.save();
  136. this.layer.renderer.autoRedraw();
  137. }
  138. }
  139. }
  140. }
  141. }
  142. updateVectorForSelectUI(selectUI) {
  143. console.log("selectUI", selectUI);
  144. const focusItem = stateService.getFocusItem();
  145. // if (selectUI == VectorStyle.Bold || selectUI == VectorStyle.Thinning) {
  146. // if (focusItem.type == VectorType.Line) {
  147. // let Line = dataService.getLine(focusItem.vectorId);
  148. // Line.setStyle(selectUI);
  149. // } else if (focusItem.type == VectorType.RoadEdge) {
  150. // let roadEdge = dataService.getRoadEdge(focusItem.vectorId);
  151. // if (roadEdge) {
  152. // roadEdge.setStyle(selectUI);
  153. // } else {
  154. // roadEdge = dataService.getCurveRoadEdge(focusItem.vectorId);
  155. // roadEdge.setStyle(selectUI);
  156. // }
  157. // }
  158. // this.layer.history.save();
  159. // this.layer.renderer.autoRedraw();
  160. // }
  161. // else
  162. if (uiService.isBelongRoadEdgeStyle(selectUI)) {
  163. let key = null;
  164. if (VectorStyle[selectUI]) {
  165. key = "setStyle";
  166. } else if (VectorWeight[selectUI]) {
  167. key = "setWeight";
  168. }
  169. if (focusItem.type == VectorType.Line) {
  170. let Line = dataService.getLine(focusItem.vectorId);
  171. // Line.setStyle(selectUI);
  172. Line[key](selectUI);
  173. } else if (focusItem.type == VectorType.CurveLine) {
  174. let Line = dataService.getCurveLine(focusItem.vectorId);
  175. // Line.setStyle(selectUI);
  176. Line[key](selectUI);
  177. } else {
  178. let roadEdge = dataService.getRoadEdge(focusItem.vectorId);
  179. if (roadEdge) {
  180. if (selectUI == VectorStyle.RoadSide) {
  181. //修改路缘线
  182. roadEdge.initRoadSide();
  183. roadEdge[key](selectUI);
  184. } else {
  185. roadEdge[key](selectUI);
  186. let crossPoint = dataService.getCrossPoint4(focusItem.vectorId);
  187. if (crossPoint) {
  188. crossPoint[key](selectUI);
  189. }
  190. if (roadEdge.roadSide) {
  191. roadEdge.removeRoadSide();
  192. }
  193. }
  194. } else {
  195. roadEdge = dataService.getCurveRoadEdge(focusItem.vectorId);
  196. if (selectUI == VectorStyle.RoadSide) {
  197. //修改路缘线
  198. roadEdge.initCurveRoadSide();
  199. } else {
  200. roadEdge[key](selectUI);
  201. if (roadEdge.roadSide) {
  202. roadEdge.removeCurveRoadSide();
  203. }
  204. }
  205. }
  206. }
  207. this.layer.history.save();
  208. this.layer.renderer.autoRedraw();
  209. } else if (selectUI == VectorEvents.AddLane) {
  210. if (focusItem && focusItem.vectorId) {
  211. stateService.setEventName(VectorEvents.AddLane);
  212. }
  213. // if (focusItem && focusItem.dir && focusItem.vectorId) {
  214. // let road = dataService.getRoad(focusItem.vectorId);
  215. // if (road) {
  216. // if (focusItem.dir == "left") {
  217. // roadService.updateForAddSubtractLanesCount(
  218. // road.vectorId,
  219. // road.leftDrivewayCount + 1,
  220. // focusItem.dir
  221. // );
  222. // } else {
  223. // roadService.updateForAddSubtractLanesCount(
  224. // road.vectorId,
  225. // road.rightDrivewayCount + 1,
  226. // focusItem.dir
  227. // );
  228. // }
  229. // } else {
  230. // road = dataService.getCurveRoad(focusItem.vectorId);
  231. // if (focusItem.dir == "left") {
  232. // curveRoadService.updateForAddSubtractLanesCount(
  233. // road.vectorId,
  234. // road.leftDrivewayCount + 1,
  235. // focusItem.dir
  236. // );
  237. // } else {
  238. // curveRoadService.updateForAddSubtractLanesCount(
  239. // road.vectorId,
  240. // road.rightDrivewayCount + 1,
  241. // focusItem.dir
  242. // );
  243. // }
  244. // }
  245. // }
  246. } else if (selectUI == VectorEvents.DelLane) {
  247. if (focusItem && focusItem.vectorId) {
  248. stateService.setEventName(VectorEvents.DelLane);
  249. }
  250. // if (focusItem && focusItem.dir && focusItem.vectorId) {
  251. // let road = dataService.getRoad(focusItem.vectorId);
  252. // if (road) {
  253. // if (focusItem.dir == "left") {
  254. // roadService.updateForAddSubtractLanesCount(
  255. // road.vectorId,
  256. // road.leftDrivewayCount - 1,
  257. // focusItem.dir
  258. // );
  259. // } else {
  260. // roadService.updateForAddSubtractLanesCount(
  261. // road.vectorId,
  262. // road.rightDrivewayCount - 1,
  263. // focusItem.dir
  264. // );
  265. // }
  266. // } else {
  267. // road = dataService.getCurveRoad(focusItem.vectorId);
  268. // if (focusItem.dir == "left") {
  269. // curveRoadService.updateForAddSubtractLanesCount(
  270. // road.vectorId,
  271. // road.leftDrivewayCount - 1,
  272. // focusItem.dir
  273. // );
  274. // } else {
  275. // curveRoadService.updateForAddSubtractLanesCount(
  276. // road.vectorId,
  277. // road.rightDrivewayCount - 1,
  278. // focusItem.dir
  279. // );
  280. // }
  281. // }
  282. // }
  283. } else if (selectUI == VectorEvents.AddCrossPoint) {
  284. if (focusItem && focusItem.vectorId) {
  285. stateService.setEventName(VectorEvents.AddCrossPoint);
  286. }
  287. // if (focusItem && focusItem.dir && focusItem.vectorId) {
  288. // const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
  289. // let index = mathUtil.getIndexForCurvesPoints(
  290. // this.mousePosition,
  291. // curveRoad.points
  292. // );
  293. // if (index != -1) {
  294. // curveRoadService.addCPoint(curveRoad, this.mousePosition, index);
  295. // } else {
  296. // const dis1 = mathUtil.getDistance(
  297. // curveRoad.points[0],
  298. // this.mousePosition
  299. // );
  300. // const dis2 = mathUtil.getDistance(
  301. // curveRoad.points[curveRoad.points.length - 1],
  302. // this.mousePosition
  303. // );
  304. // if (dis1 > dis2) {
  305. // curveRoadService.addCPoint(
  306. // curveRoad,
  307. // this.mousePosition,
  308. // curveRoad.points.length - 2
  309. // );
  310. // } else {
  311. // curveRoadService.addCPoint(curveRoad, this.mousePosition, 1);
  312. // }
  313. // }
  314. // }
  315. } else if (selectUI == VectorEvents.MinusCrossPoint) {
  316. if (focusItem && focusItem.vectorId) {
  317. stateService.setEventName(VectorEvents.MinusCrossPoint);
  318. }
  319. // if (focusItem && focusItem.dir && focusItem.vectorId) {
  320. // const curvePoint = dataService.getCurveRoadPoint(focusItem.vectorId);
  321. // const curveRoad = dataService.getCurveRoad(curvePoint.parent);
  322. // curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
  323. // }
  324. } else if (selectUI == VectorEvents.AddBranchRoad) {
  325. } else if (selectUI == VectorEvents.AddNarrowRoad) {
  326. } else if (selectUI == VectorEvents.UnLock) {
  327. let road = dataService.getRoad(focusItem.vectorId);
  328. if (road) {
  329. roadService.convertToLines(focusItem.vectorId);
  330. } else {
  331. road = dataService.getCurveRoad(focusItem.vectorId);
  332. if (road) {
  333. curveRoadService.convertToCurveLines(focusItem.vectorId);
  334. }
  335. }
  336. if (road) {
  337. this.deleteVector(focusItem.vectorId, focusItem.type);
  338. this.layer.history.save();
  339. this.layer.renderer.autoRedraw();
  340. }
  341. }
  342. }
  343. async handleGeo(action) {
  344. let needAutoRedraw = false;
  345. const item = stateService.getFocusItem();
  346. if (item && item.vectorId) {
  347. switch (action) {
  348. case GeoActions.CopyAction:
  349. await this.copyVector(item.vectorId, item.type);
  350. needAutoRedraw = true;
  351. break;
  352. case GeoActions.DeleteAction:
  353. this.deleteVector(item.vectorId, item.type);
  354. needAutoRedraw = true;
  355. break;
  356. }
  357. }
  358. if (needAutoRedraw) {
  359. this.layer.history.save();
  360. this.layer.renderer.autoRedraw();
  361. }
  362. }
  363. //删除按钮
  364. deleteVector(vectorId, geoType) {
  365. switch (geoType) {
  366. case VectorType.Point:
  367. let point = dataService.getPoint(vectorId);
  368. let parent = point.getParent();
  369. for (let key in parent) {
  370. if (Settings.baseLineId == key) {
  371. this.layer.initLocation();
  372. break;
  373. }
  374. }
  375. pointService.deletePoint(vectorId);
  376. break;
  377. case VectorType.Line:
  378. let line = dataService.getLine(vectorId);
  379. dataService.deleteLine(vectorId);
  380. if (vectorId == Settings.baseLineId) {
  381. this.layer.initLocation();
  382. } else if (
  383. line.getCategory() == VectorCategory.Line.ExtendedPositionLine ||
  384. line.getCategory() == VectorCategory.Line.PositionLine ||
  385. line.getCategory() == VectorCategory.Line.GuidePositionLine
  386. ) {
  387. let startPoint = dataService.getPoint(line.startId);
  388. let endPoint = dataService.getPoint(line.endId);
  389. if (startPoint.getCategory() != VectorCategory.Point.BasePoint) {
  390. pointService.deletePoint(line.startId);
  391. }
  392. if (endPoint.getCategory() != VectorCategory.Point.BasePoint) {
  393. pointService.deletePoint(line.endId);
  394. }
  395. } else if (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint) {
  396. let lines = dataService.getLines();
  397. for (let key in lines) {
  398. let _line = dataService.getLine(key);
  399. if (_line.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
  400. if (line.startId == _line.startId || line.startId == _line.endId || line.endId == _line.startId || line.endId == _line.endId) {
  401. dataService.deleteLine(key);
  402. break;
  403. }
  404. }
  405. }
  406. } else if (line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) {
  407. let lines = dataService.getLines();
  408. for (let key in lines) {
  409. let _line = dataService.getLine(key);
  410. if (_line.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
  411. if (line.startId == _line.startId || line.startId == _line.endId || line.endId == _line.startId || line.endId == _line.endId) {
  412. dataService.deleteLine(key);
  413. }
  414. } else if (_line.getCategory() == VectorCategory.Line.GuideLocationLine) {
  415. if (line.startId == _line.startId || line.startId == _line.endId || line.endId == _line.startId || line.endId == _line.endId) {
  416. dataService.deleteLine(key);
  417. }
  418. }
  419. }
  420. }
  421. break;
  422. case VectorType.CurveLine:
  423. lineService.deleteCurveLine(vectorId);
  424. break;
  425. case VectorType.CurvePoint:
  426. const curvePoint = dataService.getCurvePoint(vectorId);
  427. lineService.deleteCrossPointForCurveLine(vectorId, curvePoint.getParent());
  428. break;
  429. case VectorType.Circle:
  430. dataService.deleteCircle(vectorId);
  431. break;
  432. case VectorType.Text:
  433. textService.deleteText(vectorId);
  434. break;
  435. case VectorType.Magnifier:
  436. dataService.deleteMagnifier(vectorId);
  437. break;
  438. case VectorType.Road:
  439. roadService.deleteRoadForLinked(vectorId);
  440. break;
  441. case VectorType.RoadPoint:
  442. const roadPoint = dataService.getRoadPoint(vectorId);
  443. const roadPointParent = roadPoint.getParent();
  444. for (let key in roadPointParent) {
  445. roadService.deleteRoadForLinked(key);
  446. }
  447. break;
  448. case VectorType.CurveRoadPoint:
  449. curveRoadPointService.deleteCurveRoadPoint(vectorId);
  450. break;
  451. case VectorType.CurveRoad:
  452. dataService.deleteCurveRoad(vectorId);
  453. break;
  454. case VectorType.SVG:
  455. dataService.deleteSVG(vectorId);
  456. break;
  457. }
  458. this.layer.exit();
  459. uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
  460. uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
  461. this.clearFocusVector();
  462. }
  463. //复制按钮
  464. async copyVector(vectorId, geoType) {
  465. let item;
  466. switch (geoType) {
  467. case VectorType.Line:
  468. const lineId = lineService.copy(vectorId);
  469. item = stateService.getFocusItem();
  470. item.vectorId = lineId;
  471. break;
  472. case VectorType.CurveLine:
  473. const curveLineId = lineService.copyCurveLine(vectorId);
  474. item = stateService.getFocusItem();
  475. item.vectorId = curveLineId;
  476. break;
  477. case VectorType.Circle:
  478. const circleId = circleService.copy(vectorId);
  479. item = stateService.getFocusItem();
  480. item.vectorId = circleId;
  481. break;
  482. case VectorType.Text:
  483. const textId = textService.copy(vectorId);
  484. item = stateService.getFocusItem();
  485. item.vectorId = textId;
  486. break;
  487. case VectorType.Road:
  488. const roadId = roadService.copyRoad(vectorId);
  489. item = stateService.getFocusItem();
  490. item.vectorId = roadId;
  491. break;
  492. case VectorType.CurveRoad:
  493. const curveRoadId = curveRoadService.copyCurveRoad(vectorId);
  494. item = stateService.getFocusItem();
  495. item.vectorId = curveRoadId;
  496. break;
  497. case VectorType.Magnifier:
  498. const magnifierId = await magnifierService.copy(vectorId);
  499. item = stateService.getFocusItem();
  500. if (magnifierId) {
  501. item.vectorId = magnifierId;
  502. }
  503. break;
  504. case VectorType.SVG:
  505. const svgId = svgService.copy(vectorId);
  506. item = stateService.getFocusItem();
  507. item.vectorId = svgId;
  508. break;
  509. }
  510. stateService.clearEventName();
  511. }
  512. //截图
  513. async screenShot() {
  514. let canvas = this.layer.canvas;
  515. this.menu_view_reset();
  516. //隐藏grid
  517. Settings.screenMode = true;
  518. dataService.setGridDisplay(false);
  519. this.layer.renderer.autoRedraw();
  520. // this.downloadCadImg(canvas, "test.jpg");
  521. const blob = await this.getCadBlob(canvas);
  522. //显示grid
  523. dataService.setGridDisplay(true);
  524. Settings.screenMode = false;
  525. this.layer.renderer.autoRedraw();
  526. return blob;
  527. }
  528. getCadBlob(canvas) {
  529. var type = "jpg";
  530. return new Promise((resolve) => canvas.toBlob(resolve, `${type}/image`));
  531. }
  532. // downloadCadImg(canvas, filename) {
  533. // // 图片导出为 jpg 格式
  534. // var type = "jpg";
  535. // var imgData = canvas.toDataURL(type, 3);
  536. // canvas.toBlob(`${type}/image`);
  537. // // 加工image data,替换mime type
  538. // imgData = imgData.replace(this._fixType(type), "image/octet-stream");
  539. // // 下载后的图片名
  540. // //var filename = 'cad_' + new Date().getTime() + '.' + type
  541. // // download
  542. // this.saveFile(imgData, filename);
  543. // }
  544. saveFile(data, filename) {
  545. var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
  546. save_link.href = data;
  547. save_link.download = filename;
  548. var event = document.createEvent("MouseEvents");
  549. event.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  550. save_link.dispatchEvent(event);
  551. }
  552. _fixType(type) {
  553. type = type.toLowerCase().replace(/jpg/i, "jpeg");
  554. var r = type.match(/png|jpeg|bmp|gif/)[0];
  555. return "image/" + r;
  556. }
  557. /****************************************************************************针对菜单*******************************************************************************/
  558. //撤销
  559. menu_revoke() {
  560. this.layer.history.goPreState();
  561. const historyState = historyService.getHistoryState();
  562. this.graphicStateUI.canRevoke = historyState.pre;
  563. this.graphicStateUI.canRecovery = true;
  564. this.layer.stopAddVector();
  565. this.layer.renderer.autoRedraw();
  566. }
  567. //恢复
  568. menu_recovery() {
  569. this.layer.history.goNextState();
  570. const historyState = historyService.getHistoryState();
  571. this.graphicStateUI.canRecovery = historyState.next;
  572. this.graphicStateUI.canRevoke = true;
  573. this.layer.stopAddVector();
  574. this.layer.renderer.autoRedraw();
  575. }
  576. menu_view_reset() {
  577. coordinate.reSet(this.layer.canvas);
  578. this.layer.renderer.autoRedraw();
  579. }
  580. // value 为true则开 false则关
  581. menu_backgroundImg(value) {
  582. console.log(value);
  583. //
  584. const backgroundImg = dataService.getBackgroundImg();
  585. backgroundImg.setDisplay(value);
  586. this.graphicStateUI.showBackImage = value;
  587. this.layer.renderer.autoRedraw();
  588. }
  589. menu_clear(isBack) {
  590. dataService.clear();
  591. Settings.selectLocationMode = null;
  592. uiService.setBaseLineId(null);
  593. uiService.setSelectBasePointId(null);
  594. elementService.hideAll();
  595. this.layer.exit();
  596. this.layer.initLocation();
  597. if (!isBack) {
  598. this.layer.history.save();
  599. } else {
  600. historyService.clearHistoryRecord();
  601. this.layer.uiControl.graphicStateUI.canRevoke = false;
  602. this.layer.uiControl.graphicStateUI.canRecovery = false;
  603. }
  604. this.layer.renderer.autoRedraw();
  605. }
  606. /******************************************************************************************************************************************************************/
  607. // 进入持续添加出确认与取消框
  608. showConfirm() {
  609. this.graphicStateUI.continuedMode = true;
  610. }
  611. confirmEntry() {
  612. console.log("确认");
  613. this.graphicStateUI.continuedMode = false;
  614. this.layer.exit();
  615. this.layer.history.save();
  616. this.layer.renderer.autoRedraw();
  617. uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
  618. uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
  619. }
  620. confirmCancel() {
  621. console.log("取消");
  622. this.graphicStateUI.continuedMode = false;
  623. this.layer.exit();
  624. this.layer.history.save();
  625. this.layer.history.handleUndo();
  626. this.layer.renderer.autoRedraw();
  627. uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
  628. uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
  629. }
  630. // 设置默认设置
  631. setDefaultSetting(setting) {
  632. console.log("获得设置", setting);
  633. uiService.setRoadMidDivideWidth(setting.roadQuarantineWidth / coordinate.res);
  634. uiService.setCurveRoadMidDivideWidth(setting.roadQuarantineWidth / coordinate.res);
  635. Constant.defaultMidDivideWidth = setting.roadQuarantineWidth;
  636. uiService.setSingleLaneWidth(setting.singleRoadWidth / coordinate.res);
  637. Constant.defaultSingleLaneWidth = setting.singleRoadWidth;
  638. uiService.setLineWidth(setting.lineWidth);
  639. this.layer.renderer.autoRedraw();
  640. }
  641. // 获取默认设置
  642. getDefaultSetting() {
  643. const singleLaneWidth = Constant.defaultSingleLaneWidth;
  644. const roadMidDivideWidth = Constant.defaultMidDivideWidth;
  645. const lineWidth = uiService.getLineWidth();
  646. return {
  647. singleRoadWidth: singleLaneWidth,
  648. roadQuarantineWidth: roadMidDivideWidth,
  649. lineWidth: lineWidth,
  650. };
  651. }
  652. }