MapDemo.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div>
  3. <el-button @click="showMap(1)">查看地图1</el-button>
  4. <el-button @click="showMap(2)">查看地图2</el-button>
  5. <canvas id="mapDemo" width="740" height="400" tabindex="0"></canvas>
  6. </div>
  7. </template>
  8. <script lang="ts">
  9. import { SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  10. import { SFloorParser } from "@persagy-web/big/lib";
  11. import { Component, Vue } from "vue-property-decorator";
  12. @Component
  13. export default class MapDemoCanvas extends Vue {
  14. view: SGraphView | undefined;
  15. scene: SGraphScene | undefined;
  16. map1 = require('../../../public/assets/map/1.json');
  17. map2 = require('../../../public/assets/map/2.json');
  18. /**
  19. * 页面挂载
  20. */
  21. mounted(): void {
  22. this.view = new SGraphView("mapDemo");
  23. this.init()
  24. };
  25. init() {
  26. this.showMap('1');
  27. };
  28. showMap(id: string) {
  29. const scene = new SGraphScene();
  30. this.view!!.scene = scene;
  31. let parser = new SFloorParser();
  32. // @ts-ignore
  33. parser.parseData(JSON.parse(JSON.stringify(this[`map${id}`].EntityList[0].Elements)));
  34. parser.spaceList.forEach(t => scene.addItem(t));
  35. parser.wallList.forEach(t => scene.addItem(t));
  36. parser.virtualWallList.forEach(t => scene.addItem(t));
  37. parser.doorList.forEach(t => scene.addItem(t));
  38. parser.columnList.forEach(t => scene.addItem(t));
  39. parser.casementList.forEach(t => scene.addItem(t));
  40. this.view!!.fitSceneToView();
  41. }
  42. }
  43. </script>
  44. <style scoped>
  45. canvas{
  46. border: 1px solid #eeeeee;
  47. outline: none;
  48. }
  49. </style>