ListenLayer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. export default class ListenLayer {
  9. constructor() {
  10. this.roadInfo = {
  11. roadId: null,
  12. type: null,
  13. state: null, // 未选中null
  14. };
  15. this.pointInfo = {
  16. pointId: null,
  17. type: null,
  18. state: null,
  19. };
  20. this.tagInfo = {
  21. tagId: null,
  22. state: null,
  23. };
  24. this.modifyPoint = null;
  25. }
  26. //开始监听,exceptPointId表示不考虑的点,exceptRoadIds表示不考虑的墙
  27. start(position, exceptPointId, exceptRoadIds, exceptCurveRoadId) {
  28. let nearest = this.getNearForVectors(
  29. position,
  30. exceptPointId,
  31. exceptRoadIds,
  32. exceptCurveRoadId
  33. );
  34. if (
  35. nearest.modifyPoint &&
  36. (nearest.modifyPoint.hasOwnProperty("linkedPointId") ||
  37. nearest.modifyPoint.hasOwnProperty("linkedPointIdX") ||
  38. nearest.modifyPoint.hasOwnProperty("linkedPointIdY") ||
  39. nearest.modifyPoint.hasOwnProperty("linkedRoadId"))
  40. ) {
  41. this.modifyPoint = {
  42. x: nearest.modifyPoint.x,
  43. y: nearest.modifyPoint.y,
  44. };
  45. if (
  46. nearest.modifyPoint.hasOwnProperty("linkedPointId") &&
  47. nearest.modifyPoint.linkedPointId != null
  48. ) {
  49. this.modifyPoint.linkedPointId = nearest.modifyPoint.linkedPointId;
  50. } else if (
  51. nearest.modifyPoint.hasOwnProperty("linkedRoadId") &&
  52. nearest.modifyPoint.linkedRoadId != null
  53. ) {
  54. this.modifyPoint.linkedRoadId = nearest.modifyPoint.linkedRoadId;
  55. } else {
  56. if (
  57. nearest.modifyPoint.hasOwnProperty("linkedPointIdX") &&
  58. nearest.modifyPoint.linkedPointIdX != null
  59. ) {
  60. this.modifyPoint.linkedPointIdX = nearest.modifyPoint.linkedPointIdX;
  61. }
  62. if (
  63. nearest.modifyPoint.hasOwnProperty("linkedPointIdY") &&
  64. nearest.modifyPoint.linkedPointIdY != null
  65. ) {
  66. this.modifyPoint.linkedPointIdY = nearest.modifyPoint.linkedPointIdY;
  67. }
  68. }
  69. } else {
  70. this.modifyPoint = null;
  71. }
  72. const flag = this.updateSelectInfos(nearest, Constant.minAdsorbPix);
  73. this.updateSelectItem();
  74. return flag;
  75. }
  76. // 获得最近的墙面和墙角
  77. // 同时获得吸附的相关信息
  78. // 找到选中的symbol(只有选中了,才算是最近的)
  79. getNearForVectors(position, exceptPointId, exceptRoadIds, exceptCurveRoadId) {
  80. let info1 = this.getNearForRoad(position, exceptPointId, exceptRoadIds);
  81. let info2 = this.getNearForCurveRoad(
  82. position,
  83. exceptPointId,
  84. exceptCurveRoadId
  85. );
  86. let min1 = info1.min1;
  87. let modifyPoint = info1.modifyPoint;
  88. let _modifyPoint = info1._modifyPoint;
  89. if (min1 == null && info2.min1 != null) {
  90. min1 = info2.min1;
  91. modifyPoint = info2.modifyPoint;
  92. _modifyPoint = info2._modifyPoint;
  93. } else if (info2.min1 != null) {
  94. if (info1.min1.distance > info2.min1.distance) {
  95. min1 = info2.min1;
  96. modifyPoint = info2.modifyPoint;
  97. _modifyPoint = info2._modifyPoint;
  98. }
  99. }
  100. let min2 = info1.min2;
  101. if (min2 == null && info2.min2 != null) {
  102. min2 = info2.min2;
  103. modifyPoint = info2.modifyPoint;
  104. _modifyPoint = info2._modifyPoint;
  105. } else if (info2.min2 != null) {
  106. if (info1.min2.distance > info2.min2.distance) {
  107. min2 = info2.min2;
  108. modifyPoint = info2.modifyPoint;
  109. _modifyPoint = info2._modifyPoint;
  110. }
  111. }
  112. const result = {
  113. minPoint: min1,
  114. minRoad: min2,
  115. tagInfo: {},
  116. };
  117. if (_modifyPoint != null) {
  118. result.modifyPoint = JSON.parse(JSON.stringify(_modifyPoint));
  119. } else if (
  120. modifyPoint.hasOwnProperty("x") &&
  121. modifyPoint.hasOwnProperty("y")
  122. ) {
  123. result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  124. } else if (modifyPoint.hasOwnProperty("x")) {
  125. result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  126. result.modifyPoint.x = modifyPoint.x;
  127. result.modifyPoint.y = position.y;
  128. } else if (modifyPoint.hasOwnProperty("y")) {
  129. result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  130. result.modifyPoint.x = position.x;
  131. result.modifyPoint.y = modifyPoint.y;
  132. }
  133. return result;
  134. }
  135. getNearForRoad(position, exceptPointId, exceptRoadIds) {
  136. let min1 = null; // 与墙角的距离
  137. let min2 = null; // 与墙面的距离
  138. // 纠正
  139. // 垂直,水平
  140. const modifyPoint = {};
  141. // 吸附在墙面上
  142. let _modifyPoint = null;
  143. const hasPointIds = [];
  144. if (exceptPointId) {
  145. hasPointIds.push(exceptPointId);
  146. }
  147. const roads = dataService.getRoads();
  148. for (const roadId in roads) {
  149. if (exceptRoadIds && exceptRoadIds.hasOwnProperty(roadId)) {
  150. continue;
  151. }
  152. const road = dataService.getRoad(roadId);
  153. const startPoint = dataService.getPoint(road.startId);
  154. const endPoint = dataService.getPoint(road.endId);
  155. let distance = null;
  156. const line = roadService.getMidLine(road);
  157. //垂直交点
  158. const join = mathUtil.getJoinLinePoint(position, line);
  159. //先找端点
  160. if (hasPointIds.indexOf(road.startId) == -1) {
  161. hasPointIds.push(road.startId);
  162. distance = mathUtil.getDistance(position, startPoint);
  163. if (min1 == null || min1.distance > distance) {
  164. min1 = {
  165. distance: distance,
  166. pointId: road.startId,
  167. type: VectorType.RoadCorner,
  168. };
  169. //在公路内了
  170. if (
  171. (mathUtil.getDistance(join, position) < road.width / 2 &&
  172. mathUtil.getDistance(join, startPoint) < road.width / 2) ||
  173. min1.distance < road.width / 2
  174. ) {
  175. modifyPoint.linkedPointId = road.startId;
  176. modifyPoint.x = startPoint.x;
  177. modifyPoint.y = startPoint.y;
  178. delete modifyPoint.linkedPointIdX;
  179. delete modifyPoint.linkedPointIdY;
  180. break;
  181. }
  182. }
  183. //start部分找到了与x接近的其他点
  184. if (Math.abs(position.x - startPoint.x) < Constant.minAdsorbPix) {
  185. if (!modifyPoint.linkedPointIdX) {
  186. modifyPoint.x = startPoint.x;
  187. modifyPoint.linkedPointIdX = road.startId;
  188. } else {
  189. const linkedPointX = dataService.getPoint(
  190. modifyPoint.linkedPointIdX
  191. );
  192. if (
  193. mathUtil.getDistance(position, linkedPointX) >
  194. mathUtil.getDistance(position, startPoint)
  195. ) {
  196. modifyPoint.x = startPoint.x;
  197. modifyPoint.linkedPointIdX = road.startId;
  198. }
  199. }
  200. }
  201. //start部分找到了与y接近的其他点
  202. if (Math.abs(position.y - startPoint.y) < Constant.minAdsorbPix) {
  203. if (!modifyPoint.linkedPointIdY) {
  204. modifyPoint.y = startPoint.y;
  205. modifyPoint.linkedPointIdY = road.startId;
  206. } else {
  207. const linkedPointY = dataService.getPoint(
  208. modifyPoint.linkedPointIdY
  209. );
  210. if (
  211. mathUtil.getDistance(position, linkedPointY) >
  212. mathUtil.getDistance(position, startPoint)
  213. ) {
  214. modifyPoint.y = startPoint.y;
  215. modifyPoint.linkedPointIdY = road.startId;
  216. }
  217. }
  218. }
  219. }
  220. if (hasPointIds.indexOf(road.endId) == -1) {
  221. hasPointIds.push(road.endId);
  222. distance = mathUtil.getDistance(position, endPoint);
  223. if (min1 == null || min1.distance > distance) {
  224. min1 = {
  225. distance: distance,
  226. pointId: road.endId,
  227. type: VectorType.RoadCorner,
  228. };
  229. //end部分找到了墙的端点
  230. if (
  231. (mathUtil.getDistance(join, position) < road.width / 2 &&
  232. mathUtil.getDistance(join, endPoint) < road.width / 2) ||
  233. min1.distance < road.width / 2
  234. ) {
  235. modifyPoint.linkedPointId = road.endId;
  236. modifyPoint.x = endPoint.x;
  237. modifyPoint.y = endPoint.y;
  238. delete modifyPoint.linkedPointIdX;
  239. delete modifyPoint.linkedPointIdY;
  240. break;
  241. }
  242. }
  243. //end部分找到了与x接近的其他点
  244. if (Math.abs(position.x - endPoint.x) < Constant.minAdsorbPix) {
  245. if (!modifyPoint.linkedPointIdX) {
  246. modifyPoint.x = endPoint.x;
  247. modifyPoint.linkedPointIdX = road.endId;
  248. } else {
  249. const linkedPointX = dataService.getPoint(
  250. modifyPoint.linkedPointIdX
  251. );
  252. if (
  253. mathUtil.getDistance(position, linkedPointX) >
  254. mathUtil.getDistance(position, endPoint)
  255. ) {
  256. modifyPoint.x = endPoint.x;
  257. modifyPoint.linkedPointIdX = road.endId;
  258. }
  259. }
  260. }
  261. //end部分找到了与y接近的其他点
  262. if (Math.abs(position.y - endPoint.y) < Constant.minAdsorbPix) {
  263. if (!modifyPoint.linkedPointIdY) {
  264. modifyPoint.y = endPoint.y;
  265. modifyPoint.linkedPointIdY = road.endId;
  266. } else {
  267. const linkedPointY = dataService.getPoint(
  268. modifyPoint.linkedPointIdY
  269. );
  270. if (
  271. mathUtil.getDistance(position, linkedPointY) >
  272. mathUtil.getDistance(position, endPoint)
  273. ) {
  274. modifyPoint.y = endPoint.y;
  275. modifyPoint.linkedPointIdY = road.endId;
  276. }
  277. }
  278. }
  279. }
  280. distance = mathUtil.getDistance(position, join);
  281. //是否在墙上,可能在墙外
  282. const _flag = roadService.isContain(road, join);
  283. if (_flag && (min2 == null || min2.distance > distance)) {
  284. min2 = {
  285. distance: distance,
  286. type: VectorType.Road,
  287. roadId: roadId,
  288. };
  289. }
  290. if (_flag && mathUtil.getDistance(position, join) < road.width / 2) {
  291. _modifyPoint = join;
  292. _modifyPoint.linkedRoadId = roadId;
  293. }
  294. }
  295. return {
  296. min1: min1,
  297. min2: min2,
  298. modifyPoint: modifyPoint,
  299. _modifyPoint: _modifyPoint,
  300. };
  301. }
  302. //暂时只考虑端点
  303. getNearForCurveRoad(position, exceptPointId, exceptCurveRoadId) {
  304. let min1 = null; // 与墙角的距离
  305. let min2 = null; // 与墙面的距离
  306. // 纠正
  307. // 垂直,水平
  308. const modifyPoint = {};
  309. // 吸附在墙面上
  310. let _modifyPoint = null;
  311. const hasPointIds = [];
  312. if (exceptPointId) {
  313. hasPointIds.push(exceptPointId);
  314. }
  315. const curveRoads = dataService.getCurveRoads();
  316. for (const curveRoadId in curveRoads) {
  317. if (exceptCurveRoadId && exceptCurveRoadId == curveRoadId) {
  318. continue;
  319. }
  320. const curveRoad = dataService.getCurveRoad(curveRoadId);
  321. for (let i = 0; i < curveRoad.points.length; ++i) {
  322. let distance = null;
  323. //先找端点
  324. if (hasPointIds.indexOf(curveRoad.points[i].vectorId) == -1) {
  325. hasPointIds.push(curveRoad.points[i].vectorId);
  326. distance = mathUtil.getDistance(position, curveRoad.points[i]);
  327. if (distance < Constant.minAdsorbPix) {
  328. min1 = {
  329. distance: distance,
  330. pointId: curveRoad.points[i].vectorId,
  331. type: VectorType.CurveRoadCorner,
  332. };
  333. modifyPoint.linkedPointId = curveRoad.points[i].vectorId;
  334. modifyPoint.x = curveRoad.points[i].x;
  335. modifyPoint.y = curveRoad.points[i].y;
  336. delete modifyPoint.linkedPointIdX;
  337. delete modifyPoint.linkedPointIdY;
  338. break;
  339. }
  340. //start部分找到了与x接近的其他点
  341. if (
  342. Math.abs(position.x - curveRoad.points[i].x) < Constant.minAdsorbPix
  343. ) {
  344. if (!modifyPoint.linkedPointIdX) {
  345. modifyPoint.x = curveRoad.points[i].x;
  346. modifyPoint.linkedPointIdX = curveRoad.points[i].vectorId;
  347. } else {
  348. const linkedPointX = dataService.getCurvePoint(
  349. modifyPoint.linkedPointIdX
  350. );
  351. if (
  352. mathUtil.getDistance(position, linkedPointX) >
  353. mathUtil.getDistance(position, curveRoad.points[i])
  354. ) {
  355. modifyPoint.x = curveRoad.points[i].x;
  356. modifyPoint.linkedPointIdX = curveRoad.points[i].vectorId;
  357. }
  358. }
  359. }
  360. //start部分找到了与y接近的其他点
  361. if (
  362. Math.abs(position.y - curveRoad.points[i].y) < Constant.minAdsorbPix
  363. ) {
  364. if (!modifyPoint.linkedPointIdY) {
  365. modifyPoint.y = curveRoad.points[i].y;
  366. modifyPoint.linkedPointIdY = curveRoad.points[i].vectorId;
  367. } else {
  368. const linkedPointY = dataService.getCurvePoint(
  369. modifyPoint.linkedPointIdY
  370. );
  371. if (
  372. mathUtil.getDistance(position, linkedPointY) >
  373. mathUtil.getDistance(position, curveRoad.points[i])
  374. ) {
  375. modifyPoint.y = curveRoad.points[i].y;
  376. modifyPoint.linkedPointIdY = curveRoad.points[i].vectorId;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. return {
  384. min1: min1,
  385. min2: min2,
  386. modifyPoint: modifyPoint,
  387. _modifyPoint: _modifyPoint,
  388. };
  389. }
  390. updateSelectInfos(nearest, minDistance) {
  391. console.log("实时监控:" + JSON.stringify(nearest));
  392. // 墙角状态是否改变
  393. let flag1 = false;
  394. if (nearest.minPoint != null) {
  395. if (nearest.minPoint.distance < minDistance) {
  396. flag1 = this.isChanged(nearest.minPoint.pointId, SelectState.Select, 1);
  397. this.pointInfo = {
  398. pointId: nearest.minPoint.pointId,
  399. type: nearest.minPoint.type,
  400. state: SelectState.Select,
  401. };
  402. } else {
  403. flag1 = this.isChanged(nearest.minPoint.pointId, null, 1);
  404. this.pointInfo = {
  405. pointId: nearest.minPoint.pointId,
  406. type: nearest.minPoint.type,
  407. state: null,
  408. };
  409. }
  410. } else {
  411. flag1 = this.isChanged(null, null, 1);
  412. this.pointInfo = {
  413. pointId: null,
  414. type: null,
  415. state: null,
  416. };
  417. }
  418. // 墙面状态是否改变
  419. let flag2 = false;
  420. if (nearest.minRoad != null) {
  421. if (nearest.minRoad.distance < minDistance) {
  422. flag2 = this.isChanged(nearest.minRoad.roadId, SelectState.Select, 2);
  423. this.roadInfo = {
  424. roadId: nearest.minRoad.roadId,
  425. type: nearest.minRoad.type,
  426. state: SelectState.Select,
  427. };
  428. } else {
  429. flag2 = this.isChanged(nearest.minRoad.roadId, null, 2);
  430. this.roadInfo = {
  431. roadId: nearest.minRoad.roadId,
  432. type: nearest.minRoad.type,
  433. state: null,
  434. };
  435. }
  436. } else {
  437. flag2 = this.isChanged(null, null, 2);
  438. this.roadInfo = {
  439. roadId: null,
  440. type: null,
  441. state: null,
  442. };
  443. }
  444. return flag1 || flag2;
  445. }
  446. // type是1表示点,2表示墙,3表示symbol,4表示component, 5表示tag,6表示furniture
  447. isChanged(vectorId, state, type) {
  448. let flag = false;
  449. if (type == 1) {
  450. if (state == null && state == this.pointInfo.state) {
  451. flag = false;
  452. } else if (
  453. this.pointInfo.pointId == vectorId &&
  454. state == this.pointInfo.state
  455. ) {
  456. flag = false;
  457. } else {
  458. flag = true;
  459. }
  460. } else if (type == 2) {
  461. if (state == null && state == this.roadInfo.state) {
  462. flag = false;
  463. } else if (
  464. this.roadInfo.roadId == vectorId &&
  465. state == this.roadInfo.state
  466. ) {
  467. flag = false;
  468. } else {
  469. flag = true;
  470. }
  471. } else if (type == 5) {
  472. if (state == null && state == this.tagInfo.state) {
  473. flag = false;
  474. } else if (
  475. this.tagInfo.tagId == vectorId &&
  476. state == this.tagInfo.state
  477. ) {
  478. flag = false;
  479. } else {
  480. flag = true;
  481. }
  482. }
  483. return flag;
  484. }
  485. updateSelectItem() {
  486. if (this.tagInfo.tagId != null && this.tagInfo.state != null) {
  487. const tag = dataService.getTag(this.tagInfo.tagId);
  488. stateService.setSelectItem(
  489. this.tagInfo.tagId,
  490. tag.geoType,
  491. this.tagInfo.state
  492. );
  493. } else if (this.pointInfo.pointId != null && this.pointInfo.state != null) {
  494. stateService.setSelectItem(
  495. this.pointInfo.pointId,
  496. this.pointInfo.type,
  497. SelectState.Select
  498. );
  499. } else if (this.roadInfo.roadId != null && this.roadInfo.state != null) {
  500. stateService.setSelectItem(
  501. this.roadInfo.roadId,
  502. this.roadInfo.type,
  503. SelectState.Select
  504. );
  505. } else {
  506. stateService.clearSelectItem();
  507. }
  508. }
  509. // getNearForCurveRoad(position, exceptPointId, exceptRoadIds) {
  510. // let min1 = null;
  511. // let min2 = null;
  512. // const modifyPoint = {};
  513. // const hasPointIds = [];
  514. // if (exceptPointId) {
  515. // hasPointIds.push(exceptPointId);
  516. // }
  517. // const curveRoads = dataService.getCurveRoads();
  518. // for (const curveRoadId in curveRoads) {
  519. // if (exceptRoadIds && exceptRoadIds.hasOwnProperty(curveRoadId)) {
  520. // continue;
  521. // }
  522. // const curveRoad = dataService.getCurveRoad(curveRoadId);
  523. // const startPoint = dataService.getPoint(curveRoad.startId);
  524. // const endPoint = dataService.getPoint(curveRoad.endId);
  525. // let distance = null;
  526. // //先找端点
  527. // if (hasPointIds.indexOf(curveRoad.startId) == -1) {
  528. // hasPointIds.push(curveRoad.startId);
  529. // distance = mathUtil.getDistance(position, startPoint);
  530. // if (min1 == null || min1.distance > distance) {
  531. // min1 = {
  532. // distance: distance,
  533. // pointId: curveRoad.startId,
  534. // };
  535. // if (min1.distance < Constant.minAdsorbPix) {
  536. // modifyPoint.linkedPointId = curveRoad.startId;
  537. // modifyPoint.x = startPoint.x;
  538. // modifyPoint.y = startPoint.y;
  539. // delete modifyPoint.linkedPointIdX;
  540. // delete modifyPoint.linkedPointIdY;
  541. // break;
  542. // }
  543. // }
  544. // //start部分找到了与x接近的其他点
  545. // if (Math.abs(position.x - startPoint.x) < Constant.minAdsorbPix) {
  546. // if (!modifyPoint.linkedPointIdX) {
  547. // modifyPoint.x = startPoint.x;
  548. // modifyPoint.linkedPointIdX = curveRoad.startId;
  549. // } else {
  550. // const linkedPointX = dataService.getPoint(
  551. // modifyPoint.linkedPointIdX
  552. // );
  553. // if (
  554. // mathUtil.getDistance(position, linkedPointX) >
  555. // mathUtil.getDistance(position, startPoint)
  556. // ) {
  557. // modifyPoint.x = startPoint.x;
  558. // modifyPoint.linkedPointIdX = curveRoad.startId;
  559. // }
  560. // }
  561. // }
  562. // //start部分找到了与y接近的其他点
  563. // if (Math.abs(position.y - startPoint.y) < Constant.minAdsorbPix) {
  564. // if (!modifyPoint.linkedPointIdY) {
  565. // modifyPoint.y = startPoint.y;
  566. // modifyPoint.linkedPointIdY = curveRoad.startId;
  567. // } else {
  568. // const linkedPointY = dataService.getPoint(
  569. // modifyPoint.linkedPointIdY
  570. // );
  571. // if (
  572. // mathUtil.getDistance(position, linkedPointY) >
  573. // mathUtil.getDistance(position, startPoint)
  574. // ) {
  575. // modifyPoint.y = startPoint.y;
  576. // modifyPoint.linkedPointIdY = curveRoad.startId;
  577. // }
  578. // }
  579. // }
  580. // }
  581. // if (hasPointIds.indexOf(curveRoad.endId) == -1) {
  582. // hasPointIds.push(curveRoad.endId);
  583. // distance = mathUtil.getDistance(position, endPoint);
  584. // if (min1 == null || min1.distance > distance) {
  585. // min1 = {
  586. // distance: distance,
  587. // pointId: curveRoad.endId,
  588. // };
  589. // //end部分找到了墙的端点
  590. // if (min1.distance < Constant.minAdsorbPix) {
  591. // modifyPoint.linkedPointId = curveRoad.endId;
  592. // modifyPoint.x = endPoint.x;
  593. // modifyPoint.y = endPoint.y;
  594. // delete modifyPoint.linkedPointIdX;
  595. // delete modifyPoint.linkedPointIdY;
  596. // break;
  597. // }
  598. // }
  599. // //end部分找到了与x接近的其他点
  600. // if (Math.abs(position.x - endPoint.x) < Constant.minAdsorbPix) {
  601. // if (!modifyPoint.linkedPointIdX) {
  602. // modifyPoint.x = endPoint.x;
  603. // modifyPoint.linkedPointIdX = curveRoad.endId;
  604. // } else {
  605. // const linkedPointX = dataService.getPoint(
  606. // modifyPoint.linkedPointIdX
  607. // );
  608. // if (
  609. // mathUtil.getDistance(position, linkedPointX) >
  610. // mathUtil.getDistance(position, endPoint)
  611. // ) {
  612. // modifyPoint.x = endPoint.x;
  613. // modifyPoint.linkedPointIdX = curveRoad.endId;
  614. // }
  615. // }
  616. // }
  617. // //end部分找到了与y接近的其他点
  618. // if (Math.abs(position.y - endPoint.y) < Constant.minAdsorbPix) {
  619. // if (!modifyPoint.linkedPointIdY) {
  620. // modifyPoint.y = endPoint.y;
  621. // modifyPoint.linkedPointIdY = curveRoad.endId;
  622. // } else {
  623. // const linkedPointY = dataService.getPoint(
  624. // modifyPoint.linkedPointIdY
  625. // );
  626. // if (
  627. // mathUtil.getDistance(position, linkedPointY) >
  628. // mathUtil.getDistance(position, endPoint)
  629. // ) {
  630. // modifyPoint.y = endPoint.y;
  631. // modifyPoint.linkedPointIdY = curveRoad.endId;
  632. // }
  633. // }
  634. // }
  635. // }
  636. // }
  637. // const result = {
  638. // minPoint: min1,
  639. // tagInfo: {},
  640. // };
  641. // if (modifyPoint.hasOwnProperty("x") && modifyPoint.hasOwnProperty("y")) {
  642. // result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  643. // } else if (modifyPoint.hasOwnProperty("x")) {
  644. // result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  645. // result.modifyPoint.x = modifyPoint.x;
  646. // result.modifyPoint.y = position.y;
  647. // } else if (modifyPoint.hasOwnProperty("y")) {
  648. // result.modifyPoint = JSON.parse(JSON.stringify(modifyPoint));
  649. // result.modifyPoint.x = position.x;
  650. // result.modifyPoint.y = modifyPoint.y;
  651. // }
  652. // return result;
  653. // }
  654. clear() {
  655. this.roadInfo = {
  656. roadId: null,
  657. state: null,
  658. type: null,
  659. };
  660. this.pointInfo = {
  661. pointId: null,
  662. state: null,
  663. type: null,
  664. };
  665. this.modifyPoint = null;
  666. }
  667. }
  668. const listenLayer = new ListenLayer();
  669. export { listenLayer };