drawFloor.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div id="drawFloor" v-loading="canvasLoading">
  3. <canvas id="floorCanvas" :width="cadWidth" :height="cadHeight" ref="canvas"></canvas>
  4. </div>
  5. </template>
  6. <script>
  7. import eventBus from "./bus.js";
  8. import { SGraphyView } from "@sybotan-web/graphy/lib";
  9. import { FloorScene } from "cad-engine";
  10. import { SColor } from "@sybotan-web/draw/lib";
  11. export default {
  12. data() {
  13. return {
  14. drawMainScene: null,
  15. view: null,
  16. dataKey: '',
  17. cadWidth: 800,
  18. cadHeight: 600,
  19. canvasLoading: false
  20. };
  21. },
  22. mounted() {
  23. // this.initGraphy('3af6d175c34e11e993ac85337be80696');
  24. // let that = this;
  25. // eventBus.$on("suitableRatios", function () {
  26. // that.view.fitSceneToView();
  27. // });
  28. // eventBus.$on("changeRatios", function (val) {
  29. // that.changeRatios(val);
  30. // });
  31. // eventBus.$on("downImgs", function (val) {
  32. // that.view.saveImage("saveImage" + new Date(), "png");
  33. // });
  34. // eventBus.$on("openDrags", function (val) {
  35. // if (val) {
  36. // }
  37. // });
  38. this.cadWidth = document.getElementById("drawFloor").offsetWidth;
  39. this.cadHeight = document.getElementById("drawFloor").offsetHeight;
  40. },
  41. methods: {
  42. clickItem(item) {
  43. this.$emit("clickGraphyItem", item);
  44. },
  45. // 单个个体绘制颜色
  46. drawItemColor(item, color) {
  47. item.fillColor = new SColor(color); //需要缓存的边框
  48. item.cacheFillColor = new SColor(color); //需要
  49. },
  50. // 绘制所有的item
  51. drawAllItemColor() {
  52. this.drawMainScene.root.children.forEach((item, index) => {
  53. let color = this.initColor[index % 10];
  54. this.drawItemColor(item, color);
  55. });
  56. },
  57. initGraphy(ModelId) {
  58. this.dataKey = ModelId
  59. if (!this.dataKey) {
  60. return;
  61. }
  62. this.canvasLoading = true
  63. this.clearGraphy()
  64. // 初始化view类
  65. this.view = new SGraphyView("floorCanvas");
  66. this.drawMainScene = new FloorScene(null);
  67. let that = this;
  68. this.drawMainScene.getFloorData('/modelapi/base-graph/query', { ModelId: ModelId }).then(res => {
  69. that.view.scene = that.drawMainScene
  70. that.view.fitSceneToView();
  71. this.canvasLoading = false
  72. })
  73. if (this.isScale) {
  74. this.cancelScale(this.view);
  75. }
  76. },
  77. // 单个item 高亮
  78. heightLightitem(item, highlightColor) {
  79. // this.drawItemColor(item, highlightColor);
  80. },
  81. // 取消放大缩小
  82. cancelScale(view) {
  83. // view.wheelZoom = 1;
  84. },
  85. // 左键长按控制canvas的坐标
  86. leftClickMove(a, b) {
  87. // console.log('move',a,b)
  88. },
  89. changeRatios(val) {
  90. //计算缩放比例
  91. this.view.scale = val;
  92. },
  93. clearGraphy() {
  94. if(this.drawMainScene){
  95. this.drawMainScene.root.children = null
  96. this.drawMainScene = null;
  97. this.view = null;
  98. }
  99. }
  100. },
  101. watch: {
  102. findGraphyItemId(n) {
  103. if (n) {
  104. this.heightLightitem();
  105. }
  106. }
  107. }
  108. };
  109. </script>
  110. <style scoped lang="less">
  111. #drawFloor {
  112. width: 100%;
  113. height: 100%;
  114. position: relative;
  115. }
  116. </style>