wall.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <canvas id="wall" width="800" height="400" tabindex="0"/>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { SGraphScene, SGraphView } from "@persagy-web/graph/";
  8. import { SWallItem } from "@persagy-web/big/lib/items/floor/SWallItem";
  9. import { Component, Vue } from "vue-property-decorator";
  10. /**
  11. * 墙对象示例
  12. *
  13. * @author 郝洁 <haojie@persagy.com>
  14. */
  15. @Component
  16. export default class WallCanvas extends Vue {
  17. /** 实例化 view */
  18. view: SGraphView | undefined;
  19. /** 图中靠上位置的黑色矩形轮廓 */
  20. outline1 = [[{X: 120, Y: 10}, {X: 120, Y: 30}, {X: 10, Y: 30}, {X: 10, Y: 10}]];
  21. /** 图中靠下位置的,中间掏洞 */
  22. outline2 = [
  23. [{X: 120, Y: -30}, {X: 120, Y: -50}, {X: 10, Y: -50}, {X: 10, Y: -30}],
  24. [{X: 20, Y: -40}, {X: 20, Y: -45}, {X: 100, Y: -45}, {X: 100, Y: -40}]
  25. ];
  26. /**
  27. * 页面挂载
  28. */
  29. mounted() {
  30. this.init();
  31. };
  32. /**
  33. * 初始化加载
  34. */
  35. init() {
  36. this.view = new SGraphView('wall');
  37. const scene = new SGraphScene();
  38. this.view.scene = scene;
  39. // 只模拟了轮廓数据
  40. const item = new SWallItem(null, {OutLine: this.outline1});
  41. scene.addItem(item);
  42. // 只模拟了轮廓数据
  43. const item2 = new SWallItem(null, {OutLine: this.outline2});
  44. scene.addItem(item2);
  45. this.view.fitSceneToView();
  46. this.view.scalable = false;
  47. }
  48. }
  49. </script>
  50. <style scoped>
  51. </style>