From c748495762da3fdaeffa3bfbfde6607cd4f45a42 Mon Sep 17 00:00:00 2001 From: hanbaoshan <hanbaoshan@aiotlink.com> Date: 星期四, 24 十二月 2020 17:30:51 +0800 Subject: [PATCH] 实景图固定区域高度调整 --- src/pages/panoramicView/components/TracePlot.vue | 122 +++++++++++++++++++++++++++------------- 1 files changed, 82 insertions(+), 40 deletions(-) diff --git a/src/pages/panoramicView/components/TracePlot.vue b/src/pages/panoramicView/components/TracePlot.vue index f12095d..695e000 100644 --- a/src/pages/panoramicView/components/TracePlot.vue +++ b/src/pages/panoramicView/components/TracePlot.vue @@ -10,24 +10,22 @@ end-placeholder="缁撴潫鏃ユ湡" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00','23:59:59']" - ></el-date-picker> <el-button @click="searchData" size="small" type="primary" class="btn-search">鏌� 璇�</el-button> </div> - <!-- <p class="p-date" style="width:19%;vertical-align: top;"> - <el-date-picker - size="mini" - v-model="searchTime" - @change="searchData" - type="datetimerange" - start-placeholder="寮�濮嬫棩鏈�" - end-placeholder="缁撴潫鏃ユ湡" - value-format="yyyy-MM-dd HH:mm:ss" - :default-time="['00:00:00','23:59:59']" - style="width:99%;min-width:200px" - ></el-date-picker> - </p> --> - <canvas ref="trackArea" width="960" height="540" :style="{backgroundImage:`url(${panoramaPath})`}"></canvas> + + <!-- <canvas + ref="trackArea" + :width="cW" + :height="cH" + :style="{backgroundImage:`url(${panoramaPath})`}" + ></canvas> --> + <canvas + ref="trackArea" + :width="fixedW" + :height="fixedH" + :style="{backgroundImage:`url(${panoramaPath})`,backgroundSize:`${bgW}px ${bgH}px`}" + ></canvas> </div> </template> @@ -37,7 +35,9 @@ export default { data () { return { - panoramaPath:'', + cW: 0, + cH: 0, + panoramaPath: '', trackData: [], activeObjHashMap: {}, actObj: {}, @@ -47,46 +47,74 @@ //this.$moment().format("YYYY-MM-DD HH:mm:ss") ], timer: null, + colorArr: ['#F4DA40', '#0092BC', '#97D700', '#D0006F', '#D86018', '#653279', '#A45A2A', '#004B87', '#008C95', '#AA0061'], + searchStartTimeStamp: 0, + searchEndTimeStamp: 0, + fixedW: 960, + fixedH: 700, + bgW: 0, + bgH: 0 } }, mounted () { this.searchData(); - this.getPanoramaPic(); - this.timer = setInterval(()=>{ + this.getPanorama(); + this.timer = setInterval(() => { this.searchData(); - },7000); + }, 7000); }, - beforeDestroy(){ + beforeDestroy () { console.log('beforeDestroy') clearInterval(this.timer); }, methods: { - getPanoramaPic () { + getPanorama () { let _this = this; - getPanoramaPic().then(res=>{ - _this.panoramaPath = res.data.panoramaPath + getPanoramaPic().then(res => { + let { panoramaPath, width, height } = res.data; + _this.panoramaPath = panoramaPath + '?' + Math.random(); + _this.cW = width; + _this.cH = height; + //鍒ゆ柇闀垮姣� + let ratio = res.data.width/res.data.height; + if(ratio > (_this.fixedW/_this.fixedH)){ + _this.bgW = _this.fixedW; + _this.bgH = _this.bgW*res.data.height/res.data.width; + }else{ + _this.bgH = _this.fixedH; + _this.bgW = res.data.width*_this.bgH/res.data.height; + } }) }, drawTracePath () { - //let canvas = document.querySelector('#trackArea'); let canvas = this.$refs['trackArea']; let ctx = canvas.getContext('2d'); - ctx.clearRect(0,0,canvas.width,canvas.height); + ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.strokeStyle = 'yellow'; ctx.fillStyle = 'aqua'; //ctx.globalAlpha=0.5; - ctx.lineWidth = 2; + ctx.lineWidth = 3; //ctx.lineJoin='round'; ctx.lineCap = 'round'; for (var target in this.actObj) { ctx.beginPath(); - ctx.fillStyle = `rgb(${Math.floor(Math.random() * 20 + 220)},${Math.floor(Math.random() * 35 + 200)},${Math.floor(Math.random() * 55 + 200)})`; - ctx.strokeStyle = `rgb(${Math.floor(Math.random() * 20 + 220)},${Math.floor(Math.random() * 20 + 210)},${Math.floor(Math.random() * 55 + 200)})`; - ctx.fillRect(this.actObj[target][0].globalCoordX, this.actObj[target][0].globalCoordY, 9, 9); + //ctx.fillStyle = `rgb(${Math.floor(Math.random() * 55 + 150)},${Math.floor(Math.random() * 55 + 150)},${Math.floor(Math.random() * 55 + 150)})`; + ctx.fillStyle = this.actObj[target][0].color; + ctx.arc(this.actObj[target][0].globalCoordX, this.actObj[target][0].globalCoordY, 3, 0, Math.PI * 2); + ctx.fill(); + for (var i = 1; i < this.actObj[target].length; i++) { + ctx.beginPath(); + ctx.arc(this.actObj[target][i].globalCoordX, this.actObj[target][i].globalCoordY, 3, 0, Math.PI * 2); + ctx.fill() + } + } + for (var target in this.actObj) { + ctx.beginPath(); + //ctx.strokeStyle = `rgb(${Math.floor(Math.random() * 20 + 220)},${Math.floor(Math.random() * 20 + 210)},${Math.floor(Math.random() * 55 + 200)})`; + ctx.strokeStyle = this.actObj[target][0].color; ctx.moveTo(this.actObj[target][0].globalCoordX, this.actObj[target][0].globalCoordY); for (var i = 1; i < this.actObj[target].length; i++) { ctx.lineTo(this.actObj[target][i].globalCoordX, this.actObj[target][i].globalCoordY); - ctx.fillRect(this.actObj[target][i].globalCoordX, this.actObj[target][i].globalCoordY, 9, 9); } ctx.stroke(); } @@ -95,36 +123,51 @@ let _this = this; var param = { page: 1, - size: 70, + size: 100, searchTime: this.searchTime, alarmlevel: [], inputValue: '', tabs: [], tasks: [], treeNodes: [], - isAll: true + isAll: false }; getSearchList(param).then(res => { let filterArr = []; - res.data.datalist&&res.data.datalist.forEach(obj => { + if(Date.parse(_this.searchTime[0]) > _this.searchEndTimeStamp || Date.parse(_this.searchTime[1]) < _this.searchStartTimeStamp){ + _this.activeObjHashMap = []; + _this.actObj = {} + } + res.data.datalist && res.data.datalist.forEach(obj => { if (_this.activeObjHashMap[obj.activeObject.id] !== 1) { _this.activeObjHashMap[obj.activeObject.id] = 1 filterArr.push(obj) } }); + + _this.searchStartTimeStamp = Date.parse(_this.searchTime[0]); + _this.searchEndTimeStamp = Date.parse(_this.searchTime[1]); + filterArr.forEach(item => { item.activeObject.targetInfo.forEach(target => { if (target.targetType == 'UniquelID') { let attribute = JSON.parse(target.attribute) if (_this.actObj[target.targetId]) { - _this.actObj[target.targetId].push({ globalCoordX: attribute.globalCoordX, globalCoordY: attribute.globalCoordY }); + _this.actObj[target.targetId].unshift({ globalCoordX: attribute.globalCoordX, globalCoordY: attribute.globalCoordY }); } else { _this.actObj[target.targetId] = [{ globalCoordX: attribute.globalCoordX, globalCoordY: attribute.globalCoordY }]; } } }) }); - console.log(_this.actObj) + + var keyArr = Object.keys(_this.actObj); + for(var i = 0; i < keyArr.length; i++){ + _this.actObj[keyArr[i]].forEach(dot=>{ + dot.color = _this.colorArr[i%10]; + }) + } + console.log(new Date().getTime(), _this.actObj) _this.drawTracePath() }) } @@ -134,20 +177,19 @@ <style lang="scss"> .trace-plot { - .filter-bar{ + .filter-bar { width: 960px; margin: 20px auto; display: flex; align-items: center; flex-direction: end; - .btn-search{ - margin-left:20px; + .btn-search { + margin-left: 20px; } } canvas { - background: lightsteelblue; + //background: lightsteelblue; background-repeat: no-repeat; - } } </style> \ No newline at end of file -- Gitblit v1.8.0