getStartShow.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 { SColor } from "@persagy-web/draw";
  16. import { SFloorParser, getJsonz, SZoneParser } from "@persagy-web/big/lib";
  17. // 获取压缩包数据并解压
  18. const map1 = require("../../../public/assets/map/1.json");
  19. export default {
  20. data() {
  21. return {
  22. canvasWidth: 0, // 画布的宽
  23. canvasHeight: 0, // 画布的高
  24. view: null, // 视图 view
  25. scene: null, // 场景类
  26. dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
  27. mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
  28. loading: false,
  29. };
  30. },
  31. methods: {
  32. // 初始化
  33. init() {
  34. this.view ? (this.view.scene = this.scene) : null;
  35. // 解析数据并放入压缩包中
  36. setTimeout(() => {
  37. this.parserData(map1.EntityList[0].Elements);
  38. });
  39. },
  40. // 解析数据并注入 scene 类中
  41. parserData(data) {
  42. let parser = new SFloorParser();
  43. parser.parseData(data);
  44. parser.spaceList.forEach((t) => {
  45. // 添加图例
  46. this.scene.addItem(t);
  47. });
  48. parser.wallList.forEach((t) => {
  49. this.scene.addItem(t);
  50. });
  51. parser.virtualWallList.forEach((t) => {
  52. this.scene.addItem(t);
  53. });
  54. parser.doorList.forEach((t) => {
  55. this.scene.addItem(t);
  56. });
  57. parser.columnList.forEach((t) => {
  58. this.scene.addItem(t);
  59. });
  60. parser.casementList.forEach((t) => {
  61. this.scene.addItem(t);
  62. });
  63. // 画板是否可拖动
  64. if (this.view) {
  65. this.view.DragMove = true;
  66. this.view.fitSceneToView();
  67. }
  68. },
  69. // 清空画布
  70. clearImg() {
  71. this.scene = new SGraphScene();
  72. if (this.view) {
  73. this.view.update();
  74. }
  75. },
  76. },
  77. created() {
  78. this.clearImg();
  79. },
  80. mounted() {
  81. // 获取 canvas 的宽高
  82. this.canvasWidth = 800;
  83. this.canvasHeight = 600;
  84. // 初始化场景类
  85. this.view = new SGraphView("floorMap");
  86. if (this.scene) {
  87. this.view.scene = this.scene;
  88. this.init();
  89. }
  90. },
  91. };
  92. </script>