ListenLayer.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. import { mathUtil } from "./Util/MathUtil";
  2. import { dataService } from "./Service/DataService.js";
  3. import { stateService } from "./Service/StateService.js";
  4. import { roadService } from "./Service/RoadService.js";
  5. import Constant from "./Constant.js";
  6. import VectorType from "./enum/VectorType.js";
  7. import SelectState from "./enum/SelectState.js";
  8. import bezierUtil from "./Util/bezierUtil.js";
  9. import { elementService } from "./Service/ElementService";
  10. import { coordinate } from "./Coordinate";
  11. import { draw } from "./Renderer/Draw.js";
  12. import { edgeService } from "./Service/EdgeService";
  13. import VectorCategory from "./enum/VectorCategory";
  14. export default class ListenLayer {
  15. constructor() {
  16. this.modifyPoint = null;
  17. }
  18. //开始监听,exceptVectorIds表示不考虑的元素
  19. /**
  20. *
  21. * @param exceptVectorIds:{
  22. exceptPointId,
  23. exceptLineId,
  24. exceptCurvePointId,
  25. exceptCurveLineId,
  26. exceptRoadPointId,
  27. exceptRoadIds,
  28. exceptCurveRoadPointId,
  29. exceptCurveRoadId,
  30. exceptCrossCrossPointId,
  31. exceptTextId,
  32. exceptSVGId,
  33. }
  34. * @returns
  35. */
  36. start(position, exceptVectorIds) {
  37. let flag = false;
  38. let selectInfo = {};
  39. if (!exceptVectorIds) {
  40. exceptVectorIds = {};
  41. }
  42. this.clear();
  43. selectInfo.curveRoadEdgeInfo = this.isSelectCurveRoad(
  44. position,
  45. exceptVectorIds.exceptCurveRoadId
  46. ); //包括edge
  47. selectInfo.roadEdgeInfo = this.isSelectRoad(
  48. position,
  49. exceptVectorIds.exceptRoadIds
  50. ); //包括edge
  51. selectInfo.curveRoadPointInfo = this.isSelectCurveRoadPoint(
  52. position,
  53. exceptVectorIds.exceptCurveRoadPointId
  54. );
  55. selectInfo.roadPointInfo = this.isSelectRoadPoint(
  56. position,
  57. exceptVectorIds.exceptRoadPointId
  58. );
  59. selectInfo.pointInfo = this.isSelectPoint(
  60. position,
  61. exceptVectorIds.exceptPointId
  62. );
  63. selectInfo.lineInfo = this.isSelectLine(
  64. position,
  65. exceptVectorIds.exceptLineId
  66. );
  67. selectInfo.curvePointInfo = this.isSelectCurvePoint(
  68. position,
  69. exceptVectorIds.exceptCurvePointId
  70. );
  71. selectInfo.curveLineInfo = this.isSelectCurveLine(
  72. position,
  73. exceptVectorIds.exceptCurveLineId
  74. );
  75. selectInfo.circleInfo = this.isSelectCircle(
  76. position,
  77. exceptVectorIds.exceptCircleId
  78. );
  79. //交叉口拐弯处的控制点
  80. selectInfo.crossPointInfo = this.isSelectCrossCrossPoint(
  81. position,
  82. exceptVectorIds.exceptCrossCrossPointId
  83. );
  84. selectInfo.textInfo = this.isSelectText(
  85. position,
  86. exceptVectorIds.exceptTextId
  87. );
  88. selectInfo.svgInfo = this.isSelectSVG(
  89. position,
  90. exceptVectorIds.exceptSVGId
  91. );
  92. selectInfo.magnifierInfo = this.isSelectMagnifier(
  93. position,
  94. exceptVectorIds.exceptMagnifierId
  95. );
  96. this.setModifyPoint(position, selectInfo);
  97. flag = this.updateSelectItem();
  98. return flag;
  99. }
  100. isSelectCurvePoint(position, exceptCurvePointId) {
  101. let curvePointInfo = {
  102. curvePointId: null,
  103. type: null,
  104. distance: null,
  105. };
  106. let seqInfo = {};
  107. const curvePoints = dataService.getCurvePoints();
  108. for (const curvePointId in curvePoints) {
  109. if (curvePointId == exceptCurvePointId) {
  110. continue;
  111. }
  112. const curvePoint = dataService.getCurvePoint(curvePointId);
  113. const distance = this.getDistance(position, curvePoint);
  114. if (distance < Constant.minAdsorbPix) {
  115. if (curvePointInfo.curvePointId == null) {
  116. curvePointInfo = {
  117. curvePointId: curvePointId,
  118. type: VectorType.CurvePoint,
  119. distance: distance,
  120. };
  121. } else {
  122. if (distance < curvePointInfo.distance) {
  123. curvePointInfo = {
  124. curvePointId: curvePointId,
  125. type: VectorType.CurvePoint,
  126. distance: distance,
  127. };
  128. }
  129. }
  130. } else {
  131. if (Math.abs(position.x - curvePoint.x) < Constant.minAdsorbPix) {
  132. seqInfo.linkedCurvePointIdX = curvePointId;
  133. seqInfo.x = curvePoint.x;
  134. }
  135. if (Math.abs(position.y - curvePoint.y) < Constant.minAdsorbPix) {
  136. seqInfo.linkedPointIdY = curvePointId;
  137. seqInfo.y = curvePoint.y;
  138. }
  139. }
  140. }
  141. if (curvePointInfo.curvePointId) {
  142. curvePointInfo.linkedCurvePointId = curvePointInfo.curvePointId;
  143. const linkedCurvePoint = dataService.getCurvePoint(
  144. curvePointInfo.curvePointId
  145. );
  146. curvePointInfo.x = linkedCurvePoint.x;
  147. curvePointInfo.y = linkedCurvePoint.y;
  148. } else {
  149. if (seqInfo.hasOwnProperty("linkedCurvePointIdX")) {
  150. curvePointInfo.linkedCurvePointIdX = seqInfo.linkedCurvePointIdX;
  151. curvePointInfo.x = seqInfo.x;
  152. }
  153. if (seqInfo.hasOwnProperty("linkedCurvePointIdY")) {
  154. curvePointInfo.linkedCurvePointIdY = seqInfo.linkedCurvePointIdY;
  155. curvePointInfo.y = seqInfo.y;
  156. }
  157. if (
  158. curvePointInfo.hasOwnProperty("y") &&
  159. !curvePointInfo.hasOwnProperty("x")
  160. ) {
  161. curvePointInfo.x = position.x;
  162. }
  163. if (
  164. curvePointInfo.hasOwnProperty("x") &&
  165. !curvePointInfo.hasOwnProperty("y")
  166. ) {
  167. curvePointInfo.y = position.y;
  168. }
  169. }
  170. return curvePointInfo;
  171. }
  172. isSelectCurveLine(position, exceptCurveLineIds) {
  173. let curveLineInfo = {
  174. curveLineId: null,
  175. type: null,
  176. distance: null,
  177. };
  178. const curveLines = dataService.getCurveLines();
  179. for (const curveLineId in curveLines) {
  180. if (
  181. exceptCurveLineIds &&
  182. exceptCurveLineIds.hasOwnProperty(curveLineId)
  183. ) {
  184. continue;
  185. }
  186. const curveLine = dataService.getCurveLine(curveLineId);
  187. let joinInfo = this.distanceForBezier(
  188. position,
  189. curveLine.curves,
  190. Constant.minAdsorbPix
  191. );
  192. //选中了路
  193. if (joinInfo.distance < Constant.minAdsorbPix) {
  194. curveLineInfo = {
  195. curveLineId: curveLineId,
  196. type: VectorType.CurveLine,
  197. distance: joinInfo.distance,
  198. x: joinInfo.position.x,
  199. y: joinInfo.position.y,
  200. };
  201. }
  202. }
  203. return curveLineInfo;
  204. }
  205. isSelectPoint(position, exceptPointId) {
  206. let pointInfo = {
  207. pointId: null,
  208. type: null,
  209. distance: null,
  210. };
  211. let seqInfo = {};
  212. const points = dataService.getPoints();
  213. for (const pointId in points) {
  214. if (pointId == exceptPointId) {
  215. continue;
  216. }
  217. const point = dataService.getPoint(pointId);
  218. if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
  219. continue;
  220. }
  221. const distance = this.getDistance(position, point);
  222. if (distance < Constant.minAdsorbPix) {
  223. if (pointInfo.pointId == null) {
  224. pointInfo = {
  225. pointId: pointId,
  226. type: VectorType.Point,
  227. distance: distance,
  228. };
  229. } else {
  230. if (distance < pointInfo.distance) {
  231. pointInfo = {
  232. pointId: pointId,
  233. type: VectorType.Point,
  234. distance: distance,
  235. };
  236. }
  237. }
  238. } else {
  239. if (Math.abs(position.x - point.x) < Constant.minAdsorbPix) {
  240. seqInfo.linkedPointIdX = pointId;
  241. seqInfo.x = point.x;
  242. }
  243. if (Math.abs(position.y - point.y) < Constant.minAdsorbPix) {
  244. seqInfo.linkedPointIdY = pointId;
  245. seqInfo.y = point.y;
  246. }
  247. }
  248. }
  249. if (pointInfo.pointId) {
  250. pointInfo.linkedPointId = pointInfo.pointId;
  251. const linkedPoint = dataService.getPoint(pointInfo.pointId);
  252. pointInfo.x = linkedPoint.x;
  253. pointInfo.y = linkedPoint.y;
  254. } else {
  255. if (seqInfo.hasOwnProperty("linkedPointIdX")) {
  256. pointInfo.linkedPointIdX = seqInfo.linkedPointIdX;
  257. pointInfo.x = seqInfo.x;
  258. }
  259. if (seqInfo.hasOwnProperty("linkedPointIdY")) {
  260. pointInfo.linkedPointIdY = seqInfo.linkedPointIdY;
  261. pointInfo.y = seqInfo.y;
  262. }
  263. if (pointInfo.hasOwnProperty("y") && !pointInfo.hasOwnProperty("x")) {
  264. pointInfo.x = position.x;
  265. }
  266. if (pointInfo.hasOwnProperty("x") && !pointInfo.hasOwnProperty("y")) {
  267. pointInfo.y = position.y;
  268. }
  269. }
  270. return pointInfo;
  271. }
  272. isSelectLine(position, exceptLineId) {
  273. let lineInfo = {
  274. lineId: null,
  275. type: null,
  276. distance: null,
  277. };
  278. const lines = dataService.getLines();
  279. for (const lineId in lines) {
  280. if (exceptLineId == lineId) {
  281. continue;
  282. }
  283. const line = dataService.getLine(lineId);
  284. if (
  285. line.getCategory() == VectorCategory.Line.PositionLine ||
  286. line.getCategory() == VectorCategory.Line.BaseLine
  287. ) {
  288. continue;
  289. }
  290. let startPoint = dataService.getPoint(line.startId);
  291. let endPoint = dataService.getPoint(line.endId);
  292. const comLine = mathUtil.createLine1(startPoint, endPoint);
  293. const join = mathUtil.getJoinLinePoint(position, comLine);
  294. const distance = this.getDistance(position, join);
  295. if (!mathUtil.isContainForSegment(join, startPoint, endPoint)) {
  296. continue;
  297. }
  298. if (distance < Constant.minAdsorbPix / 2) {
  299. lineInfo = {
  300. lineId: lineId,
  301. type: VectorType.Line,
  302. distance: distance,
  303. };
  304. }
  305. }
  306. if (lineInfo.lineId) {
  307. const linkedLine = dataService.getLine(lineInfo.lineId);
  308. let startPoint = dataService.getPoint(linkedLine.startId);
  309. let endPoint = dataService.getPoint(linkedLine.endId);
  310. const linkedComLine = mathUtil.createLine1(startPoint, endPoint);
  311. const linkedPosition = mathUtil.getJoinLinePoint(position, linkedComLine);
  312. lineInfo.x = linkedPosition.x;
  313. lineInfo.y = linkedPosition.y;
  314. return lineInfo;
  315. }
  316. return lineInfo;
  317. }
  318. isSelectCircle(position, exceptCircleId) {
  319. let circleInfo = {
  320. circleId: null,
  321. type: null,
  322. distance: null,
  323. };
  324. const circles = dataService.getCircles();
  325. let distance;
  326. for (const circleId in circles) {
  327. if (circleId == exceptCircleId) {
  328. continue;
  329. }
  330. const circle = dataService.getCircle(circleId);
  331. for (let i = 0; i < circle.points.length; ++i) {
  332. distance = this.getDistance(position, circle.points[i]);
  333. if (distance < Constant.minAdsorbPix) {
  334. circleInfo = {
  335. circleId: circleId,
  336. type: VectorType.Circle,
  337. distance: distance,
  338. x: circle.points[i].x,
  339. y: circle.points[i].y,
  340. index: i,
  341. };
  342. return circleInfo;
  343. }
  344. }
  345. distance = this.getDistance(position, circle.center);
  346. if (distance < circle.radius) {
  347. if (circleInfo.circleId == null || distance < circleInfo.distance) {
  348. circleInfo = {
  349. circleId: circleId,
  350. type: VectorType.Circle,
  351. distance: distance,
  352. x: circle.center.x,
  353. y: circle.center.y,
  354. index: -1,
  355. };
  356. }
  357. }
  358. }
  359. return circleInfo;
  360. }
  361. // isSelectCurveLine(position, exceptCurveLineId) {
  362. // let curveLineInfo = {
  363. // curveLineId: null,
  364. // type: null,
  365. // distance: null,
  366. // };
  367. // let seqInfo = {};
  368. // const curveLines = dataService.getCurveLines();
  369. // for (const curveLineId in curveLines) {
  370. // if (curveLineId == exceptCurveLineId) {
  371. // continue;
  372. // }
  373. // const curveLine = dataService.getCurveLine(curveLineId);
  374. // let joinInfo = this.distanceForBezier(
  375. // position,
  376. // curveRoad.curves,
  377. // Constant.minAdsorbPix / 2
  378. // );
  379. // if (
  380. // mathUtil.isClockwise([curveRoad.points[0], joinInfo.position, position])
  381. // ) {
  382. // //选中了路
  383. // if (joinInfo.distance < curveRoad.leftWidth - Constant.minAdsorbPix) {
  384. // curveRoadInfo = {
  385. // curveRoadId: curveRoadId,
  386. // type: VectorType.CurveRoad,
  387. // distance: joinInfo.distance,
  388. // x: joinInfo.position.x,
  389. // y: joinInfo.position.y,
  390. // };
  391. // }
  392. // //选中了edge
  393. // else if (
  394. // joinInfo.distance <
  395. // curveRoad.leftWidth + Constant.minAdsorbPix
  396. // ) {
  397. // const leftCurveEdge = dataService.getCurveRoadEdge(
  398. // curveRoad.leftEdgeId
  399. // );
  400. // joinInfo = this.distanceForBezier(
  401. // position,
  402. // leftCurveEdge.curves,
  403. // curveRoad.leftWidth
  404. // );
  405. // const index = mathUtil.getIndexForCurvesPoints(
  406. // joinInfo.position,
  407. // curveRoad.points
  408. // );
  409. // curveEdgeInfo = {
  410. // curveEdgeId: curveRoad.leftEdgeId,
  411. // type: VectorType.CurveRoadEdge,
  412. // distance: joinInfo.distance,
  413. // selectIndex: index,
  414. // x: joinInfo.position.x,
  415. // y: joinInfo.position.y,
  416. // };
  417. // }
  418. // } else if (
  419. // !mathUtil.isClockwise([
  420. // curveRoad.points[0],
  421. // joinInfo.position,
  422. // position,
  423. // ])
  424. // ) {
  425. // //选中了路
  426. // if (joinInfo.distance < curveRoad.rightWidth - Constant.minAdsorbPix) {
  427. // curveRoadInfo = {
  428. // curveRoadId: curveRoadId,
  429. // type: VectorType.CurveRoad,
  430. // distance: joinInfo.distance,
  431. // x: joinInfo.position.x,
  432. // y: joinInfo.position.y,
  433. // };
  434. // }
  435. // //选中了edge
  436. // else if (
  437. // joinInfo.distance <
  438. // curveRoad.rightWidth + Constant.minAdsorbPix
  439. // ) {
  440. // const rightCurveEdge = dataService.getCurveRoadEdge(
  441. // curveRoad.rightEdgeId
  442. // );
  443. // joinInfo = this.distanceForBezier(
  444. // position,
  445. // rightCurveEdge.curves,
  446. // curveRoad.rightWidth
  447. // );
  448. // const index = mathUtil.getIndexForCurvesPoints(
  449. // joinInfo.position,
  450. // curveRoad.points
  451. // );
  452. // curveEdgeInfo = {
  453. // curveEdgeId: curveRoad.rightEdgeId,
  454. // type: VectorType.CurveRoadEdge,
  455. // distance: joinInfo.distance,
  456. // selectIndex: index,
  457. // x: joinInfo.position.x,
  458. // y: joinInfo.position.y,
  459. // };
  460. // }
  461. // }
  462. // }
  463. // if (curveRoadInfo.curveRoadId) {
  464. // return curveRoadInfo;
  465. // } else if (curveEdgeInfo.curveEdgeId) {
  466. // return curveEdgeInfo;
  467. // } else {
  468. // return {
  469. // curveRoadId: null,
  470. // curveEdgeId: null,
  471. // };
  472. // }
  473. // }
  474. isSelectRoadPoint(position, exceptRoadPointId) {
  475. let roadPointInfo = {
  476. roadPointId: null,
  477. type: null,
  478. distance: null,
  479. };
  480. let seqInfo = {};
  481. const roadPoints = dataService.getRoadPoints();
  482. for (const roadPointId in roadPoints) {
  483. if (roadPointId == exceptRoadPointId) {
  484. continue;
  485. }
  486. const roadPoint = dataService.getRoadPoint(roadPointId);
  487. const distance = this.getDistance(position, roadPoint);
  488. if (distance < Constant.minAdsorbPix) {
  489. if (roadPointInfo.roadPointId == null) {
  490. roadPointInfo = {
  491. roadPointId: roadPointId,
  492. type: VectorType.RoadPoint,
  493. distance: distance,
  494. };
  495. } else if (roadPointInfo.roadPointId != null) {
  496. if (distance < roadPointInfo.distance) {
  497. roadPointInfo = {
  498. roadPointId: roadPointId,
  499. type: VectorType.RoadPoint,
  500. distance: distance,
  501. };
  502. }
  503. }
  504. } else {
  505. if (Math.abs(position.x - roadPoint.x) < Constant.minAdsorbPix) {
  506. seqInfo.linkedRoadPointIdX = roadPointId;
  507. seqInfo.x = roadPoint.x;
  508. } else if (Math.abs(position.y - roadPoint.y) < Constant.minAdsorbPix) {
  509. seqInfo.linkedRoadPointIdY = roadPointId;
  510. seqInfo.y = roadPoint.y;
  511. }
  512. }
  513. }
  514. if (roadPointInfo.roadPointId) {
  515. const linkedPoint = dataService.getRoadPoint(roadPointInfo.roadPointId);
  516. roadPointInfo.x = linkedPoint.x;
  517. roadPointInfo.y = linkedPoint.y;
  518. }
  519. //因为这种纠正的权限最低
  520. else {
  521. if (seqInfo.hasOwnProperty("linkedRoadPointIdX")) {
  522. roadPointInfo.linkedRoadPointIdX = seqInfo.linkedRoadPointIdX;
  523. roadPointInfo.x = seqInfo.x;
  524. }
  525. if (seqInfo.hasOwnProperty("linkedRoadPointIdY")) {
  526. roadPointInfo.linkedRoadPointIdY = seqInfo.linkedRoadPointIdY;
  527. roadPointInfo.y = seqInfo.y;
  528. }
  529. if (
  530. roadPointInfo.hasOwnProperty("y") &&
  531. !roadPointInfo.hasOwnProperty("x")
  532. ) {
  533. roadPointInfo.x = position.x;
  534. }
  535. if (
  536. roadPointInfo.hasOwnProperty("x") &&
  537. !roadPointInfo.hasOwnProperty("y")
  538. ) {
  539. roadPointInfo.y = position.y;
  540. }
  541. }
  542. return roadPointInfo;
  543. }
  544. isSelectCurveRoadPoint(position, exceptCurveRoadPointId) {
  545. let curveRoadPointInfo = {
  546. curveRoadPointId: null,
  547. type: null,
  548. distance: null,
  549. };
  550. let seqInfo = {};
  551. const curveRoadPoints = dataService.getCurveRoadPoints();
  552. for (const curveRoadPointId in curveRoadPoints) {
  553. if (curveRoadPointId == exceptCurveRoadPointId) {
  554. continue;
  555. }
  556. const curveRoadPoint = dataService.getCurveRoadPoint(curveRoadPointId);
  557. const distance = this.getDistance(position, curveRoadPoint);
  558. if (distance < Constant.minAdsorbPix) {
  559. if (curveRoadPointInfo.curveRoadPointId == null) {
  560. curveRoadPointInfo = {
  561. curveRoadPointId: curveRoadPointId,
  562. type: VectorType.CurveRoadPoint,
  563. distance: distance,
  564. };
  565. } else {
  566. if (distance < curveRoadPointInfo.distance) {
  567. curveRoadPointInfo = {
  568. curveRoadPointId: curveRoadPointId,
  569. type: VectorType.CurveRoadPoint,
  570. distance: distance,
  571. };
  572. }
  573. }
  574. } else {
  575. if (Math.abs(position.x - curveRoadPoint.x) < Constant.minAdsorbPix) {
  576. seqInfo.linkedCurveRoadPointIdX = curveRoadPointId;
  577. seqInfo.x = curveRoadPoint.x;
  578. } else if (
  579. Math.abs(position.y - curveRoadPoint.y) < Constant.minAdsorbPix
  580. ) {
  581. seqInfo.linkedCurveRoadPointIdY = curveRoadPointId;
  582. seqInfo.y = curveRoadPoint.y;
  583. }
  584. }
  585. }
  586. if (curveRoadPointInfo.curveRoadPointId) {
  587. curveRoadPointInfo.linkedCurveRoadPointId =
  588. curveRoadPointInfo.curveRoadPointId;
  589. const linkedCurvePoint = dataService.getCurveRoadPoint(
  590. curveRoadPointInfo.curveRoadPointId
  591. );
  592. curveRoadPointInfo.x = linkedCurvePoint.x;
  593. curveRoadPointInfo.y = linkedCurvePoint.y;
  594. } else {
  595. if (seqInfo.hasOwnProperty("linkedCurveRoadPointIdX")) {
  596. curveRoadPointInfo.linkedCurveRoadPointIdX =
  597. seqInfo.linkedCurveRoadPointIdX;
  598. curveRoadPointInfo.x = seqInfo.x;
  599. } else if (seqInfo.hasOwnProperty("linkedCurveRoadPointIdY")) {
  600. curveRoadPointInfo.linkedCurveRoadPointIdY =
  601. seqInfo.linkedCurveRoadPointIdY;
  602. curveRoadPointInfo.y = seqInfo.y;
  603. }
  604. if (
  605. curveRoadPointInfo.hasOwnProperty("y") &&
  606. !curveRoadPointInfo.hasOwnProperty("x")
  607. ) {
  608. curveRoadPointInfo.x = position.x;
  609. }
  610. if (
  611. curveRoadPointInfo.hasOwnProperty("x") &&
  612. !curveRoadPointInfo.hasOwnProperty("y")
  613. ) {
  614. curveRoadPointInfo.y = position.y;
  615. }
  616. }
  617. return curveRoadPointInfo;
  618. }
  619. isSelectRoad(position, exceptRoadIds) {
  620. let roadInfo = {
  621. roadId: null,
  622. type: null,
  623. distance: null,
  624. };
  625. let edgeInfo = {
  626. edgeId: null,
  627. type: null,
  628. distance: null,
  629. dir: null,
  630. };
  631. const roads = dataService.getRoads();
  632. for (const roadId in roads) {
  633. if (exceptRoadIds != null && exceptRoadIds.hasOwnProperty(roadId)) {
  634. continue;
  635. }
  636. const road = dataService.getRoad(roadId);
  637. let startPoint = dataService.getRoadPoint(road.startId);
  638. let endPoint = dataService.getRoadPoint(road.endId);
  639. const leftEdge = dataService.getRoadEdge(road.leftEdgeId);
  640. const rightEdge = dataService.getRoadEdge(road.rightEdgeId);
  641. const roadLine = roadService.getMidLine(road);
  642. let join = mathUtil.getJoinLinePoint(position, roadLine);
  643. let distance = this.getDistance(position, join);
  644. if (
  645. mathUtil.isContainForSegment(join, startPoint, endPoint) &&
  646. distance < Constant.minAdsorbPix
  647. ) {
  648. if (!roadInfo.roadId || distance < roadInfo.distance) {
  649. roadInfo = {
  650. roadId: roadId,
  651. type: VectorType.Road,
  652. distance: distance,
  653. };
  654. }
  655. }
  656. //检查edge
  657. let leftLine = mathUtil.createLine1(leftEdge.start, leftEdge.end);
  658. join = mathUtil.getJoinLinePoint(position, leftLine);
  659. distance = this.getDistance(position, join);
  660. if (
  661. mathUtil.isContainForSegment(join, leftEdge.start, leftEdge.end) &&
  662. distance < Constant.minAdsorbPix
  663. ) {
  664. if (!edgeInfo.edgeId || distance < edgeInfo.distance) {
  665. edgeInfo = {
  666. edgeId: road.leftEdgeId,
  667. type: VectorType.RoadEdge,
  668. distance: distance,
  669. dir: "left",
  670. };
  671. }
  672. }
  673. let rightLine = mathUtil.createLine1(rightEdge.start, rightEdge.end);
  674. join = mathUtil.getJoinLinePoint(position, rightLine);
  675. distance = this.getDistance(position, join);
  676. if (
  677. mathUtil.isContainForSegment(join, rightEdge.start, rightEdge.end) &&
  678. distance < Constant.minAdsorbPix
  679. ) {
  680. if (!edgeInfo.edgeId || distance < edgeInfo.distance) {
  681. edgeInfo = {
  682. edgeId: road.rightEdgeId,
  683. type: VectorType.RoadEdge,
  684. distance: distance,
  685. dir: "right",
  686. };
  687. }
  688. }
  689. }
  690. if (
  691. roadInfo.roadId &&
  692. (!edgeInfo.edgeId || roadInfo.distance < edgeInfo.distance)
  693. ) {
  694. const linkedRoad = dataService.getRoad(roadInfo.roadId);
  695. const linkedRoadLine = roadService.getMidLine(linkedRoad);
  696. const linkedPosition = mathUtil.getJoinLinePoint(
  697. position,
  698. linkedRoadLine
  699. );
  700. roadInfo.x = linkedPosition.x;
  701. roadInfo.y = linkedPosition.y;
  702. return roadInfo;
  703. } else if (edgeInfo.edgeId) {
  704. if (edgeInfo.dir == "left") {
  705. const leftEdge = dataService.getRoadEdge(edgeInfo.edgeId);
  706. const leftLine = edgeService.getLine(leftEdge);
  707. const linkedPosition = mathUtil.getJoinLinePoint(position, leftLine);
  708. edgeInfo.x = linkedPosition.x;
  709. edgeInfo.y = linkedPosition.y;
  710. } else {
  711. const rightEdge = dataService.getRoadEdge(edgeInfo.edgeId);
  712. const rightLine = edgeService.getLine(rightEdge);
  713. const linkedPosition = mathUtil.getJoinLinePoint(position, rightLine);
  714. edgeInfo.x = linkedPosition.x;
  715. edgeInfo.y = linkedPosition.y;
  716. }
  717. return edgeInfo;
  718. }
  719. return {
  720. roadId: null,
  721. edgeId: null,
  722. };
  723. }
  724. isSelectCurveRoad(position, exceptCurveRoadId) {
  725. let curveRoadInfo = {
  726. curveRoadId: null,
  727. type: null,
  728. distance: null,
  729. };
  730. let curveEdgeInfo = {
  731. curveEdgeId: null,
  732. type: null,
  733. distance: null,
  734. };
  735. const curveRoads = dataService.getCurveRoads();
  736. for (const curveRoadId in curveRoads) {
  737. if (curveRoadId == exceptCurveRoadId) {
  738. continue;
  739. }
  740. const curveRoad = dataService.getCurveRoad(curveRoadId);
  741. let joinInfo = this.distanceForBezier(
  742. position,
  743. curveRoad.curves,
  744. Constant.minAdsorbPix
  745. );
  746. //选中了路
  747. if (joinInfo.distance < Constant.minAdsorbPix) {
  748. curveRoadInfo = {
  749. curveRoadId: curveRoadId,
  750. type: VectorType.CurveRoad,
  751. distance: joinInfo.distance,
  752. x: joinInfo.position.x,
  753. y: joinInfo.position.y,
  754. };
  755. }
  756. //检查edge
  757. else {
  758. const leftCurveEdge = dataService.getCurveRoadEdge(
  759. curveRoad.leftEdgeId
  760. );
  761. joinInfo = this.distanceForBezier(
  762. position,
  763. leftCurveEdge.curves,
  764. Constant.minAdsorbPix
  765. );
  766. if (joinInfo.distance < Constant.minAdsorbPix) {
  767. const index = mathUtil.getIndexForCurvesPoints(
  768. joinInfo.position,
  769. curveRoad.points
  770. );
  771. curveEdgeInfo = {
  772. curveEdgeId: curveRoad.leftEdgeId,
  773. type: VectorType.CurveRoadEdge,
  774. distance: joinInfo.distance,
  775. selectIndex: index,
  776. x: joinInfo.position.x,
  777. y: joinInfo.position.y,
  778. };
  779. } else {
  780. const rightCurveEdge = dataService.getCurveRoadEdge(
  781. curveRoad.rightEdgeId
  782. );
  783. joinInfo = this.distanceForBezier(
  784. position,
  785. rightCurveEdge.curves,
  786. Constant.minAdsorbPix
  787. );
  788. if (joinInfo.distance < Constant.minAdsorbPix) {
  789. const index = mathUtil.getIndexForCurvesPoints(
  790. joinInfo.position,
  791. curveRoad.points
  792. );
  793. curveEdgeInfo = {
  794. curveEdgeId: curveRoad.rightEdgeId,
  795. type: VectorType.CurveRoadEdge,
  796. distance: joinInfo.distance,
  797. selectIndex: index,
  798. x: joinInfo.position.x,
  799. y: joinInfo.position.y,
  800. };
  801. }
  802. }
  803. }
  804. }
  805. if (curveRoadInfo.curveRoadId) {
  806. return curveRoadInfo;
  807. } else if (curveEdgeInfo.curveEdgeId) {
  808. return curveEdgeInfo;
  809. } else {
  810. return {
  811. curveRoadId: null,
  812. curveEdgeId: null,
  813. };
  814. }
  815. }
  816. isSelectCrossCrossPoint(position, exceptCrossCrossPointId) {
  817. let crossCrossPointInfo = {
  818. crossCrossPointId: null,
  819. type: null,
  820. distance: null,
  821. };
  822. const crossPoints = dataService.getCrossPoints();
  823. for (const crossPointId in crossPoints) {
  824. if (crossPointId == exceptCrossCrossPointId) {
  825. continue;
  826. }
  827. const crossPoint = dataService.getCrossPoint2(crossPointId);
  828. const distance = this.getDistance(position, crossPoint.extremePoint);
  829. if (distance < Constant.minAdsorbPix) {
  830. crossCrossPointInfo = {
  831. crossCrossPointId: crossPointId,
  832. type: VectorType.CrossPoint,
  833. distance: distance,
  834. x: crossPoint.extremePoint.x,
  835. y: crossPoint.extremePoint.y,
  836. };
  837. }
  838. }
  839. return crossCrossPointInfo;
  840. }
  841. isSelectText(position, exceptTextId) {
  842. let textInfo = {
  843. textId: null,
  844. type: null,
  845. distance: null,
  846. };
  847. const texts = dataService.getTexts();
  848. for (const textId in texts) {
  849. if (textId == exceptTextId) {
  850. continue;
  851. }
  852. const text = dataService.getText(textId);
  853. const distance = this.getDistance(position, text.center);
  854. if (distance < Constant.minAdsorbPix) {
  855. textInfo = {
  856. textId: textId,
  857. type: VectorType.Text,
  858. distance: distance,
  859. x: text.center.x,
  860. y: text.center.y,
  861. };
  862. }
  863. }
  864. return textInfo;
  865. }
  866. isSelectSVG(position, exceptSVGId) {
  867. let svgInfo = {
  868. svgId: null,
  869. type: null,
  870. distance: null,
  871. };
  872. const svgs = dataService.getSVGs();
  873. for (const svgId in svgs) {
  874. if (svgId == exceptSVGId) {
  875. continue;
  876. }
  877. const svg = dataService.getSVG(svgId);
  878. for (let i = 0; i < svg.points.length; ++i) {
  879. let distance = this.getDistance(position, svg.points[i]);
  880. if (!svgInfo.svgId && distance < Constant.minAdsorbPix / 5) {
  881. svgInfo = {
  882. svgId: svgId,
  883. distance: distance,
  884. type: VectorType.SVG,
  885. index: i,
  886. };
  887. } else if (svgInfo.svgId && distance < svgInfo.distance) {
  888. svgInfo = {
  889. svgId: svgId,
  890. distance: distance,
  891. type: VectorType.SVG,
  892. index: i,
  893. };
  894. }
  895. }
  896. if (svgInfo.svgId) {
  897. return svgInfo;
  898. }
  899. let flag = mathUtil.isPointInPoly(position, svg.points);
  900. if (flag) {
  901. svgInfo = {
  902. svgId: svgId,
  903. type: VectorType.SVG,
  904. index: -1,
  905. };
  906. }
  907. break;
  908. }
  909. return svgInfo;
  910. }
  911. isSelectMagnifier(position, exceptMagnifierId) {
  912. let magnifierInfo = {
  913. magnifierId: null,
  914. type: null,
  915. distance: null,
  916. };
  917. const magnifiers = dataService.getMagnifiers();
  918. for (const magnifierId in magnifiers) {
  919. if (magnifierId == exceptMagnifierId) {
  920. continue;
  921. }
  922. const magnifier = dataService.getMagnifier(magnifierId);
  923. const distance = this.getDistance(position, magnifier.position);
  924. if (distance < Constant.minAdsorbPix) {
  925. magnifierInfo = {
  926. magnifierId: magnifierId,
  927. type: VectorType.Magnifier,
  928. distance: distance,
  929. x: magnifier.position.x,
  930. y: magnifier.position.y,
  931. };
  932. }
  933. }
  934. return magnifierInfo;
  935. }
  936. /**
  937. *
  938. * @param info:{
  939. roadPointInfo,
  940. curveRoadPointInfo,
  941. roadEdgeInfo,
  942. curveRoadEdgeInfo,
  943. crossPointInfo,
  944. pointInfo,
  945. roadPointInfo
  946. }
  947. */
  948. setModifyPoint(position, info) {
  949. //优先级最高
  950. if (
  951. info &&
  952. (info.roadPointInfo.roadPointId ||
  953. info.curveRoadPointInfo.curveRoadPointId)
  954. ) {
  955. this.modifyPoint = {};
  956. if (
  957. info.roadPointInfo.roadPointId &&
  958. info.curveRoadPointInfo.curveRoadPointId
  959. ) {
  960. if (info.roadPointInfo.distance < info.curveRoadPointInfo.distance) {
  961. this.modifyPoint.linkedRoadPointId = info.roadPointInfo.roadPointId;
  962. this.modifyPoint.x = info.roadPointInfo.x;
  963. this.modifyPoint.y = info.roadPointInfo.y;
  964. } else {
  965. this.modifyPoint.linkedCurveRoadPointId =
  966. info.curveRoadPointInfo.curveRoadPointId;
  967. this.modifyPoint.x = info.curveRoadPointInfo.x;
  968. this.modifyPoint.y = info.curveRoadPointInfo.y;
  969. }
  970. } else if (info.roadPointInfo.roadPointId) {
  971. this.modifyPoint.linkedRoadPointId = info.roadPointInfo.roadPointId;
  972. this.modifyPoint.x = info.roadPointInfo.x;
  973. this.modifyPoint.y = info.roadPointInfo.y;
  974. } else if (info.curveRoadPointInfo.curveRoadPointId) {
  975. this.modifyPoint.linkedCurveRoadPointId =
  976. info.curveRoadPointInfo.curveRoadPointId;
  977. this.modifyPoint.x = info.curveRoadPointInfo.x;
  978. this.modifyPoint.y = info.curveRoadPointInfo.y;
  979. }
  980. } else if (
  981. info &&
  982. (info.pointInfo.pointId || info.curvePointInfo.curvePointId)
  983. ) {
  984. this.modifyPoint = {};
  985. if (info.pointInfo.pointId && info.curvePointInfo.curvePointId) {
  986. if (info.pointInfo.distance < info.curvePointInfo.distance) {
  987. this.modifyPoint.linkedPointId = info.pointInfo.pointId;
  988. this.modifyPoint.x = info.pointInfo.x;
  989. this.modifyPoint.y = info.pointInfo.y;
  990. } else {
  991. this.modifyPoint.linkedCurvePointId =
  992. info.curvePointInfo.curvePointId;
  993. this.modifyPoint.x = info.curvePointInfo.x;
  994. this.modifyPoint.y = info.curvePointInfo.y;
  995. }
  996. } else if (info.pointInfo.pointId) {
  997. this.modifyPoint.linkedPointId = info.pointInfo.pointId;
  998. this.modifyPoint.x = info.pointInfo.x;
  999. this.modifyPoint.y = info.pointInfo.y;
  1000. } else if (info.curvePointInfo.curvePointId) {
  1001. this.modifyPoint.linkedCurvePointId = info.curvePointInfo.curvePointId;
  1002. this.modifyPoint.x = info.curvePointInfo.x;
  1003. this.modifyPoint.y = info.curvePointInfo.y;
  1004. }
  1005. } else if (
  1006. info &&
  1007. (info.roadEdgeInfo.roadId || info.curveRoadEdgeInfo.curveRoadId)
  1008. ) {
  1009. this.modifyPoint = {};
  1010. if (info.roadEdgeInfo.roadId && info.curveRoadEdgeInfo.curveRoadId) {
  1011. if (roadEdgeInfo.distance < info.curveRoadEdgeInfo.distance) {
  1012. this.modifyPoint.linkedRoadId = info.roadEdgeInfo.roadId;
  1013. this.modifyPoint.x = info.roadEdgeInfo.x;
  1014. this.modifyPoint.y = info.roadEdgeInfo.y;
  1015. } else {
  1016. this.modifyPoint.linkedCurveRoadId = curveRoadEdgeInfo.curveRoadId;
  1017. this.modifyPoint.x = info.curveRoadEdgeInfo.x;
  1018. this.modifyPoint.y = info.curveRoadEdgeInfo.y;
  1019. }
  1020. } else if (info.roadEdgeInfo.roadId) {
  1021. this.modifyPoint.linkedRoadId = info.roadEdgeInfo.roadId;
  1022. this.modifyPoint.x = info.roadEdgeInfo.x;
  1023. this.modifyPoint.y = info.roadEdgeInfo.y;
  1024. } else if (info.curveRoadEdgeInfo.curveRoadId) {
  1025. this.modifyPoint.linkedCurveRoadId = info.curveRoadEdgeInfo.curveRoadId;
  1026. this.modifyPoint.x = info.curveRoadEdgeInfo.x;
  1027. this.modifyPoint.y = info.curveRoadEdgeInfo.y;
  1028. }
  1029. } else if (info && info.crossPointInfo.crossCrossPointId) {
  1030. this.modifyPoint = {};
  1031. this.modifyPoint.linkedCrossCrossPointId =
  1032. info.crossPointInfo.crossCrossPointId;
  1033. this.modifyPoint.x = info.crossPointInfo.x;
  1034. this.modifyPoint.y = info.crossPointInfo.y;
  1035. } else if (info && info.textInfo.textId) {
  1036. this.modifyPoint = {};
  1037. this.modifyPoint.textId = info.textInfo.textId;
  1038. this.modifyPoint.x = info.textInfo.x;
  1039. this.modifyPoint.y = info.textInfo.y;
  1040. } else if (info && info.magnifierInfo.magnifierId) {
  1041. this.modifyPoint = {};
  1042. this.modifyPoint.magnifierId = info.magnifierInfo.magnifierId;
  1043. this.modifyPoint.x = info.magnifierInfo.x;
  1044. this.modifyPoint.y = info.magnifierInfo.y;
  1045. } else if (
  1046. info &&
  1047. (info.roadEdgeInfo.edgeId || info.curveRoadEdgeInfo.curveEdgeId)
  1048. ) {
  1049. this.modifyPoint = {};
  1050. if (info.roadEdgeInfo.edgeId && info.curveRoadEdgeInfo.curveEdgeId) {
  1051. if (info.roadEdgeInfo.distance < info.curveRoadEdgeInfo.distance) {
  1052. this.modifyPoint.linkedEdgeId = info.roadEdgeInfo.edgeId;
  1053. this.modifyPoint.x = info.roadEdgeInfo.x;
  1054. this.modifyPoint.y = info.roadEdgeInfo.y;
  1055. } else {
  1056. this.modifyPoint.linkedCurveEdgeId =
  1057. info.curveRoadEdgeInfo.curveEdgeId;
  1058. this.modifyPoint.selectIndex = info.curveRoadEdgeInfo.selectIndex;
  1059. this.modifyPoint.x = info.curveRoadEdgeInfo.x;
  1060. this.modifyPoint.y = info.curveRoadEdgeInfo.y;
  1061. }
  1062. } else if (info.roadEdgeInfo.edgeId) {
  1063. this.modifyPoint.linkedEdgeId = info.roadEdgeInfo.edgeId;
  1064. this.modifyPoint.x = info.roadEdgeInfo.x;
  1065. this.modifyPoint.y = info.roadEdgeInfo.y;
  1066. } else if (info.curveRoadEdgeInfo.curveEdgeId) {
  1067. this.modifyPoint.linkedCurveEdgeId = info.curveRoadEdgeInfo.curveEdgeId;
  1068. this.modifyPoint.selectIndex = info.curveRoadEdgeInfo.selectIndex;
  1069. this.modifyPoint.x = info.curveRoadEdgeInfo.x;
  1070. this.modifyPoint.y = info.curveRoadEdgeInfo.y;
  1071. }
  1072. } else if (
  1073. info &&
  1074. (info.lineInfo.lineId || info.curveLineInfo.curveLineId)
  1075. ) {
  1076. this.modifyPoint = {};
  1077. if (info.lineInfo.lineId && info.curveLineInfo.curveLineId) {
  1078. if (info.lineInfo.distance < info.curveLineInfo.distance) {
  1079. this.modifyPoint.linkedLineId = info.lineInfo.lineId;
  1080. this.modifyPoint.x = info.lineInfo.x;
  1081. this.modifyPoint.y = info.lineInfo.y;
  1082. } else {
  1083. this.modifyPoint.linkedCurveLineId = info.curveLineInfo.curveLineId;
  1084. this.modifyPoint.x = info.curveLineInfo.x;
  1085. this.modifyPoint.y = info.curveLineInfo.y;
  1086. }
  1087. } else if (info.lineInfo.lineId) {
  1088. this.modifyPoint.linkedLineId = info.lineInfo.lineId;
  1089. this.modifyPoint.x = info.lineInfo.x;
  1090. this.modifyPoint.y = info.lineInfo.y;
  1091. } else if (info.curveLineInfo.curveLineId) {
  1092. this.modifyPoint.linkedCurveLineId = info.curveLineInfo.curveLineId;
  1093. this.modifyPoint.x = info.curveLineInfo.x;
  1094. this.modifyPoint.y = info.curveLineInfo.y;
  1095. }
  1096. } else if (info && info.circleInfo.circleId) {
  1097. this.modifyPoint = {};
  1098. this.modifyPoint.linkedCircleId = info.circleInfo.circleId;
  1099. this.modifyPoint.index = info.circleInfo.index;
  1100. this.modifyPoint.x = info.circleInfo.x;
  1101. this.modifyPoint.y = info.circleInfo.y;
  1102. } else if (info && info.roadPointInfo.linkedRoadPointIdX) {
  1103. this.modifyPoint = {};
  1104. this.modifyPoint.linkedRoadPointIdX =
  1105. info.roadPointInfo.linkedRoadPointIdX;
  1106. this.modifyPoint.x = info.roadPointInfo.x;
  1107. this.modifyPoint.y = info.roadPointInfo.y;
  1108. } else if (info && info.roadPointInfo.linkedRoadPointIdY) {
  1109. this.modifyPoint = {};
  1110. this.modifyPoint.linkedRoadPointIdY =
  1111. info.roadPointInfo.linkedRoadPointIdY;
  1112. this.modifyPoint.y = info.roadPointInfo.y;
  1113. this.modifyPoint.x = info.roadPointInfo.x;
  1114. } else if (info && info.curvePointInfo.linkedRoadPointIdX) {
  1115. this.modifyPoint = {};
  1116. this.modifyPoint.linkedRoadPointIdX =
  1117. info.curvePointInfo.linkedRoadPointIdX;
  1118. this.modifyPoint.x = info.curvePointInfo.x;
  1119. this.modifyPoint.y = position.y;
  1120. } else if (info && info.curvePointInfo.linkedRoadPointIdY) {
  1121. this.modifyPoint = {};
  1122. this.modifyPoint.linkedRoadPointIdY =
  1123. info.curvePointInfo.linkedRoadPointIdY;
  1124. this.modifyPoint.y = info.curvePointInfo.y;
  1125. this.modifyPoint.x = position.x;
  1126. } else if (
  1127. info &&
  1128. info.pointInfo.linkedPointIdX &&
  1129. !info.pointInfo.linkedPointIdY
  1130. ) {
  1131. this.modifyPoint = {};
  1132. this.modifyPoint.linkedPointIdX = info.pointInfo.linkedPointIdX;
  1133. this.modifyPoint.x = info.pointInfo.x;
  1134. this.modifyPoint.y = info.pointInfo.y;
  1135. } else if (
  1136. info &&
  1137. info.pointInfo.linkedPointIdY &&
  1138. !info.pointInfo.linkedPointIdX
  1139. ) {
  1140. this.modifyPoint = {};
  1141. this.modifyPoint.linkedPointIdY = info.pointInfo.linkedPointIdY;
  1142. this.modifyPoint.y = info.pointInfo.y;
  1143. this.modifyPoint.x = info.pointInfo.x;
  1144. } else if (
  1145. info &&
  1146. info.pointInfo.linkedPointIdY &&
  1147. info.pointInfo.linkedPointIdX
  1148. ) {
  1149. this.modifyPoint = {};
  1150. this.modifyPoint.linkedPointIdX = info.pointInfo.linkedPointIdX;
  1151. this.modifyPoint.linkedPointIdY = info.pointInfo.linkedPointIdY;
  1152. this.modifyPoint.y = info.pointInfo.y;
  1153. this.modifyPoint.x = info.pointInfo.x;
  1154. } else if (info && info.svgInfo.svgId) {
  1155. this.modifyPoint = {};
  1156. this.modifyPoint.svgId = info.svgInfo.svgId;
  1157. this.modifyPoint.index = info.svgInfo.index;
  1158. } else {
  1159. this.modifyPoint = null;
  1160. }
  1161. }
  1162. updateSelectItem() {
  1163. let selectItem = stateService.getSelectItem();
  1164. if (this.modifyPoint == null) {
  1165. if (selectItem != null) {
  1166. stateService.clearSelectItem();
  1167. return true;
  1168. } else {
  1169. return false;
  1170. }
  1171. } else if (this.modifyPoint.linkedRoadPointId) {
  1172. stateService.setSelectItem(
  1173. this.modifyPoint.linkedRoadPointId,
  1174. VectorType.RoadPoint,
  1175. SelectState.Select
  1176. );
  1177. } else if (this.modifyPoint.linkedCurveRoadPointId) {
  1178. stateService.setSelectItem(
  1179. this.modifyPoint.linkedCurveRoadPointId,
  1180. VectorType.CurveRoadPoint,
  1181. SelectState.Select
  1182. );
  1183. } else if (this.modifyPoint.linkedRoadId) {
  1184. stateService.setSelectItem(
  1185. this.modifyPoint.linkedRoadId,
  1186. VectorType.Road,
  1187. SelectState.Select
  1188. );
  1189. } else if (this.modifyPoint.linkedCurveRoadId) {
  1190. stateService.setSelectItem(
  1191. this.modifyPoint.linkedCurveRoadId,
  1192. VectorType.CurveRoad,
  1193. SelectState.Select
  1194. );
  1195. } else if (this.modifyPoint.linkedCrossCrossPointId) {
  1196. stateService.setSelectItem(
  1197. this.modifyPoint.linkedCrossCrossPointId,
  1198. VectorType.CrossPoint,
  1199. SelectState.Select
  1200. );
  1201. } else if (this.modifyPoint.textId) {
  1202. stateService.setSelectItem(
  1203. this.modifyPoint.textId,
  1204. VectorType.Text,
  1205. SelectState.Select
  1206. );
  1207. } else if (this.modifyPoint.svgId) {
  1208. stateService.setSelectItem(
  1209. this.modifyPoint.svgId,
  1210. VectorType.SVG,
  1211. this.modifyPoint.index
  1212. );
  1213. } else if (this.modifyPoint.magnifierId) {
  1214. stateService.setSelectItem(
  1215. this.modifyPoint.magnifierId,
  1216. VectorType.Magnifier,
  1217. SelectState.Select
  1218. );
  1219. } else if (this.modifyPoint.linkedEdgeId) {
  1220. stateService.setSelectItem(
  1221. this.modifyPoint.linkedEdgeId,
  1222. VectorType.RoadEdge,
  1223. SelectState.Select
  1224. );
  1225. } else if (this.modifyPoint.linkedCurveEdgeId) {
  1226. stateService.setSelectItem(
  1227. this.modifyPoint.linkedCurveEdgeId,
  1228. VectorType.CurveRoadEdge,
  1229. SelectState.Select
  1230. );
  1231. } else if (this.modifyPoint.linkedPointId) {
  1232. stateService.setSelectItem(
  1233. this.modifyPoint.linkedPointId,
  1234. VectorType.Point,
  1235. SelectState.Select
  1236. );
  1237. } else if (this.modifyPoint.linkedCurvePointId) {
  1238. stateService.setSelectItem(
  1239. this.modifyPoint.linkedCurvePointId,
  1240. VectorType.CurvePoint,
  1241. SelectState.Select
  1242. );
  1243. } else if (this.modifyPoint.linkedLineId) {
  1244. stateService.setSelectItem(
  1245. this.modifyPoint.linkedLineId,
  1246. VectorType.Line,
  1247. SelectState.Select
  1248. );
  1249. } else if (this.modifyPoint.linkedCurveLineId) {
  1250. stateService.setSelectItem(
  1251. this.modifyPoint.linkedCurveLineId,
  1252. VectorType.CurveLine,
  1253. SelectState.Select
  1254. );
  1255. } else if (this.modifyPoint.linkedCircleId) {
  1256. stateService.setSelectItem(
  1257. this.modifyPoint.linkedCircleId,
  1258. VectorType.Circle,
  1259. this.modifyPoint.index
  1260. );
  1261. } else {
  1262. stateService.clearSelectItem();
  1263. }
  1264. let newSelectItem = stateService.getSelectItem();
  1265. if (selectItem == null && newSelectItem == null) {
  1266. return false;
  1267. } else if (selectItem == null && newSelectItem != null) {
  1268. return true;
  1269. } else if (selectItem != null && newSelectItem == null) {
  1270. return true;
  1271. } else if (selectItem.vectorId == newSelectItem.vectorId) {
  1272. return false;
  1273. } else {
  1274. return true;
  1275. }
  1276. }
  1277. distanceForBezier(position, curves, width) {
  1278. return mathUtil.getHitInfoForCurves(position, curves, width);
  1279. }
  1280. equalAndClone(info1, info2) {
  1281. let flag = true;
  1282. for (let key in info1) {
  1283. if (info1[key] != info2[key]) {
  1284. flag = false;
  1285. }
  1286. info1[key] = info2[key];
  1287. }
  1288. return flag;
  1289. }
  1290. getDistance(start, end) {
  1291. return (
  1292. (mathUtil.getDistance(start, end) * coordinate.zoom) /
  1293. coordinate.defaultZoom
  1294. );
  1295. }
  1296. clear() {
  1297. this.modifyPoint = null;
  1298. }
  1299. }
  1300. const listenLayer = new ListenLayer();
  1301. export { listenLayer };