index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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('listChange', this, this.listChange)
  67. if (this.canvasID != `canvas${this.id}`) {
  68. this.canvasID = `canvas${this.id}`
  69. }
  70. this.parserData(floorid)
  71. }
  72. }, 100)
  73. },
  74. parserData(floor) {
  75. if (floor == 'g80') {
  76. // 屋顶
  77. if (window.fengmapData.frImg) {
  78. let imgItem = new SImageItem(null, `${this.mapServerURL}/webtheme/${this.fmapID}/${window.fengmapData.frImg}`)
  79. this.scene.addItem(imgItem)
  80. this.view.scene = this.scene
  81. this.view.minScale = this.view.scale
  82. if (this.$refs.canvasFun) {
  83. this.$refs.canvasFun.everyScale = this.view.scale
  84. }
  85. this.view.fitSceneToView()
  86. }
  87. } else {
  88. if (window.fengmapData.gnameToGid[floor]) {
  89. window.fengmapData.parseData(window.fengmapData.gnameToGid[floor], res => {
  90. if (res.err) {
  91. console.log('errr', res.err)
  92. return
  93. }
  94. const fParser = new SFloorParser(null)
  95. fParser.parseData(res)
  96. fParser.spaceList.forEach(t => {
  97. // t.selectable = true;
  98. this.scene.addItem(t)
  99. })
  100. fParser.wallList.forEach(t => this.scene.addItem(t))
  101. fParser.virtualWallList.forEach(t => this.scene.addItem(t))
  102. fParser.doorList.forEach(t => this.scene.addItem(t))
  103. fParser.columnList.forEach(t => this.scene.addItem(t))
  104. fParser.casementList.forEach(t => this.scene.addItem(t))
  105. this.view.scene = this.scene
  106. this.view.minScale = this.view.scale
  107. if (this.$refs.canvasFun) {
  108. this.$refs.canvasFun.everyScale = this.view.scale
  109. }
  110. this.view.fitSceneToView()
  111. //console.log('success')
  112. })
  113. } else {
  114. console.log('楼层不正确')
  115. }
  116. }
  117. this.readGroup(this.floorid).then(data => {
  118. this.loading = false
  119. if (data.Result == 'failure') {
  120. this.$message({
  121. message: data.Message,
  122. type: 'warning'
  123. })
  124. this.$store.commit('SETISMESSAGE', false)
  125. // 一会回来存这个
  126. } else {
  127. this.$store.commit('SETISMESSAGE', true)
  128. }
  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(val / scale, this.canvasWidth / 2, this.canvasHeight / 2)
  200. },
  201. showText(val) {
  202. this.topologyParser.zoneLegendList.forEach(t => {
  203. t.showText = val
  204. })
  205. },
  206. // 读取数据
  207. readGroup(FloorID) {
  208. const data = {
  209. BuildingID: '1',
  210. FloorID: FloorID,
  211. categoryId: this.categoryId ? this.categoryId : this.$cookie.get('categoryId'),
  212. projectId: this.urlMsg.ProjectID
  213. }
  214. return readGroup(data)
  215. },
  216. // 地图尺寸
  217. mapSize() {
  218. if (window.screen.height == '768') {
  219. this.canvasWidth = this.$refs.graphy.offsetWidth
  220. this.canvasHeight = this.$refs.graphy.offsetHeight - 100
  221. } else {
  222. this.canvasWidth = this.$refs.graphy.offsetWidth
  223. this.canvasHeight = 900
  224. }
  225. },
  226. getEvent() {
  227. bus.$on('changeShow', res => {
  228. this.topologyParser.zoneLegendList.forEach(t => {
  229. let id = t.data.GraphElementId
  230. t.maskFlag = !(res.indexOf(id) > -1)
  231. })
  232. this.topologyParser.textMarkerList.forEach(t => {
  233. let id = t.data.GraphElementId
  234. t.maskFlag = !(res.indexOf(id) > -1)
  235. })
  236. this.topologyParser.imageMarkerList.forEach(t => {
  237. let id = t.data.GraphElementId
  238. t.maskFlag = !(res.indexOf(id) > -1)
  239. })
  240. this.topologyParser.lineMarkerList.forEach(t => {
  241. let id = t.data.GraphElementId
  242. t.maskFlag = !(res.indexOf(id) > -1)
  243. })
  244. this.topologyParser.imageLegendList.forEach(t => {
  245. let id = t.data.GraphElementId
  246. t.maskFlag = !(res.indexOf(id) > -1)
  247. })
  248. this.topologyParser.relationList.forEach(t => {
  249. let id = t.data.GraphElementId
  250. t.maskFlag = !(res.indexOf(id) > -1)
  251. })
  252. })
  253. }
  254. },
  255. watch: {
  256. 'view.scale': {
  257. handler(n) {
  258. if (this.$refs.canvasFun) {
  259. let s = (n * 10) / this.view.minScale
  260. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s
  261. }
  262. }
  263. },
  264. haveFengMap(val) {
  265. if (val) {
  266. this.init(this.floorid)
  267. }
  268. }
  269. },
  270. mounted() {
  271. this.mapSize()
  272. this.getEvent()
  273. },
  274. created() {
  275. this.urlMsg = {
  276. categoryId: this.$cookie.get('categoryId'),
  277. ProjectID: this.plazaId,
  278. BuildingID: '1',
  279. FloorID: this.$cookie.get('floorMapId') || 'f1',
  280. fmapID: this.fmapID
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="less" scoped>
  286. #floor_base {
  287. position: relative;
  288. .fengMap {
  289. position: fixed;
  290. width: 100px;
  291. height: 100px;
  292. z-index: -1;
  293. }
  294. .strip-bottom {
  295. position: absolute;
  296. right: 0;
  297. bottom: 40px;
  298. width: 100%;
  299. }
  300. }
  301. </style>