ListenLayer.js 24 KB

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