Load.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { dataService } from "./Service/DataService.js";
  2. import { lineService } from "./Service/LineService.js";
  3. import { pointService } from "./Service/PointService.js";
  4. import { imageService } from "./Service/ImageService.js";
  5. import VectorCategory from "./enum/VectorCategory.js";
  6. import { coordinate } from "./Coordinate.js";
  7. import { circleService } from "./Service/CircleService.js";
  8. import { magnifierService } from "./Service/MagnifierService.js";
  9. import { textService } from "./Service/TextService.js";
  10. export default class Load {
  11. constructor(layer) {
  12. this.layer = layer;
  13. this.version = "v1.0";
  14. this.vectorsJson = null;
  15. this.newVectorId = null;
  16. }
  17. async load(dataLocal, data3d) {
  18. if (dataLocal) {
  19. if (dataLocal.backgroundImg) {
  20. let bgImg = imageService.create(
  21. dataLocal.backgroundImg.src,
  22. dataLocal.backgroundImg.vectorId
  23. );
  24. bgImg.setCenter(dataLocal.backgroundImg.center);
  25. bgImg.setDisplay(dataLocal.backgroundImg.display);
  26. bgImg.setAngle(dataLocal.backgroundImg.angle);
  27. try {
  28. await bgImg.setImageData();
  29. } catch (e) {}
  30. }
  31. if (dataLocal.circles) {
  32. for (let key in dataLocal.circles) {
  33. let circle = circleService.create(
  34. dataLocal.circles[key].center,
  35. dataLocal.circles[key].radius,
  36. key
  37. );
  38. circle.setPoints(dataLocal.circles[key].points);
  39. circle.setColor(dataLocal.circles[key].color);
  40. circle.setDisplay(dataLocal.circles[key].display);
  41. }
  42. }
  43. if (dataLocal.magnifiers) {
  44. for (let key in dataLocal.magnifiers) {
  45. let magnifier = magnifierService.create(
  46. dataLocal.magnifiers[key].position,
  47. key
  48. );
  49. magnifier.setSrc(dataLocal.magnifiers[key].photoUrl);
  50. magnifier.setDisplay(dataLocal.magnifiers[key].display);
  51. try {
  52. await magnifier.setImageData();
  53. } catch (e) {}
  54. }
  55. }
  56. if (dataLocal.texts) {
  57. for (let key in dataLocal.texts) {
  58. let text = textService.create(dataLocal.texts[key].center, key);
  59. text.setValue(dataLocal.texts[key].value);
  60. text.setFontSize(dataLocal.texts[key].fontSize);
  61. text.setColor(dataLocal.texts[key].color);
  62. text.setDisplay(dataLocal.texts[key].display);
  63. }
  64. }
  65. if (dataLocal.points) {
  66. for (let key in dataLocal.points) {
  67. let point = pointService.create(
  68. { x: dataLocal.points[key].x, y: dataLocal.points[key].y },
  69. dataLocal.points[key].category,
  70. key
  71. );
  72. point.setParent(
  73. JSON.parse(JSON.stringify(dataLocal.points[key].parent))
  74. );
  75. point.setDisplay(dataLocal.points[key].display);
  76. }
  77. }
  78. if (dataLocal.lines) {
  79. for (let key in dataLocal.lines) {
  80. let line = lineService.createByPointId(
  81. dataLocal.lines[key].startId,
  82. dataLocal.lines[key].endId,
  83. dataLocal.lines[key].category,
  84. key
  85. );
  86. if (dataLocal.lines[key].arrowColor) {
  87. line.setArrowColor(dataLocal.lines[key].arrowColor);
  88. }
  89. line.setDisplay(dataLocal.lines[key].display);
  90. }
  91. }
  92. if (dataLocal.hasOwnProperty("currentId")) {
  93. dataService.setCurrentId(dataLocal.currentId);
  94. }
  95. }
  96. if (data3d) {
  97. if (data3d.backImage) {
  98. let bgImg = imageService.create(data3d.backImage, data3d.vectorId);
  99. bgImg.setCenter(coordinate.center);
  100. try {
  101. await bgImg.setImageData();
  102. } catch (e) {}
  103. }
  104. if (data3d.baseLines) {
  105. for (let i = 0; i < data3d.baseLines.length; ++i) {
  106. //理论上基准线只能有一条
  107. lineService.create(
  108. data3d.baseLines[i][0],
  109. data3d.baseLines[i][1],
  110. VectorCategory.Line.BaseLine
  111. );
  112. }
  113. }
  114. if (data3d.measures) {
  115. for (let i = 0; i < data3d.measures.length; ++i) {
  116. //理论上基准线只能有一条
  117. lineService.create(
  118. data3d.measures[i][0],
  119. data3d.measures[i][1],
  120. VectorCategory.Line.MeasureLine
  121. );
  122. }
  123. }
  124. if (data3d.basePoints) {
  125. for (let i = 0; i < data3d.basePoints.length; ++i) {
  126. pointService.create(
  127. data3d.basePoints[i],
  128. VectorCategory.Point.BasePoint
  129. );
  130. }
  131. }
  132. if (data3d.fixPoints) {
  133. for (let i = 0; i < data3d.fixPoints.length; ++i) {
  134. pointService.create(
  135. data3d.fixPoints[i],
  136. VectorCategory.Point.FixPoint
  137. );
  138. }
  139. }
  140. }
  141. this.layer.history.init();
  142. this.layer.renderer.autoRedraw();
  143. }
  144. save() {
  145. return dataService.vectorData;
  146. }
  147. // 退出页面清除缓存及其他操作
  148. clear() {
  149. console.warn("clear");
  150. }
  151. }