Browse Source

[完善]预警框优化

beijing
邵佳豪 2 years ago
parent
commit
5f1ad0a69b
  1. 30
      src/app/pages/today-warning/get-out-of-line-details/get-out-of-line-details.component.ts

30
src/app/pages/today-warning/get-out-of-line-details/get-out-of-line-details.component.ts

@ -215,14 +215,12 @@ export class GetOutOfLineDetailsComponent implements OnInit {
//清空画布并且重新标绘 //清空画布并且重新标绘
clearCanvas(url) { clearCanvas(url) {
this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight); this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
var img = new Image(); let imgBg: any = document.getElementById("img");
img.src = url; imgBg.src = url;
img.onload = () => { imgBg.onload = () => {
// this.canvasWidth = img.width;
// this.canvasHeight = img.height;
window.setTimeout(() => { window.setTimeout(() => {
// 加载图片 // 加载图片
this.ctx.drawImage(img, 0, 0, this.canvasWidth, this.canvasHeight); this.ctx.drawImage(imgBg, 0, 0, this.canvasWidth, this.canvasHeight);
this.strokeRect(this.currentCoordinate); this.strokeRect(this.currentCoordinate);
}, 0); }, 0);
}; };
@ -235,17 +233,15 @@ export class GetOutOfLineDetailsComponent implements OnInit {
imgBg.onload = () => { imgBg.onload = () => {
this.canvasWidth = imgBg.offsetWidth; this.canvasWidth = imgBg.offsetWidth;
this.canvasHeight = imgBg.offsetHeight; this.canvasHeight = imgBg.offsetHeight;
const img = new Image(); const canvas: any = document.querySelector("#canvas");
img.src = imgBg.src; this.ctx = canvas.getContext("2d");
img.onload = () => { const cWidth = canvas.width,
const canvas: any = document.querySelector("#canvas"); cHeight = canvas.height;
this.ctx = canvas.getContext("2d"); setTimeout(() => {
const cWidth = canvas.width,
cHeight = canvas.height;
// 以图画底 // 以图画底
this.ctx.drawImage(img, 0, 0, cWidth, cHeight); this.ctx.drawImage(imgBg, 0, 0, cWidth, cHeight);
this.strokeRect(this.currentCoordinate); this.strokeRect(this.currentCoordinate);
}; }, 0);
}; };
} }
@ -329,10 +325,8 @@ export class GetOutOfLineDetailsComponent implements OnInit {
} }
this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight); this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
let imgBg: any = document.getElementById("img"); let imgBg: any = document.getElementById("img");
const img = new Image();
img.src = imgBg.src;
const canvas: any = document.querySelector("#canvas"); const canvas: any = document.querySelector("#canvas");
this.ctx.drawImage(img, 0, 0, canvas.width, canvas.height); this.ctx.drawImage(imgBg, 0, 0, canvas.width, canvas.height);
this.strokeRect(this.currentCoordinate); this.strokeRect(this.currentCoordinate);
} }

Loading…
Cancel
Save