ListenLayer.js 36 KB

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