getStart.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- 画板 -->
  2. <template>
  3. <div ref="baseMap" class="base-map">
  4. <canvas
  5. v-loading="loading"
  6. id="floorMap"
  7. :width="canvasWidth"
  8. :height="canvasHeight"
  9. tabindex="0"
  10. ></canvas>
  11. </div>
  12. </template>
  13. <script>
  14. import { SGraphView, SGraphScene } from "@persagy-web/graph";
  15. import { SFloorParser, getJsonz, SZoneParser } from "@persagy-web/big/lib";
  16. export default {
  17. data() {
  18. return {
  19. canvasWidth: 0, // 画布的宽
  20. canvasHeight: 0, // 画布的高
  21. view: null, // 视图 view
  22. scene: null, // 场景类
  23. dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
  24. mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
  25. loading: false,
  26. };
  27. },
  28. methods: {
  29. // 初始化
  30. init() {
  31. this.clearImg();
  32. this.view ? (this.view.scene = this.scene) : null;
  33. // 获取压缩包数据并解压
  34. this.getMapBlob();
  35. },
  36. // 请求获取地图的压缩包
  37. getMapBlob() {
  38. const url = this.mapUrl + this.dataKey;
  39. this.loading = true;
  40. getJsonz(url)
  41. .then((data) => {
  42. // 解析数据并放入压缩包中
  43. this.parserData(data);
  44. this.loading = false;
  45. })
  46. .catch(() => {
  47. this.loading = false;
  48. });
  49. },
  50. // 解析数据并注入 scene 类中
  51. parserData(data) {
  52. let parser = new SFloorParser();
  53. parser.parseData(data);
  54. parser.spaceList.forEach((t) => {
  55. // 添加图例
  56. this.scene.addItem(t);
  57. });
  58. parser.wallList.forEach((t) => {
  59. this.scene.addItem(t);
  60. });
  61. parser.virtualWallList.forEach((t) => {
  62. this.scene.addItem(t);
  63. });
  64. parser.doorList.forEach((t) => {
  65. this.scene.addItem(t);
  66. });
  67. parser.columnList.forEach((t) => {
  68. this.scene.addItem(t);
  69. });
  70. parser.casementList.forEach((t) => {
  71. this.scene.addItem(t);
  72. });
  73. // 画板是否可拖动
  74. if (this.view) {
  75. this.view.DragMove = true;
  76. this.view.fitSceneToView();
  77. }
  78. },
  79. // 清空画布
  80. clearImg() {
  81. this.scene = new SGraphScene();
  82. if (this.view) {
  83. this.view.update();
  84. }
  85. },
  86. },
  87. watch: {
  88. // 监听key
  89. dataKey: {
  90. handler(val) {
  91. if (val) {
  92. this.init();
  93. }
  94. },
  95. immediate: true,
  96. },
  97. },
  98. created() {
  99. this.clearImg();
  100. },
  101. mounted() {
  102. // 获取 canvas 的宽高
  103. this.canvasWidth = 800;
  104. this.canvasHeight = 600;
  105. // 初始化场景类
  106. this.view = new SGraphView("floorMap");
  107. if (this.scene) {
  108. this.view.scene = this.scene;
  109. }
  110. },
  111. };
  112. </script>