Change.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. import { dataService } from "../Service/DataService";
  2. import { roadService } from "../Service/RoadService";
  3. import { historyUtil } from "./HistoryUtil";
  4. import HistoryEvents from "../enum/HistoryEvents";
  5. import { coordinate } from "../Coordinate";
  6. import { mathUtil } from "../Util/MathUtil";
  7. import Settings from "../Settings";
  8. export default class Change {
  9. constructor() {
  10. this.lastData = {}; // 每次都是当前数据和lastData进行比较,一般在mouseDown的时候存储进来
  11. this.currentData = {}; // 当前的变化
  12. }
  13. // 保存当前记录
  14. saveCurrentInfo() {
  15. // this.lastData.roadPoints = JSON.parse(
  16. // JSON.stringify(dataService.getRoadPoints())
  17. // );
  18. //this.lastData.roads = JSON.parse(JSON.stringify(dataService.getRoads()));
  19. this.lastData.lines = JSON.parse(JSON.stringify(dataService.getLines()));
  20. this.lastData.texts = JSON.parse(JSON.stringify(dataService.getTexts()));
  21. this.lastData.points = JSON.parse(JSON.stringify(dataService.getPoints()));
  22. this.lastData.curveLines = JSON.parse(
  23. JSON.stringify(dataService.getCurveLines())
  24. );
  25. this.lastData.curvePoints = JSON.parse(
  26. JSON.stringify(dataService.getCurvePoints())
  27. );
  28. this.lastData.circles = JSON.parse(
  29. JSON.stringify(dataService.getCircles())
  30. );
  31. this.lastData.magnifiers = JSON.parse(
  32. JSON.stringify(dataService.getMagnifiers())
  33. );
  34. this.lastData.svgs = JSON.parse(JSON.stringify(dataService.getSVGs()));
  35. this.lastData.roadPoints = JSON.parse(
  36. JSON.stringify(dataService.getRoadPoints())
  37. );
  38. this.lastData.roadEdges = JSON.parse(
  39. JSON.stringify(dataService.getRoadEdges())
  40. );
  41. this.lastData.roads = JSON.parse(JSON.stringify(dataService.getRoads()));
  42. this.lastData.curveRoadPoints = JSON.parse(
  43. JSON.stringify(dataService.getCurveRoadPoints())
  44. );
  45. this.lastData.curveRoadEdges = JSON.parse(
  46. JSON.stringify(dataService.getCurveRoadEdges())
  47. );
  48. this.lastData.curveRoads = JSON.parse(
  49. JSON.stringify(dataService.getCurveRoads())
  50. );
  51. this.lastData.crossPoints = JSON.parse(
  52. JSON.stringify(dataService.getCrossPoints())
  53. );
  54. this.lastData.settings = JSON.parse(JSON.stringify(Settings));
  55. }
  56. operate() {
  57. //
  58. this.currentData = {};
  59. // this.compareRoads();
  60. this.comparePoints();
  61. this.compareLines();
  62. this.compareCurvePoints();
  63. this.compareCurveLines();
  64. this.compareCircles();
  65. this.compareTexts();
  66. this.compareMagnifiers();
  67. this.compareSVGs();
  68. this.compareRoadPoints();
  69. this.compareRoadEdges();
  70. this.compareRoads();
  71. this.compareCurveRoadPoints();
  72. this.compareCurveRoadEdges();
  73. this.compareCurveRoads();
  74. this.compareCrossPoints();
  75. this.compareSettings();
  76. if (
  77. this.currentData.points.length == 0 &&
  78. this.currentData.lines.length == 0 &&
  79. this.currentData.curvePoints.length == 0 &&
  80. this.currentData.curveLines.length == 0 &&
  81. this.currentData.circles.length == 0 &&
  82. this.currentData.texts.length == 0 &&
  83. this.currentData.magnifiers.length == 0 &&
  84. this.currentData.roadPoints.length == 0 &&
  85. this.currentData.roadEdges.length == 0 &&
  86. this.currentData.roads.length == 0 &&
  87. this.currentData.curveRoadPoints.length == 0 &&
  88. this.currentData.curveRoadEdges.length == 0 &&
  89. this.currentData.curveRoads.length == 0 &&
  90. this.currentData.crossPoints.length == 0 &&
  91. !this.currentData.settings
  92. ) {
  93. this.saveCurrentInfo();
  94. return false;
  95. }
  96. this.lastData = {};
  97. // 这里不能取this.records.length-1,因为可能撤销后操作,这时候应该是覆盖,而不是往后面添加
  98. return true;
  99. }
  100. comparePoints() {
  101. const points = dataService.getPoints();
  102. this.currentData.points = [];
  103. for (const key in points) {
  104. const point = points[key];
  105. // 不存在意味着增加
  106. if (!this.lastData.points[key]) {
  107. const item = {
  108. handle: HistoryEvents.AddPoint,
  109. point: historyUtil.getDataForPoint(point),
  110. };
  111. this.currentData.points.push(item);
  112. } else {
  113. const lastPoint = this.lastData.points[key];
  114. if (!historyUtil.isDifferentForPoints(point, lastPoint)) {
  115. delete this.lastData.points[key];
  116. continue;
  117. } else {
  118. const item = {
  119. handle: HistoryEvents.ModifyPoint,
  120. prePoint: historyUtil.getDataForPoint(lastPoint),
  121. curPoint: historyUtil.getDataForPoint(point),
  122. };
  123. this.currentData.points.push(item);
  124. }
  125. }
  126. delete this.lastData.points[key];
  127. }
  128. for (const key in this.lastData.points) {
  129. const item = {
  130. handle: HistoryEvents.DeletePoint,
  131. point: historyUtil.getDataForPoint(this.lastData.points[key]),
  132. };
  133. this.currentData.points.push(item);
  134. }
  135. }
  136. compareLines() {
  137. const lines = dataService.getLines();
  138. this.currentData.lines = [];
  139. for (const key in lines) {
  140. const line = lines[key];
  141. // 不存在意味着增加
  142. if (!this.lastData.lines[key]) {
  143. const item = {
  144. handle: HistoryEvents.AddLine,
  145. line: historyUtil.getDataForLine(line),
  146. };
  147. this.currentData.lines.push(item);
  148. } else {
  149. const lastLine = this.lastData.lines[key];
  150. if (!historyUtil.isDifferentForLines(line, lastLine)) {
  151. delete this.lastData.lines[key];
  152. continue;
  153. } else {
  154. const item = {
  155. handle: HistoryEvents.ModifyLine,
  156. preLine: historyUtil.getDataForLine(lastLine),
  157. curLine: historyUtil.getDataForLine(line),
  158. };
  159. this.currentData.lines.push(item);
  160. }
  161. }
  162. delete this.lastData.lines[key];
  163. }
  164. for (const key in this.lastData.lines) {
  165. const item = {
  166. handle: HistoryEvents.DeleteLine,
  167. line: historyUtil.getDataForLine(this.lastData.lines[key]),
  168. };
  169. this.currentData.lines.push(item);
  170. }
  171. }
  172. compareCurvePoints() {
  173. const curvePoints = dataService.getCurvePoints();
  174. this.currentData.curvePoints = [];
  175. for (const key in curvePoints) {
  176. const curvePoint = curvePoints[key];
  177. // 不存在意味着增加
  178. if (!this.lastData.curvePoints[key]) {
  179. const item = {
  180. handle: HistoryEvents.AddCurvePoint,
  181. curvePoint: historyUtil.getDataForCurvePoint(curvePoint),
  182. };
  183. this.currentData.curvePoints.push(item);
  184. } else {
  185. const lastCurvePoint = this.lastData.curvePoints[key];
  186. if (
  187. !historyUtil.isDifferentForCurvePoints(curvePoint, lastCurvePoint)
  188. ) {
  189. delete this.lastData.curvePoints[key];
  190. continue;
  191. } else {
  192. const item = {
  193. handle: HistoryEvents.ModifyCurvePoint,
  194. preCurvePoint: historyUtil.getDataForCurvePoint(lastCurvePoint),
  195. curCurvePoint: historyUtil.getDataForCurvePoint(curvePoint),
  196. };
  197. this.currentData.curvePoints.push(item);
  198. }
  199. }
  200. delete this.lastData.curvePoints[key];
  201. }
  202. for (const key in this.lastData.curvePoints) {
  203. const item = {
  204. handle: HistoryEvents.DeleteCurvePoint,
  205. curvePoint: historyUtil.getDataForCurvePoint(
  206. this.lastData.curvePoints[key]
  207. ),
  208. };
  209. this.currentData.curvePoints.push(item);
  210. }
  211. }
  212. compareCurveLines() {
  213. const curveLines = dataService.getCurveLines();
  214. this.currentData.curveLines = [];
  215. for (const key in curveLines) {
  216. const curveLine = curveLines[key];
  217. // 不存在意味着增加
  218. if (!this.lastData.curveLines[key]) {
  219. const item = {
  220. handle: HistoryEvents.AddCurveLine,
  221. curveLine: historyUtil.getDataForCurveLine(curveLine),
  222. };
  223. this.currentData.curveLines.push(item);
  224. } else {
  225. const lastCurveLine = this.lastData.curveLines[key];
  226. if (!historyUtil.isDifferentForCurveLines(curveLine, lastCurveLine)) {
  227. delete this.lastData.curveLines[key];
  228. continue;
  229. } else {
  230. const item = {
  231. handle: HistoryEvents.ModifyCurveLine,
  232. preCurveLine: historyUtil.getDataForCurveLine(lastCurveLine),
  233. curCurveLine: historyUtil.getDataForCurveLine(curveLine),
  234. };
  235. this.currentData.curveLines.push(item);
  236. }
  237. }
  238. delete this.lastData.curveLines[key];
  239. }
  240. for (const key in this.lastData.curveLines) {
  241. const item = {
  242. handle: HistoryEvents.DeleteCurveLine,
  243. curveLine: historyUtil.getDataForCurveLine(
  244. this.lastData.curveLines[key]
  245. ),
  246. };
  247. this.currentData.curveLines.push(item);
  248. }
  249. }
  250. compareTexts() {
  251. this.currentData.texts = [];
  252. const texts = dataService.getTexts();
  253. for (const key in texts) {
  254. const text = texts[key];
  255. const lastText = this.lastData.texts[key];
  256. // 不存在意味着增加
  257. if (!lastText) {
  258. const item = {
  259. handle: HistoryEvents.AddText,
  260. text: historyUtil.getDataForText(text),
  261. };
  262. this.currentData.texts.push(item);
  263. } else {
  264. if (!historyUtil.isDifferentForTexts(text, lastText)) {
  265. delete this.lastData.texts[key];
  266. continue;
  267. } else {
  268. const item = {
  269. handle: HistoryEvents.ModifyText,
  270. preText: historyUtil.getDataForText(lastText),
  271. curText: historyUtil.getDataForText(text),
  272. };
  273. this.currentData.texts.push(item);
  274. }
  275. }
  276. delete this.lastData.texts[key];
  277. }
  278. for (const key in this.lastData.texts) {
  279. const item = {
  280. handle: HistoryEvents.DeleteText,
  281. text: historyUtil.getDataForText(this.lastData.texts[key]),
  282. };
  283. this.currentData.texts.push(item);
  284. }
  285. }
  286. compareCircles() {
  287. const circles = dataService.getCircles();
  288. this.currentData.circles = [];
  289. for (const key in circles) {
  290. const circle = circles[key];
  291. // 不存在意味着增加
  292. if (!this.lastData.circles[key]) {
  293. const item = {
  294. handle: HistoryEvents.AddCircle,
  295. circle: historyUtil.getDataForCircle(circle),
  296. };
  297. this.currentData.circles.push(item);
  298. } else {
  299. const lastCircle = this.lastData.circles[key];
  300. if (!historyUtil.isDifferentForCircles(circle, lastCircle)) {
  301. delete this.lastData.circles[key];
  302. continue;
  303. } else {
  304. const item = {
  305. handle: HistoryEvents.ModifyCircle,
  306. preCircle: historyUtil.getDataForCircle(lastCircle),
  307. curCircle: historyUtil.getDataForCircle(circle),
  308. };
  309. this.currentData.circles.push(item);
  310. }
  311. }
  312. delete this.lastData.circles[key];
  313. }
  314. for (const key in this.lastData.circles) {
  315. const item = {
  316. handle: HistoryEvents.DeleteCircle,
  317. circle: historyUtil.getDataForCircle(this.lastData.circles[key]),
  318. };
  319. this.currentData.circles.push(item);
  320. }
  321. }
  322. compareMagnifiers() {
  323. const magnifiers = dataService.getMagnifiers();
  324. this.currentData.magnifiers = [];
  325. for (const key in magnifiers) {
  326. const magnifier = magnifiers[key];
  327. // 不存在意味着增加
  328. if (!this.lastData.magnifiers[key]) {
  329. const item = {
  330. handle: HistoryEvents.AddMagnifier,
  331. magnifier: historyUtil.getDataForMagnifier(magnifier),
  332. };
  333. this.currentData.magnifiers.push(item);
  334. } else {
  335. const lastMagnifier = this.lastData.magnifiers[key];
  336. if (!historyUtil.isDifferentForMagnifiers(magnifier, lastMagnifier)) {
  337. delete this.lastData.magnifiers[key];
  338. continue;
  339. } else {
  340. const item = {
  341. handle: HistoryEvents.ModifyMagnifier,
  342. preMagnifier: historyUtil.getDataForMagnifier(lastMagnifier),
  343. curMagnifier: historyUtil.getDataForMagnifier(magnifier),
  344. };
  345. this.currentData.magnifiers.push(item);
  346. }
  347. }
  348. delete this.lastData.magnifiers[key];
  349. }
  350. for (const key in this.lastData.magnifiers) {
  351. const item = {
  352. handle: HistoryEvents.DeleteMagnifier,
  353. magnifier: historyUtil.getDataForMagnifier(
  354. this.lastData.magnifiers[key]
  355. ),
  356. };
  357. this.currentData.magnifiers.push(item);
  358. }
  359. }
  360. compareSVGs() {
  361. this.currentData.svgs = [];
  362. const svgs = dataService.getSVGs();
  363. for (const key in svgs) {
  364. const svg = svgs[key];
  365. const lastSVG = this.lastData.svgs[key];
  366. // 不存在意味着增加
  367. if (!lastSVG) {
  368. const item = {
  369. handle: HistoryEvents.AddSVG,
  370. svg: historyUtil.getDataForSVG(svg),
  371. };
  372. this.currentData.svgs.push(item);
  373. } else {
  374. if (!historyUtil.isDifferentForSVGs(svg, lastSVG)) {
  375. delete this.lastData.svgs[key];
  376. continue;
  377. } else {
  378. const item = {
  379. handle: HistoryEvents.ModifySVG,
  380. preSVG: historyUtil.getDataForSVG(lastSVG),
  381. curSVG: historyUtil.getDataForSVG(svg),
  382. };
  383. this.currentData.svgs.push(item);
  384. }
  385. }
  386. delete this.lastData.svgs[key];
  387. }
  388. for (const key in this.lastData.svgs) {
  389. const item = {
  390. handle: HistoryEvents.DeleteSVG,
  391. svg: historyUtil.getDataForSVG(this.lastData.svgs[key]),
  392. };
  393. this.currentData.svgs.push(item);
  394. }
  395. }
  396. compareRoadPoints() {
  397. this.currentData.roadPoints = [];
  398. const roadPoints = dataService.getRoadPoints();
  399. for (const key in roadPoints) {
  400. const roadPoint = roadPoints[key];
  401. const lastRoadPoint = this.lastData.roadPoints[key];
  402. // 不存在意味着增加
  403. if (!lastRoadPoint) {
  404. const item = {
  405. handle: HistoryEvents.AddRoadPoint,
  406. roadPoint: historyUtil.getDataForRoadPoint(roadPoint),
  407. };
  408. this.currentData.roadPoints.push(item);
  409. } else {
  410. if (!historyUtil.isDifferentForRoadPoints(roadPoint, lastRoadPoint)) {
  411. delete this.lastData.roadPoints[key];
  412. continue;
  413. } else {
  414. const item = {
  415. handle: HistoryEvents.ModifyRoadPoint,
  416. preRoadPoint: historyUtil.getDataForRoadPoint(lastRoadPoint),
  417. curRoadPoint: historyUtil.getDataForRoadPoint(roadPoint),
  418. };
  419. this.currentData.roadPoints.push(item);
  420. }
  421. }
  422. delete this.lastData.roadPoints[key];
  423. }
  424. for (const key in this.lastData.roadPoints) {
  425. const item = {
  426. handle: HistoryEvents.DeleteRoadPoint,
  427. roadPoint: historyUtil.getDataForRoadPoint(
  428. this.lastData.roadPoints[key]
  429. ),
  430. };
  431. this.currentData.roadPoints.push(item);
  432. }
  433. }
  434. compareRoadEdges() {
  435. this.currentData.roadEdges = [];
  436. const roadEdges = dataService.getRoadEdges();
  437. for (const key in roadEdges) {
  438. const roadEdge = roadEdges[key];
  439. const lastRoadEdge = this.lastData.roadEdges[key];
  440. // 不存在意味着增加
  441. if (!lastRoadEdge) {
  442. const item = {
  443. handle: HistoryEvents.AddRoadEdge,
  444. roadEdge: historyUtil.getDataForRoadEdge(roadEdge),
  445. };
  446. this.currentData.roadEdges.push(item);
  447. } else {
  448. if (!historyUtil.isDifferentForRoadEdges(roadEdge, lastRoadEdge)) {
  449. delete this.lastData.roadEdges[key];
  450. continue;
  451. } else {
  452. const item = {
  453. handle: HistoryEvents.ModifyRoadEdge,
  454. preRoadEdge: historyUtil.getDataForRoadEdge(lastRoadEdge),
  455. curRoadEdge: historyUtil.getDataForRoadEdge(roadEdge),
  456. };
  457. this.currentData.roadEdges.push(item);
  458. }
  459. }
  460. delete this.lastData.roadEdges[key];
  461. }
  462. for (const key in this.lastData.roadEdges) {
  463. const item = {
  464. handle: HistoryEvents.DeleteRoadEdge,
  465. roadEdge: historyUtil.getDataForRoadEdge(this.lastData.roadEdges[key]),
  466. };
  467. this.currentData.roadEdges.push(item);
  468. }
  469. }
  470. compareRoads() {
  471. this.currentData.roads = [];
  472. const roads = dataService.getRoads();
  473. for (const key in roads) {
  474. const road = roads[key];
  475. const lastRoad = this.lastData.roads[key];
  476. // 不存在意味着增加
  477. if (!lastRoad) {
  478. const item = {
  479. handle: HistoryEvents.AddRoad,
  480. road: historyUtil.getDataForRoad(road),
  481. };
  482. this.currentData.roads.push(item);
  483. } else {
  484. if (!historyUtil.isDifferentForRoads(road, lastRoad)) {
  485. delete this.lastData.roads[key];
  486. continue;
  487. } else {
  488. const item = {
  489. handle: HistoryEvents.ModifyRoad,
  490. preRoad: historyUtil.getDataForRoad(lastRoad),
  491. curRoad: historyUtil.getDataForRoad(road),
  492. };
  493. this.currentData.roads.push(item);
  494. }
  495. }
  496. delete this.lastData.roads[key];
  497. }
  498. for (const key in this.lastData.roads) {
  499. const item = {
  500. handle: HistoryEvents.DeleteRoad,
  501. road: historyUtil.getDataForRoad(this.lastData.roads[key]),
  502. };
  503. this.currentData.roads.push(item);
  504. }
  505. }
  506. compareCurveRoadPoints() {
  507. this.currentData.curveRoadPoints = [];
  508. const curveRoadPoints = dataService.getCurveRoadPoints();
  509. for (const key in curveRoadPoints) {
  510. const curveRoadPoint = curveRoadPoints[key];
  511. const lastCurveRoadPoint = this.lastData.curveRoadPoints[key];
  512. // 不存在意味着增加
  513. if (!lastCurveRoadPoint) {
  514. const item = {
  515. handle: HistoryEvents.AddCurveRoadPoint,
  516. curveRoadPoint: historyUtil.getDataForCurveRoadPoint(curveRoadPoint),
  517. };
  518. this.currentData.curveRoadPoints.push(item);
  519. } else {
  520. if (
  521. !historyUtil.isDifferentForCurveRoadPoints(
  522. curveRoadPoint,
  523. lastCurveRoadPoint
  524. )
  525. ) {
  526. delete this.lastData.curveRoadPoints[key];
  527. continue;
  528. } else {
  529. const item = {
  530. handle: HistoryEvents.ModifyCurveRoadPoint,
  531. preCurveRoadPoint:
  532. historyUtil.getDataForCurveRoadPoint(lastCurveRoadPoint),
  533. curCurveRoadPoint:
  534. historyUtil.getDataForCurveRoadPoint(curveRoadPoint),
  535. };
  536. this.currentData.curveRoadPoints.push(item);
  537. }
  538. }
  539. delete this.lastData.curveRoadPoints[key];
  540. }
  541. for (const key in this.lastData.curveRoadPoints) {
  542. const item = {
  543. handle: HistoryEvents.DeleteCurveRoadPoint,
  544. curveRoadPoint: historyUtil.getDataForCurveRoadPoint(
  545. this.lastData.curveRoadPoints[key]
  546. ),
  547. };
  548. this.currentData.curveRoadPoints.push(item);
  549. }
  550. }
  551. compareCurveRoads() {
  552. this.currentData.curveRoads = [];
  553. const curveRoads = dataService.getCurveRoads();
  554. for (const key in curveRoads) {
  555. const curveRoad = curveRoads[key];
  556. const lastCurveRoad = this.lastData.curveRoads[key];
  557. // 不存在意味着增加
  558. if (!lastCurveRoad) {
  559. const item = {
  560. handle: HistoryEvents.AddCurveRoad,
  561. curveRoad: historyUtil.getDataForCurveRoad(curveRoad),
  562. };
  563. this.currentData.curveRoads.push(item);
  564. } else {
  565. if (!historyUtil.isDifferentForCurveRoads(curveRoad, lastCurveRoad)) {
  566. delete this.lastData.curveRoads[key];
  567. continue;
  568. } else {
  569. const item = {
  570. handle: HistoryEvents.ModifyCurveRoad,
  571. preCurveRoad: historyUtil.getDataForCurveRoad(lastCurveRoad),
  572. curCurveRoad: historyUtil.getDataForCurveRoad(curveRoad),
  573. };
  574. this.currentData.curveRoads.push(item);
  575. }
  576. }
  577. delete this.lastData.curveRoads[key];
  578. }
  579. for (const key in this.lastData.curveRoads) {
  580. const item = {
  581. handle: HistoryEvents.DeleteCurveRoad,
  582. curveRoad: historyUtil.getDataForCurveRoad(
  583. this.lastData.curveRoads[key]
  584. ),
  585. };
  586. this.currentData.curveRoads.push(item);
  587. }
  588. }
  589. compareCurveRoadEdges() {
  590. this.currentData.curveRoadEdges = [];
  591. const curveRoadEdges = dataService.getCurveRoadEdges();
  592. for (const key in curveRoadEdges) {
  593. const curveRoadEdge = curveRoadEdges[key];
  594. const lastCurveRoadEdge = this.lastData.curveRoadEdges[key];
  595. // 不存在意味着增加
  596. if (!lastCurveRoadEdge) {
  597. const item = {
  598. handle: HistoryEvents.AddCurveRoadEdge,
  599. curveRoadEdge: historyUtil.getDataForCurveRoadEdge(curveRoadEdge),
  600. };
  601. this.currentData.curveRoadEdges.push(item);
  602. } else {
  603. if (
  604. !historyUtil.isDifferentForCurveRoadEdges(
  605. curveRoadEdge,
  606. lastCurveRoadEdge
  607. )
  608. ) {
  609. delete this.lastData.curveRoadEdges[key];
  610. continue;
  611. } else {
  612. const item = {
  613. handle: HistoryEvents.ModifyCurveRoadEdge,
  614. preCurveRoadEdge:
  615. historyUtil.getDataForCurveRoadEdge(lastCurveRoadEdge),
  616. curCurveRoadEdge:
  617. historyUtil.getDataForCurveRoadEdge(curveRoadEdge),
  618. };
  619. this.currentData.curveRoadEdges.push(item);
  620. }
  621. }
  622. delete this.lastData.curveRoadEdges[key];
  623. }
  624. for (const key in this.lastData.curveRoadEdges) {
  625. const item = {
  626. handle: HistoryEvents.DeleteCurveRoadEdge,
  627. curveRoadEdge: historyUtil.getDataForCurveRoadEdge(
  628. this.lastData.curveRoadEdges[key]
  629. ),
  630. };
  631. this.currentData.curveRoadEdges.push(item);
  632. }
  633. }
  634. compareCrossPoints() {
  635. this.currentData.crossPoints = [];
  636. const crossPoints = dataService.getCrossPoints();
  637. for (const key in crossPoints) {
  638. const crossPoint = crossPoints[key];
  639. const lastCrossPoint = this.lastData.crossPoints[key];
  640. // 不存在意味着增加
  641. if (!lastCrossPoint) {
  642. const item = {
  643. handle: HistoryEvents.AddCrossPoint,
  644. crossPoint: historyUtil.getDataForCrossPoint(crossPoint),
  645. };
  646. this.currentData.crossPoints.push(item);
  647. } else {
  648. if (
  649. !historyUtil.isDifferentForCrossPoints(crossPoint, lastCrossPoint)
  650. ) {
  651. delete this.lastData.crossPoints[key];
  652. continue;
  653. } else {
  654. const item = {
  655. handle: HistoryEvents.ModifyCrossPoint,
  656. preCrossPoint: historyUtil.getDataForCrossPoint(lastCrossPoint),
  657. curCrossPoint: historyUtil.getDataForCrossPoint(crossPoint),
  658. };
  659. this.currentData.crossPoints.push(item);
  660. }
  661. }
  662. delete this.lastData.crossPoints[key];
  663. }
  664. for (const key in this.lastData.crossPoints) {
  665. const item = {
  666. handle: HistoryEvents.DeleteCrossPoint,
  667. crossPoint: historyUtil.getDataForCrossPoint(
  668. this.lastData.crossPoints[key]
  669. ),
  670. };
  671. this.currentData.crossPoints.push(item);
  672. }
  673. }
  674. compareSettings() {
  675. const lastSettings = this.lastData.settings;
  676. this.currentData.settings = null;
  677. if (historyUtil.isDifferentForSettings(Settings, lastSettings)) {
  678. const item = {
  679. handle: HistoryEvents.ModifySettings,
  680. preSettings: historyUtil.getDataForSettings(lastSettings),
  681. curSettings: historyUtil.getDataForSettings(Settings),
  682. };
  683. this.currentData.settings = item;
  684. }
  685. }
  686. }
  687. const change = new Change();
  688. export { change };