addEvent1.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <!-- 画板 -->
  2. <template>
  3. <div class="base-map">
  4. <canvas
  5. v-loading="loading"
  6. id="floorMap4"
  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. import { eventScene } from "./addEventClass/eventScene";
  18. export default {
  19. data() {
  20. return {
  21. canvasWidth: 0, // 画布的宽
  22. canvasHeight: 0, // 画布的高
  23. view: null, // 视图 view
  24. scene: null, // 场景类
  25. dataKey: "base/f2a4b3d10d3511eb9a1da1ce4aece47c.jsonz", // 基 路径
  26. mapUrl: "/image-service/common/file_get?systemId=revit&key=", // 图 key
  27. loading: false,
  28. isShowColumn: false, //是否展示柱子
  29. isShowWall: false, //是否显示墙
  30. isShowVirtualWall: false, //是否显示虚拟墙
  31. isShowDoor: false, // 是否显示门
  32. isShowWindow: false, //是否显示窗户
  33. isSpaceSelectable: true, //是否显示空间
  34. selectItem: null, // 选中的 item 实例
  35. };
  36. },
  37. methods: {
  38. // 初始化
  39. init() {
  40. this.clearImg();
  41. this.view ? (this.view.scene = this.scene) : null;
  42. // 获取压缩包数据并解压
  43. this.getMapBlob();
  44. },
  45. // 请求获取地图的压缩包
  46. getMapBlob() {
  47. const url = this.mapUrl + this.dataKey;
  48. this.loading = true;
  49. getJsonz(url)
  50. .then((data) => {
  51. // 解析数据并放入压缩包中
  52. this.parserData(data);
  53. this.loading = false;
  54. })
  55. .catch(() => {
  56. this.loading = false;
  57. });
  58. },
  59. // 解析数据并注入 scene 类中
  60. parserData(data) {
  61. let parser = new SFloorParser();
  62. parser.parseData(data);
  63. parser.spaceList.forEach((t) => {
  64. /////////////////////////////////////////
  65. // 样式调整
  66. // 是否显示实例
  67. t.visible = this.isSpaceSelectable;
  68. //是否展示名称
  69. t.showBaseName = false;
  70. // 显示边框色
  71. t.strokeColor = new SColor("#F0F3F7");
  72. // 填充色
  73. t.fillColor = new SColor("#F0F3F7");
  74. // 边框线宽
  75. t.lineWidth = 1;
  76. t.connect("onMouseDown", this, this.onMousedown);
  77. t.connect("onMouseUp", this, this.onMouseup);
  78. t.connect("onMouseLeave", this, this.onMouseleave);
  79. t.connect("onMouseEnter", this, this.onMouseenter);
  80. // 添加图例
  81. this.scene.addItem(t);
  82. });
  83. parser.wallList.forEach((t) => {
  84. // 是否显示
  85. t.visible = this.isShowWall;
  86. this.scene.addItem(t);
  87. });
  88. parser.virtualWallList.forEach((t) => {
  89. // 是否显示
  90. t.visible = this.isShowVirtualWall;
  91. this.scene.addItem(t);
  92. });
  93. parser.doorList.forEach((t) => {
  94. // 是否显示
  95. t.visible = this.isShowDoor;
  96. this.scene.addItem(t);
  97. });
  98. parser.columnList.forEach((t) => {
  99. // 是否显示
  100. t.visible = this.isShowColumn;
  101. this.scene.addItem(t);
  102. });
  103. parser.casementList.forEach((t) => {
  104. // 是否显示
  105. t.visible = this.isShowWindow;
  106. this.scene.addItem(t);
  107. });
  108. // 画板是否可拖动
  109. if (this.view) {
  110. this.view.DragMove = true;
  111. this.view.fitSceneToView();
  112. }
  113. },
  114. // 鼠标点击事件
  115. onMousedown(item, e) {
  116. const DefaltColor = "#F0F3F7"; //默认颜色
  117. const clickColor = "#7ed321";
  118. // 如果点击前有选中的 selectItem 清空
  119. if (this.selectItem) {
  120. this.selectItem.fillColor = new SColor(DefaltColor);
  121. this.selectItem.strokeColor = new SColor(DefaltColor);
  122. }
  123. // 是否选中 item
  124. if (item) {
  125. // 判断当前 item 是否重复点击或者之前 selectItem = null
  126. if (this.selectItem) {
  127. if (this.selectItem != item) {
  128. // 之前空间置回原来的状态
  129. const oldSelectItem = this.selectItem;
  130. oldSelectItem.fillColor = new SColor(DefaltColor);
  131. oldSelectItem.strokeColor = new SColor(DefaltColor);
  132. // 新item高亮
  133. const newSelectItem = item;
  134. newSelectItem.fillColor = new SColor(clickColor);
  135. newSelectItem.strokeColor = new SColor(clickColor);
  136. this.selectItem = newSelectItem;
  137. } else {
  138. // 将选中的item 置为默认状态 选中 selectItem 为空
  139. const oldSelectItem = this.selectItem;
  140. oldSelectItem.fillColor = new SColor(DefaltColor);
  141. oldSelectItem.strokeColor = new SColor(DefaltColor);
  142. this.selectItem = null;
  143. }
  144. } else {
  145. // 如果点击前没有选中的 item 则直接赋给
  146. this.selectItem = item;
  147. this.selectItem.fillColor = new SColor(clickColor);
  148. this.selectItem.strokeColor = new SColor(clickColor);
  149. }
  150. } else {
  151. this.selectItem = null;
  152. }
  153. },
  154. // 鼠标抬起事件
  155. onMouseup(item, e) {},
  156. // 鼠标事件移入
  157. onMouseenter(item, e) {
  158. // 如果为点击选中的实例则不做样式修改
  159. if (this.selectItem && item == this.selectItem) return;
  160. item.fillColor = new SColor("#E1F2FF");
  161. item.strokeColor = new SColor("#E1F2FF");
  162. },
  163. // 鼠标事件移出
  164. onMouseleave(item, e) {
  165. // 如果为点击选中的实例则不做样式修改
  166. if (this.selectItem && item == this.selectItem) return;
  167. item.fillColor = new SColor("#F0F3F7");
  168. item.strokeColor = new SColor("#F0F3F7");
  169. },
  170. // 清空画布
  171. clearImg() {
  172. this.scene = new eventScene();
  173. this.scene.vueOnMouseDown = this.onMousedown;
  174. if (this.view) {
  175. this.view.update();
  176. }
  177. },
  178. },
  179. watch: {
  180. // 监听key
  181. dataKey: {
  182. handler(val) {
  183. if (val) {
  184. this.init();
  185. }
  186. },
  187. immediate: true,
  188. },
  189. },
  190. created() {
  191. this.clearImg();
  192. },
  193. mounted() {
  194. // 获取 canvas 的宽高
  195. this.canvasWidth = 800;
  196. this.canvasHeight = 600;
  197. // 初始化场景类
  198. this.view = new SGraphView("floorMap4");
  199. if (this.scene) {
  200. this.view.scene = this.scene;
  201. }
  202. },
  203. };
  204. </script>