drawFloor.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div id="drawFloor">
  3. <canvas :id="'canvas'+indexs" :width="cadWidth" :height="cadHeight"></canvas>
  4. </div>
  5. </template>
  6. <script>
  7. import {
  8. SGraphyView,
  9. SGraphyScene,
  10. SGraphyClockItem
  11. } from "@sybotan-web/graphy/lib";
  12. import axios from "axios";
  13. import { SPoint } from "@sybotan-web/base/lib";
  14. import { SPen, SPainter, SColor } from "@sybotan-web/draw";
  15. import { mainScene, SGraphyRectItem } from "@/assets/graphy/index.js";
  16. import eventBus from "./bus.js";
  17. export default {
  18. props: {
  19. cadWidth: {
  20. type: String | Number,
  21. default: "100%",
  22. required: false
  23. },
  24. cadHeight: {
  25. type: String | Number,
  26. default: "100%",
  27. required: false
  28. },
  29. dataKey: {
  30. type: String,
  31. default: "",
  32. required: true
  33. },
  34. point: {
  35. type: Array,
  36. default: [0, 0],
  37. required: false
  38. },
  39. pointWidth: {
  40. type: Number,
  41. default: 2000,
  42. required: false
  43. },
  44. initColor: {
  45. type: Array,
  46. default: function() {
  47. return [
  48. "#F9C3C3",
  49. "#FFD1BF",
  50. "#FFF3BF",
  51. "#D8F7C6",
  52. "#C6F2F6",
  53. "#DCE3C0",
  54. "#FAE6C9",
  55. "#E3D7F7",
  56. "#C4CBF8",
  57. "#DEC3F6"
  58. ];
  59. },
  60. required: false
  61. },
  62. findGraphyItemId: {
  63. //高亮的id
  64. type: String,
  65. default: "",
  66. required: false
  67. },
  68. highlightColor: {
  69. //高亮的color
  70. type: String,
  71. default: "#1abc9c",
  72. required: false
  73. },
  74. isScale: {
  75. //是否放大缩小
  76. type: Boolean,
  77. default: false,
  78. required: false
  79. },
  80. indexs: {
  81. //是否放大缩小
  82. type: Number | String,
  83. default: "",
  84. required: false
  85. }
  86. },
  87. data() {
  88. return {
  89. drawMainScene: null,
  90. view: null
  91. };
  92. },
  93. mounted() {
  94. this.initGraphy();
  95. let that = this;
  96. eventBus.$on("suitableRatios", function() {
  97. that.view.fitSceneToView();
  98. });
  99. eventBus.$on("changeRatios", function(val) {
  100. that.changeRatios(val)
  101. });
  102. },
  103. methods: {
  104. clickItem(item) {
  105. this.$emit("clickGraphyItem", item);
  106. },
  107. // 单个个体绘制颜色
  108. drawItemColor(item, color) {
  109. item.fillColor = new SColor(color); //需要缓存的边框
  110. item.cacheFillColor = new SColor(color); //需要
  111. },
  112. // 绘制所有的item
  113. drawAllItemColor() {
  114. this.drawMainScene.root.children.forEach((item, index) => {
  115. let color = this.initColor[index % 10];
  116. this.drawItemColor(item, color);
  117. });
  118. },
  119. initGraphy() {
  120. if (!this.dataKey) {
  121. return;
  122. }
  123. this.drawMainScene = null;
  124. this.view = null;
  125. // 初始化view类
  126. this.view = new SGraphyView("canvas" + this.indexs);
  127. this.drawMainScene = new mainScene(null);
  128. this.drawMainScene
  129. .urlGetData(
  130. "/image-service/common/file_get/Fl4201050001c72ff970d2ba11e8a57543fa3e79672520181120041440bim.jsonz?systemId=revit" ///////////测试路径
  131. // this.dataKey //开发url
  132. )
  133. .then(() => {
  134. // 将场景赋给view对图进行绘制
  135. this.view.scene = this.drawMainScene;
  136. // 自动缩放比例
  137. this.view.fitSceneToView();
  138. // 绘制地图颜色
  139. this.drawAllItemColor();
  140. // this.drawMainScene.click(this, this.clickItem);
  141. this.drawMainScene.mouseMove(this, this.leftClickMove);
  142. });
  143. if (this.isScale) {
  144. this.cancelScale(this.view);
  145. }
  146. },
  147. // 单个item 高亮
  148. heightLightitem(item, highlightColor) {
  149. this.drawItemColor(item, highlightColor);
  150. },
  151. // 取消放大缩小
  152. cancelScale(view) {
  153. view.wheelZoom = 1;
  154. },
  155. // 左键长按控制canvas的坐标
  156. leftClickMove(a, b) {
  157. // console.log('move',a,b)
  158. },
  159. changeRatios(val){
  160. console.log('val',val)
  161. }
  162. },
  163. watch: {
  164. dataKey(str) {
  165. if (str) {
  166. this.initGraphy();
  167. }
  168. },
  169. findGraphyItemId(str) {
  170. if (str) {
  171. this.heightLightitem();
  172. }
  173. }
  174. }
  175. };
  176. </script>
  177. <style scoped lang="less">
  178. #drawFloor {
  179. width: 100%;
  180. position: relative;
  181. height: auto;
  182. canvas {
  183. position: absolute;
  184. left: 50%;
  185. transform: translateX(-50%);
  186. }
  187. }
  188. </style>