| | |
| | | <template> |
| | | <div class="video-player"> |
| | | <canvas id="area-canvas" ></canvas> |
| | | <video ref="videoPlayer" :poster="poster" preload="auto" muted></video> |
| | | <div class="controls"> |
| | | <!-- 全屏 --> |
| | |
| | | </template> |
| | | <script> |
| | | import Wfs from "./wfs"; |
| | | |
| | | import VideoRuleData from "@/Pool/VideoRuleData"; |
| | | import TreeDataPool from "@/Pool/TreeData"; |
| | | import { getAllPolygon } from "@/api/polygon"; |
| | | export default { |
| | | name: "CameraPlayer", |
| | | props: { |
| | |
| | | data() { |
| | | return { |
| | | wfs: {}, |
| | | wfsId: 0 |
| | | wfsId: 0, |
| | | Camera: new VideoRuleData(), |
| | | canvasData: { |
| | | line: [], |
| | | rect: [], // {id:'uuid', name: '矩形1', location: [{ x: 20, y: 30 }, { x: 20, y: 60 }, { x: 100, y: 60 }, { x: 100, y: 30 }] } |
| | | arrow: [], |
| | | polygon: [] |
| | | }, |
| | | showProportion: 1.71, |
| | | canvas: null, |
| | | ctx: null |
| | | }; |
| | | }, |
| | | watch: { |
| | | "TreeDataPool.selectedNode": function(node){ |
| | | debugger; |
| | | this.initCanvas(node); |
| | | |
| | | }, |
| | | rtspUrl: function (newVal, oldVal) { |
| | | if (newVal !== oldVal) { |
| | | if (this.wfs.config) { |
| | |
| | | }, |
| | | fullScreen() { |
| | | this.$refs.videoPlayer.webkitRequestFullScreen(); |
| | | }, |
| | | // 回显cavas数据 |
| | | // 点击选中变色 将当前页面所有路径重绘判断当前鼠标的坐标在哪个图形内 如果不传坐标参数就是回显的方法 |
| | | clickSelect(e) { |
| | | this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); |
| | | let _this = this; // 集合中遍历需要将this转存一下使用 |
| | | _this.canvasData.line.forEach(function (v, i) { |
| | | _this.ctx.strokeStyle = "yellow"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "default"; |
| | | if (e && _this.ctx.isPointInStroke(e.offsetX, e.offsetY)) { |
| | | // 如果传入了事件坐标,就用isPointInStroke判断一下 |
| | | // 如果当前环境覆盖了该坐标,就将图形的index放到数组里 |
| | | // 当鼠标移入之后将当前的模式切换为选中模式 |
| | | _this.type = "0"; |
| | | _this.delCursor.type = "1"; |
| | | _this.delCursor.index = i; |
| | | // 将当前元素标红 |
| | | _this.ctx.strokeStyle = "red"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "pointer"; |
| | | } |
| | | }); |
| | | _this.canvasData.rect.forEach(function (v, i) { |
| | | _this.ctx.strokeStyle = "yellow"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "default"; |
| | | if (e && _this.ctx.isPointInPath(e.offsetX, e.offsetY)) { |
| | | // 如果传入了事件坐标,就用isPointInStroke判断一下 |
| | | // 当鼠标移入之后将当前的模式切换为选中模式 |
| | | _this.type = "0"; |
| | | _this.delCursor.type = "2"; |
| | | _this.delCursor.index = i; |
| | | // 将当前元素标红 |
| | | _this.ctx.strokeStyle = "red"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion); |
| | | _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "pointer"; |
| | | } |
| | | }); |
| | | _this.canvasData.arrow.forEach(function (v, i) { |
| | | _this.ctx.strokeStyle = "yellow"; |
| | | // _this.ctx.beginPath() |
| | | // _this.ctx.moveTo(v.location[0].x / 2, v.location[0].y / 2) |
| | | // _this.ctx.lineTo(v.location[1].x / 2, v.location[1].y / 2) |
| | | // _this.ctx.stroke() |
| | | _this.drawArrow( |
| | | _this.ctx, |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.location[1].x / _this.showProportion, |
| | | v.location[1].y / _this.showProportion, |
| | | 20, |
| | | 30, |
| | | "yellow" |
| | | ); // 绘制方法 |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "default"; |
| | | if (e && _this.ctx.isPointInStroke(e.offsetX, e.offsetY)) { |
| | | // 如果传入了事件坐标,就用isPointInStroke判断一下 |
| | | // 如果当前环境覆盖了该坐标,就将图形的index放到数组里 |
| | | // 当鼠标移入之后将当前的模式切换为选中模式 |
| | | _this.type = "0"; |
| | | _this.delCursor.type = "4"; |
| | | _this.delCursor.index = i; |
| | | // 将当前元素标红 |
| | | _this.ctx.strokeStyle = "red"; |
| | | // _this.ctx.beginPath() |
| | | // _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion) |
| | | // _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion) |
| | | // _this.ctx.stroke() |
| | | _this.drawArrow( |
| | | _this.ctx, |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.location[1].x / _this.showProportion, |
| | | v.location[1].y / _this.showProportion, |
| | | 20, |
| | | 30, |
| | | "red" |
| | | ); // 绘制方法 |
| | | _this.showRemarks( |
| | | v.location[0].x / _this.showProportion, |
| | | v.location[0].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "pointer"; |
| | | } |
| | | }); |
| | | _this.canvasData.polygon.forEach(function (v, i) { |
| | | if (v.location.length === 0) { |
| | | return; |
| | | } |
| | | _this.ctx.strokeStyle = "yellow"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | for (let i = 1; i < v.location.length; i++) { |
| | | _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportion); |
| | | } |
| | | _this.ctx.closePath(); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[v.location.length - 1].x / _this.showProportion, |
| | | v.location[v.location.length - 1].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "default"; |
| | | if (e && _this.ctx.isPointInPath(e.offsetX, e.offsetY)) { |
| | | // 如果传入了事件坐标,就用isPointInStroke判断一下 |
| | | // 如果当前环境覆盖了该坐标,就将图形的index放到数组里 |
| | | // 当鼠标移入之后将当前的模式切换为选中模式 |
| | | _this.type = "0"; |
| | | _this.delCursor.type = "5"; |
| | | _this.delCursor.index = i; |
| | | // 将当前元素标红 |
| | | _this.ctx.strokeStyle = "red"; |
| | | _this.ctx.beginPath(); |
| | | _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion); |
| | | for (let i = 1; i < v.location.length; i++) { |
| | | _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportion); |
| | | } |
| | | _this.ctx.closePath(); |
| | | _this.ctx.stroke(); |
| | | _this.showRemarks( |
| | | v.location[v.location.length - 1].x / _this.showProportion, |
| | | v.location[v.location.length - 1].y / _this.showProportion, |
| | | v.name |
| | | ); |
| | | _this.canvas.style.cursor = "pointer"; |
| | | } |
| | | }); |
| | | }, |
| | | // 回显图形备注 |
| | | showRemarks(x, y, remarks) { |
| | | this.ctx.moveTo(x, y - 10); // 因为放大之后是y-20,所以缩小版的为y-10 |
| | | this.ctx.fillStyle = "green"; // 设置填充颜色为绿色 |
| | | this.ctx.font = '10px "微软雅黑"'; // 设置字体 |
| | | this.ctx.textBaseline = "bottom"; // 设置字体底线对齐绘制基线 |
| | | this.ctx.textAlign = "left"; // 设置字体对齐的方式 |
| | | this.ctx.fillText(remarks, x, y - 10); // 填充文字 |
| | | }, |
| | | |
| | | async initCanvas(id){ |
| | | |
| | | this.canvas = document.querySelector("#area-canvas"); |
| | | this.ctx = this.canvas.getContext("2d"); |
| | | |
| | | // this.Camera.getPolygon(); |
| | | // console.log(this.Camera.canvasData); |
| | | const rsp = await getAllPolygon({ cameraId: id }); |
| | | debugger |
| | | if (rsp && rsp.success) { |
| | | this.canvasData = { |
| | | line: rsp.data.line, |
| | | arrow: rsp.data.arrow, |
| | | polygon: rsp.data.polygon, |
| | | //rect: rsp.data.rect |
| | | rect: [{id:'uuid', name: '矩形1', location: [{ x: 20, y: 30 }, { x: 20, y: 60 }, { x: 100, y: 60 }, { x: 100, y: 30 }] }] |
| | | }; |
| | | } |
| | | debugger |
| | | this.clickSelect(this.canvasData); |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.clickStart(); |
| | | |
| | | }, |
| | | beforeDestroy() { |
| | | this.wfs.destroy(); |
| | |
| | | </script> |
| | | |
| | | <style lang="scss"> |
| | | #area-canvas{ |
| | | width: 100%; |
| | | height: 100%; |
| | | background: transparent; |
| | | position: absolute; |
| | | top: 0; |
| | | left: 0; |
| | | } |
| | | video { |
| | | object-fit: fill; |
| | | width: 100%; |