index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <!-- 底图 -->
  2. <template>
  3. <div id="floor_base" v-loading="loading" ref="graphy">
  4. <canvas :id="`canvas${id}`" :width="canvasWidth" :height="canvasHeight" tabindex="0"></canvas>
  5. <!-- 地图底部操作按钮 -->
  6. <div class="strip-bottom">
  7. <canvasFun @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @saveJson="saveJson" @scale="scale" @showText="showText" ref="canvasFun"></canvasFun>
  8. </div>
  9. <room-box ref="boxRoom"></room-box>
  10. </div>
  11. </template>
  12. <script>
  13. import { SFengParser } from "@saga-web/feng-map";
  14. import { SFloorParser } from "@saga-web/big";
  15. import { FloorView } from "@/lib/FloorView";
  16. import { FloorScene } from "@/lib/FloorScene";
  17. import RoomBox from "@/views/room/index";
  18. import canvasFun from "@/components/floorMap/canvasFun";
  19. import { readGroup } from "@/api/public";
  20. import { STopologyParser } from "@/lib/parsers/STopologyParser";
  21. import { mapGetters, mapActions } from "vuex";
  22. import { SImageItem } from "@saga-web/graph/lib";
  23. import bus from "@/utils/bus.js"
  24. // import { uuid } from "@/components/mapClass/until";
  25. export default {
  26. data() {
  27. return {
  28. appName: "万达可视化系统",
  29. key: "23f30a832a862c58637a4aadbf50a566",
  30. mapServerURL: `/wdfn`,
  31. canvasWidth: 1100,
  32. canvasHeight: 800,
  33. loading: false, // 限制重复查询
  34. view: null,
  35. urlMsg: {},
  36. canvasID: "canvas",
  37. floorid: "", //楼层id
  38. topologyParser: null, // 解析器数据
  39. };
  40. },
  41. props: {
  42. id: {
  43. default: "1",
  44. type: String
  45. },
  46. categoryId: {
  47. default: "",
  48. type: String
  49. },
  50. loadName: null,
  51. type: null
  52. },
  53. components: { RoomBox, canvasFun },
  54. computed: {
  55. ...mapGetters(["plazaId", "fmapID", "haveFengMap"])
  56. },
  57. methods: {
  58. ...mapActions(["getfmapID"]),
  59. init(floorid) {
  60. this.loading = true;
  61. this.floorid = floorid;
  62. setTimeout(() => {
  63. if (this.haveFengMap) {
  64. this.clearGraphy();
  65. this.scene = new FloorScene();
  66. this.scene.selectContainer.connect(
  67. "listChange",
  68. this,
  69. this.listChange
  70. );
  71. if (this.canvasID != `canvas${this.id}`) {
  72. this.canvasID = `canvas${this.id}`;
  73. }
  74. this.parserData(floorid);
  75. }
  76. }, 100);
  77. },
  78. parserData(floor) {
  79. if (floor == "g80") {
  80. // 屋顶
  81. if (window.fengmapData.frImg) {
  82. let imgItem = new SImageItem(
  83. null,
  84. `${this.mapServerURL}/webtheme/${this.fmapID}/${window.fengmapData.frImg}`
  85. );
  86. this.scene.addItem(imgItem);
  87. this.view.scene = this.scene;
  88. this.view.minScale = this.view.scale;
  89. if (this.$refs.canvasFun) {
  90. this.$refs.canvasFun.everyScale = this.view.scale;
  91. }
  92. this.view.fitSceneToView();
  93. }
  94. } else {
  95. if (window.fengmapData.gnameToGid[floor]) {
  96. window.fengmapData.parseData(
  97. window.fengmapData.gnameToGid[floor],
  98. res => {
  99. if (res.err) {
  100. console.log("errr", res.err);
  101. return;
  102. }
  103. const fParser = new SFloorParser(null);
  104. fParser.parseData(res);
  105. fParser.spaceList.forEach(t => {
  106. // t.selectable = true;
  107. this.scene.addItem(t);
  108. });
  109. fParser.wallList.forEach(t => this.scene.addItem(t));
  110. fParser.virtualWallList.forEach(t => this.scene.addItem(t));
  111. fParser.doorList.forEach(t => this.scene.addItem(t));
  112. fParser.columnList.forEach(t => this.scene.addItem(t));
  113. fParser.casementList.forEach(t => this.scene.addItem(t));
  114. this.view.scene = this.scene;
  115. this.view.minScale = this.view.scale;
  116. if (this.$refs.canvasFun) {
  117. this.$refs.canvasFun.everyScale = this.view.scale;
  118. }
  119. this.view.fitSceneToView();
  120. //console.log('success')
  121. }
  122. );
  123. } else {
  124. console.log("楼层不正确");
  125. }
  126. }
  127. this.readGroup(this.floorid).then(data => {
  128. this.loading = false;
  129. if (data.Data.length > 0) {
  130. //console.log(data.data.Data[0].ID)
  131. this.$cookie.set("graphId", data.Data[0].ID, 3);
  132. }
  133. this.topologyParser = new STopologyParser(null);
  134. this.topologyParser.parseData(data.Data[0].Elements);
  135. // 多边形
  136. this.topologyParser.zoneLegendList.forEach(t => {
  137. this.scene.addItem(t);
  138. });
  139. // 增加文字
  140. this.topologyParser.textMarkerList.forEach(t => {
  141. this.scene.addItem(t);
  142. });
  143. // 增加图片
  144. this.topologyParser.imageMarkerList.forEach(t => {
  145. this.scene.addItem(t);
  146. });
  147. // 增加直线
  148. this.topologyParser.lineMarkerList.forEach(t => {
  149. this.scene.addItem(t);
  150. });
  151. // 增加图标类图例
  152. this.topologyParser.imageLegendList.forEach(t => {
  153. this.scene.addItem(t);
  154. });
  155. // 增加管线类
  156. // 增加图标类图例
  157. this.topologyParser.relationList.forEach(t => {
  158. this.scene.addItem(t);
  159. });
  160. this.view.fitSceneToView();
  161. });
  162. },
  163. clearGraphy() {
  164. if (this.view) {
  165. this.view.scene = null;
  166. return;
  167. }
  168. this.view = new FloorView(`canvas${this.id}`);
  169. },
  170. listChange(item, ev) {
  171. let name = ev[0][0].data.Name;
  172. if (name.slice(name.length - 2, name.length) == "机房") {
  173. this.$refs.boxRoom.open({ name: name, type: this.type });
  174. }
  175. },
  176. // 适配底图到窗口
  177. fit() {
  178. this.view.fitSceneToView();
  179. },
  180. // 保存为png
  181. savePng() {
  182. this.view.saveImage(`${this.loadName}.png`, "png");
  183. //console.log(`${this.loadName}.png`)
  184. },
  185. // 保存为svg
  186. saveSvg() {
  187. this.view.saveSceneSvg(`${this.loadName}.svg`, 6400, 4800);
  188. },
  189. // 保存为json
  190. saveJson() {
  191. this.view.saveFloorJson(`${this.loadName}.json`);
  192. },
  193. // 缩放
  194. scale(val) {
  195. if (!this.view) {
  196. return;
  197. }
  198. let scale = this.view.scale;
  199. this.view.scaleByPoint(
  200. val / scale,
  201. this.canvasWidth / 2,
  202. this.canvasHeight / 2
  203. );
  204. },
  205. showText() {
  206. this.topologyParser.zoneLegendList.forEach(t => {
  207. t.showText = !t.showText;
  208. })
  209. },
  210. // 读取数据
  211. readGroup(FloorID) {
  212. const data = {
  213. BuildingID: "1",
  214. FloorID: FloorID,
  215. categoryId: this.categoryId ? this.categoryId : this.$cookie.get("categoryId"),
  216. projectId: this.urlMsg.ProjectID
  217. };
  218. return readGroup(data);
  219. },
  220. // 地图尺寸
  221. mapSize() {
  222. if (window.screen.height == "768") {
  223. this.canvasWidth = this.$refs.graphy.offsetWidth;
  224. this.canvasHeight = this.$refs.graphy.offsetHeight - 100;
  225. } else {
  226. this.canvasWidth = this.$refs.graphy.offsetWidth;
  227. this.canvasHeight = 900;
  228. }
  229. },
  230. getEvent() {
  231. bus.$on('changeShow', res => {
  232. this.topologyParser.zoneLegendList.forEach(t => {
  233. let id = t.data.GraphElementId
  234. t.maskFlag = !(res.indexOf(id) > -1)
  235. })
  236. this.topologyParser.textMarkerList.forEach(t => {
  237. let id = t.data.GraphElementId
  238. t.maskFlag = !(res.indexOf(id) > -1)
  239. });
  240. this.topologyParser.imageMarkerList.forEach(t => {
  241. let id = t.data.GraphElementId
  242. t.maskFlag = !(res.indexOf(id) > -1)
  243. });
  244. this.topologyParser.lineMarkerList.forEach(t => {
  245. let id = t.data.GraphElementId
  246. t.maskFlag = !(res.indexOf(id) > -1)
  247. });
  248. this.topologyParser.imageLegendList.forEach(t => {
  249. let id = t.data.GraphElementId
  250. t.maskFlag = !(res.indexOf(id) > -1)
  251. });
  252. this.topologyParser.relationList.forEach(t => {
  253. let id = t.data.GraphElementId
  254. t.maskFlag = !(res.indexOf(id) > -1)
  255. });
  256. })
  257. }
  258. },
  259. watch: {
  260. "view.scale": {
  261. handler(n) {
  262. if (this.$refs.canvasFun) {
  263. let s = (n * 10) / this.view.minScale;
  264. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
  265. }
  266. }
  267. },
  268. haveFengMap(val) {
  269. if (val) {
  270. this.init(this.floorid);
  271. }
  272. }
  273. },
  274. mounted() {
  275. this.mapSize();
  276. this.getEvent()
  277. },
  278. created() {
  279. this.urlMsg = {
  280. categoryId: this.$cookie.get("categoryId"),
  281. ProjectID: this.plazaId,
  282. BuildingID: "1",
  283. FloorID: this.$cookie.get("floorMapId") || "f1",
  284. fmapID: this.fmapID
  285. };
  286. }
  287. };
  288. </script>
  289. <style lang="less" scoped>
  290. #floor_base {
  291. position: relative;
  292. .fengMap {
  293. position: fixed;
  294. width: 100px;
  295. height: 100px;
  296. z-index: -1;
  297. }
  298. .strip-bottom {
  299. position: absolute;
  300. right: 0;
  301. bottom: 40px;
  302. width: 100%;
  303. }
  304. }
  305. </style>