UIControl.js 23 KB

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