canvasProjectInfo.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="canvasProjectInfoPanel">
  3. <canvas id="canvasProjectInfo" width="1000" height="500"></canvas>
  4. <canvas id="canvasProjectInfoA" width="1000" height="500"></canvas>
  5. </div>
  6. </template>
  7. <script>
  8. //import from '';
  9. export default {
  10. name: "canvasProjectInfo", // 任务详情中的canvas
  11. components: {},
  12. data() {
  13. return {
  14. // modelImgSrc: require("@/assets/common/image/others/carTopView.png"),
  15. sensorSrc1: require("@/assets/common/image/sensor/l1.png"),
  16. sensorSrc2: require("@/assets/common/image/sensor/l2.png"),
  17. sensorSrc3: require("@/assets/common/image/sensor/l3.png"),
  18. sensorSrc5: require("@/assets/common/image/sensor/l5.png"),
  19. ctx: null,
  20. ctxBg: null,
  21. imgBg: null,
  22. imgIcon1: null,
  23. imgIcon2: null,
  24. imgIcon3: null,
  25. imgIcon5: null,
  26. rate: 70, // 换算比例
  27. };
  28. },
  29. props: {
  30. configList: {
  31. type: Object,
  32. default: {
  33. camera: [],
  34. ogt: [],
  35. lidar: [],
  36. gps: [],
  37. },
  38. },
  39. modelImgSrc: {
  40. type: String,
  41. default: require("@/assets/common/image/others/carTopView.png"),
  42. },
  43. },
  44. watch: {
  45. modelImgSrc() {
  46. this.drawBg();
  47. },
  48. },
  49. methods: {
  50. draw(data, type) {
  51. let rate = this.rate;
  52. data.x = data.sensorX;
  53. data.y = data.sensorY;
  54. data.h = data.sensorH;
  55. if (data.x === "" || data.y === "" || data.h === "") return;
  56. // this.imgIcon.src = src;
  57. let x = +data.y * rate;
  58. let y = +data.x * rate;
  59. let h1 = 90 - +data.h / 2;
  60. let h2 = 90 + +data.h / 2;
  61. // this.ctx.drawImage(this.imgIcon, x - 6, y - 6, 20.5, 14.5);
  62. let icon = null;
  63. if (type === 1) {
  64. icon = this.imgIcon1;
  65. } else if (type === 2) {
  66. icon = this.imgIcon2;
  67. } else if (type === 3) {
  68. icon = this.imgIcon3;
  69. } else if (type === 5) {
  70. icon = this.imgIcon5;
  71. }
  72. this.ctx.drawImage(icon, x - 6, y - 6, 20, 20);
  73. this.ctx.beginPath();
  74. //定义起点
  75. this.ctx.moveTo(x, y);
  76. //以起点为圆心,画一个半径为100的圆弧
  77. this.ctx.arc(x, y, 200, (h1 * Math.PI) / 180, (h2 * Math.PI) / 180);
  78. this.ctx.closePath();
  79. this.ctx.fillStyle = "rgba(252,222,147,0.54)";
  80. this.ctx.fill();
  81. },
  82. drawBg() {
  83. this.ctxBg.clearRect(0, 0, 1000, 500);
  84. this.imgBg.src = this.modelImgSrc;
  85. this.ctxBg.drawImage(this.imgBg, 0, 0, 1000, 500);
  86. },
  87. },
  88. mounted() {
  89. $(document).ready(() => {
  90. this.ctx = document
  91. .getElementById("canvasProjectInfo")
  92. .getContext("2d");
  93. this.ctxBg = document
  94. .getElementById("canvasProjectInfoA")
  95. .getContext("2d");
  96. this.ctx.translate(960, 250);
  97. this.ctx.rotate(Math.PI / 2);
  98. this.imgBg = new Image();
  99. this.imgBg.src = this.modelImgSrc;
  100. this.imgBg.onload = () => {
  101. this.ctxBg.drawImage(this.imgBg, 0, 0, 1000, 500);
  102. this.imgIcon1 = new Image();
  103. this.imgIcon1.src = this.sensorSrc1;
  104. this.imgIcon1.onload = () => {
  105. this.configList.camera.forEach((i) => {
  106. this.draw(i, 1);
  107. });
  108. };
  109. this.imgIcon2 = new Image();
  110. this.imgIcon2.src = this.sensorSrc2;
  111. this.imgIcon2.onload = () => {
  112. this.configList.ogt.forEach((i) => {
  113. this.draw(i, 2);
  114. });
  115. };
  116. this.imgIcon3 = new Image();
  117. this.imgIcon3.src = this.sensorSrc3;
  118. this.imgIcon3.onload = () => {
  119. this.configList.lidar.forEach((i) => {
  120. this.draw(i, 3);
  121. });
  122. };
  123. this.imgIcon5 = new Image();
  124. this.imgIcon5.src = this.sensorSrc5;
  125. this.imgIcon5.onload = () => {
  126. this.configList.gps.forEach((i) => {
  127. this.draw(i, 5);
  128. });
  129. };
  130. };
  131. });
  132. },
  133. };
  134. </script>
  135. <style lang="less" scoped>
  136. .canvasProjectInfoPanel {
  137. position: relative;
  138. canvas {
  139. width: 100%;
  140. }
  141. #canvasProjectInfo {
  142. position: relative;
  143. z-index: 1;
  144. }
  145. #canvasProjectInfoA {
  146. position: absolute;
  147. top: 0;
  148. left: 0;
  149. z-index: 0;
  150. }
  151. }
  152. </style>