addEventShow.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!-- 画板 -->
  2. <template>
  3. <div class="base-map">
  4. <canvas
  5. v-loading="loading"
  6. id="floorMap3"
  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. // 获取压缩包数据并解压
  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. isShowColumn: false, //是否展示柱子
  30. isShowWall: false, //是否显示墙
  31. isShowVirtualWall: false, //是否显示虚拟墙
  32. isShowDoor: false, // 是否显示门
  33. isShowWindow: false, //是否显示窗户
  34. isSpaceSelectable: true, //是否显示空间
  35. };
  36. },
  37. methods: {
  38. // 初始化
  39. init() {
  40. this.clearImg();
  41. this.view ? (this.view.scene = this.scene) : null;
  42. // 解析数据并放入压缩包中
  43. setTimeout(() => {
  44. this.parserData(map1.EntityList[0].Elements);
  45. });
  46. },
  47. // 解析数据并注入 scene 类中
  48. parserData(data) {
  49. let parser = new SFloorParser();
  50. parser.parseData(data);
  51. parser.spaceList.forEach((t) => {
  52. /////////////////////////////////////////
  53. // 样式调整
  54. // 是否显示实例
  55. t.visible = this.isSpaceSelectable;
  56. //是否展示名称
  57. t.showBaseName = false;
  58. // 显示边框色
  59. t.strokeColor = new SColor("#F0F3F7");
  60. // 填充色
  61. t.fillColor = new SColor("#F0F3F7");
  62. // 边框线宽
  63. t.lineWidth = 1;
  64. t.connect("onMouseDown", this, this.onMousedown);
  65. t.connect("onMouseUp", this, this.onMouseup);
  66. t.connect("onMouseLeave", this, this.onMouseleave);
  67. t.connect("onMouseEnter", this, this.onMouseenter);
  68. // 添加图例
  69. this.scene.addItem(t);
  70. });
  71. parser.wallList.forEach((t) => {
  72. // 是否显示
  73. t.visible = this.isShowWall;
  74. this.scene.addItem(t);
  75. });
  76. parser.virtualWallList.forEach((t) => {
  77. // 是否显示
  78. t.visible = this.isShowVirtualWall;
  79. this.scene.addItem(t);
  80. });
  81. parser.doorList.forEach((t) => {
  82. // 是否显示
  83. t.visible = this.isShowDoor;
  84. this.scene.addItem(t);
  85. });
  86. parser.columnList.forEach((t) => {
  87. // 是否显示
  88. t.visible = this.isShowColumn;
  89. this.scene.addItem(t);
  90. });
  91. parser.casementList.forEach((t) => {
  92. // 是否显示
  93. t.visible = this.isShowWindow;
  94. this.scene.addItem(t);
  95. });
  96. // 画板是否可拖动
  97. if (this.view) {
  98. this.view.DragMove = true;
  99. this.view.fitSceneToView();
  100. }
  101. },
  102. // 鼠标点击事件
  103. onMousedown(item, e) {
  104. alert("鼠标按下!");
  105. console.log("鼠标按下!", item, e);
  106. },
  107. // 鼠标抬起事件
  108. onMouseup(item, e) {},
  109. // 鼠标事件移入
  110. onMouseenter(item, e) {},
  111. // 鼠标事件移出
  112. onMouseleave(item, e) {},
  113. // 清空画布
  114. clearImg() {
  115. this.scene = new SGraphScene();
  116. if (this.view) {
  117. this.view.update();
  118. }
  119. },
  120. },
  121. watch: {},
  122. created() {
  123. this.clearImg();
  124. },
  125. mounted() {
  126. // 获取 canvas 的宽高
  127. this.canvasWidth = 800;
  128. this.canvasHeight = 600;
  129. // 初始化场景类
  130. this.view = new SGraphView("floorMap3");
  131. if (this.scene) {
  132. this.view.scene = this.scene;
  133. this.init();
  134. }
  135. },
  136. };
  137. </script>