partChange.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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, SPoint } from "@persagy-web/draw";
  17. /////////模拟接口数据
  18. const map1 = require("../../../public/assets/map/1.json");
  19. import { equipmentList } from "./data/equipmentList.js";
  20. import { spaceList } from "./data/spacelist.js";
  21. import { MarkItem } from "./addPictrueClass/MarkItem";
  22. import { FloorView } from "./addPictrueClass/FloorView";
  23. export default {
  24. data() {
  25. return {
  26. canvasWidth: 0, // 画布的宽
  27. canvasHeight: 0, // 画布的高
  28. view: null, // 视图 view
  29. scene: null, // 场景类
  30. dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
  31. mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
  32. loading: false,
  33. isShowColumn: false, //是否展示柱子
  34. isShowWall: false, //是否显示墙
  35. isShowVirtualWall: false, //是否显示虚拟墙
  36. isShowDoor: false, // 是否显示门
  37. isShowWindow: false, //是否显示窗户
  38. isSpaceSelectable: true, //是否显示空间
  39. };
  40. },
  41. methods: {
  42. // 初始化
  43. init() {
  44. this.clearImg();
  45. this.view ? (this.view.scene = this.scene) : null;
  46. // 获取压缩包数据并解压
  47. setTimeout(() => {
  48. this.parserData(map1.EntityList[0].Elements);
  49. });
  50. },
  51. // 解析数据并注入 scene 类中
  52. parserData(data) {
  53. let parser = new SFloorParser();
  54. parser.parseData(data);
  55. parser.spaceList.forEach((t) => {
  56. /////////////////////////////////////////
  57. // 样式调整
  58. // 是否显示实例
  59. t.visible = this.isSpaceSelectable;
  60. //是否展示名称
  61. t.showBaseName = false;
  62. // 显示边框色
  63. t.strokeColor = new SColor("#F0F3F7");
  64. // 填充色
  65. t.fillColor = new SColor("#F0F3F7");
  66. // 边框线宽
  67. t.lineWidth = 1;
  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. this.mapSpace(spaceList);
  103. // 设备
  104. this.mapEquipment(equipmentList);
  105. },
  106. // 解析业务空间
  107. mapSpace(val) {
  108. if (!this.scene) return;
  109. const parse = new SZoneParser();
  110. parse.parseData(val);
  111. parse.zoneList.forEach((item) => {
  112. // 添加到场景
  113. item.selectable = true;
  114. item.showSelect = false;
  115. item.connect("onMouseDown", this, this.spaceDown);
  116. this.scene.addItem(item);
  117. });
  118. },
  119. // 解析设备点
  120. mapEquipment(val) {
  121. val.forEach((item) => {
  122. if (item.bimLocation) {
  123. const arr = item.bimLocation.split(",");
  124. const mark = {
  125. Id: item.equipId,
  126. ElementType: "Mark",
  127. equipId: item.equipId,
  128. Name: item.equipName,
  129. x: Number(arr[0]),
  130. y: Number(arr[1]),
  131. width: item.width,
  132. height: item.height,
  133. url: require("./../../public/assets/img/mark.png"),
  134. };
  135. // vuepress 报错 暂时注掉
  136. // const aaa = new MarkItem(null, mark);
  137. // aaa.connect("onMouseDown", this, this.equipDown);
  138. // this.scene.addItem(aaa);
  139. }
  140. });
  141. },
  142. // 点击设备
  143. equipDown(item, e) {
  144. this.locationGraphy(item);
  145. },
  146. // 点击空间
  147. spaceDown(item, e) {
  148. item.selected = true;
  149. this.sizeGraphy();
  150. },
  151. // 画布移动到中部
  152. locationGraphy(item) {
  153. let centerX = this.view.width / 2 - item.x * this.view.scale;
  154. let centerY = this.view.height / 2 - item.y * this.view.scale;
  155. this.view.origin = new SPoint(centerX, centerY);
  156. },
  157. // 局部放大
  158. sizeGraphy() {
  159. this.view.fitSelectedToView(0.9);
  160. },
  161. // 清空画布
  162. clearImg() {
  163. this.scene = new SGraphScene();
  164. if (this.view) {
  165. this.view.update();
  166. }
  167. },
  168. },
  169. watch: {
  170. // 监听key
  171. dataKey: {
  172. handler(val) {
  173. if (val) {
  174. this.init();
  175. }
  176. },
  177. immediate: true,
  178. },
  179. },
  180. created() {
  181. this.clearImg();
  182. },
  183. mounted() {
  184. // 获取 canvas 的宽高
  185. this.canvasWidth = 800;
  186. this.canvasHeight = 600;
  187. // 初始化场景类
  188. this.view = new FloorView("floorMap1");
  189. if (this.scene) {
  190. this.view.scene = this.scene;
  191. }
  192. },
  193. };
  194. </script>