getStart1.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!-- 画板 -->
  2. <template>
  3. <div ref="baseMap" class="base-map">
  4. <canvas
  5. v-loading="loading"
  6. id="floorMap1"
  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. import { SColor } from "@persagy-web/draw";
  17. export default {
  18. data() {
  19. return {
  20. canvasWidth: 0, // 画布的宽
  21. canvasHeight: 0, // 画布的高
  22. view: null, // 视图 view
  23. scene: null, // 场景类
  24. dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
  25. mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
  26. loading: false,
  27. isShowColumn: false, //是否展示柱子
  28. isShowWall: false, //是否显示墙
  29. isShowVirtualWall: false, //是否显示虚拟墙
  30. isShowDoor: false, // 是否显示门
  31. isShowWindow: false, //是否显示窗户
  32. isSpaceSelectable: true, //是否显示空间
  33. };
  34. },
  35. methods: {
  36. // 初始化
  37. init() {
  38. this.clearImg();
  39. this.view ? (this.view.scene = this.scene) : null;
  40. // 获取压缩包数据并解压
  41. this.getMapBlob();
  42. },
  43. // 请求获取地图的压缩包
  44. getMapBlob() {
  45. const url = this.mapUrl + this.dataKey;
  46. this.loading = true;
  47. getJsonz(url)
  48. .then((data) => {
  49. // 解析数据并放入压缩包中
  50. this.parserData(data);
  51. this.loading = false;
  52. })
  53. .catch(() => {
  54. this.loading = false;
  55. });
  56. },
  57. // 解析数据并注入 scene 类中
  58. parserData(data) {
  59. let parser = new SFloorParser();
  60. parser.parseData(data);
  61. parser.spaceList.forEach((t) => {
  62. /////////////////////////////////////////
  63. // 样式调整
  64. // 是否显示实例
  65. t.visible = this.isSpaceSelectable;
  66. //是否展示名称
  67. t.showBaseName = false;
  68. // 显示边框色
  69. t.strokeColor = new SColor("#F0F3F7");
  70. // 填充色
  71. t.fillColor = new SColor("#F0F3F7");
  72. // 边框线宽
  73. t.lineWidth = 1;
  74. // 添加图例
  75. this.scene.addItem(t);
  76. });
  77. parser.wallList.forEach((t) => {
  78. // 是否显示
  79. t.visible = this.isShowWall;
  80. this.scene.addItem(t);
  81. });
  82. parser.virtualWallList.forEach((t) => {
  83. // 是否显示
  84. t.visible = this.isShowVirtualWall;
  85. this.scene.addItem(t);
  86. });
  87. parser.doorList.forEach((t) => {
  88. // 是否显示
  89. t.visible = this.isShowDoor;
  90. this.scene.addItem(t);
  91. });
  92. parser.columnList.forEach((t) => {
  93. // 是否显示
  94. t.visible = this.isShowColumn;
  95. this.scene.addItem(t);
  96. });
  97. parser.casementList.forEach((t) => {
  98. // 是否显示
  99. t.visible = this.isShowWindow;
  100. this.scene.addItem(t);
  101. });
  102. // 画板是否可拖动
  103. if (this.view) {
  104. this.view.DragMove = true;
  105. this.view.fitSceneToView();
  106. }
  107. },
  108. // 清空画布
  109. clearImg() {
  110. this.scene = new SGraphScene();
  111. if (this.view) {
  112. this.view.update();
  113. }
  114. },
  115. },
  116. watch: {
  117. // 监听key
  118. dataKey: {
  119. handler(val) {
  120. if (val) {
  121. this.init();
  122. }
  123. },
  124. immediate: true,
  125. },
  126. },
  127. created() {
  128. this.clearImg();
  129. },
  130. mounted() {
  131. // 获取 canvas 的宽高
  132. this.canvasWidth = 800;
  133. this.canvasHeight = 600;
  134. // 初始化场景类
  135. this.view = new SGraphView("floorMap1");
  136. if (this.scene) {
  137. this.view.scene = this.scene;
  138. }
  139. },
  140. };
  141. </script>