surprise
2024-01-08 7e6b37afd1295c71bca1de595426330aff88420d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
  <div id="mapInfo" class="modelBox" v-drag>
    <div>
      <div class="modleTitle ">
        <div>属性信息</div>
        <div class="modelClose" @click="$store.state.isshowZhaiHai = false"> X</div>
      </div>
    </div>
    <div class="modelContent ">
      <div class="pdDialog" style="height: 100%;width: 100%; ">
        <canvas id="pdCanvas">
        </canvas>
    </div>
    </div>
 
 
  </div>
</template>
 
<script>
 
 
 
 
export default {
  name: "zhaiHaiInfo",
  components: {
 
  },
 
  data() {
    return {
      properties: null,
 
    };
  },
  mounted() {
    this.setLayerStart();
  },
  destroyed() {
 
  },
  methods: {
 
    setLayerStart() {
      this.properties = this.$store.state.showZhaiHaiImg;
      this.renderCanvas(this.properties)
    },
    renderCanvas(properties) {
      // 图片加载成功后
      const imgs = new Image()
      let imgSrc = "http://222.128.27.75:18010/thumb/production/road_detection_v4/"
        + properties.projectId + "/distress_track_processor_v5/output/"
        + properties.trackId + "/bev_video/"
        + properties.trackId + ".mp4/thumb-"
        + (properties.frameNo - 1) * 10 + ".jpg"
      imgs.crossOrigin = 'Anonymous'
      imgs.setAttribute('crossOrigin', 'Anonymous')
      imgs.src = imgSrc;
      imgs.onerror = () => {
        console.error('图片加载失败!');
        return false
      }
      var that = this;
      imgs.onload = () => {
        let imgHeight = 0,
          imgWidth = 0;
 
        let gridSize = [
          properties.G_WIDTH || 40, properties.G_WIDTH || 44
        ]
        const canvas = document.getElementById('pdCanvas');
        if (!canvas) { return }
        const ctx = canvas.getContext('2d');
        const _frame = document.getElementsByClassName('pdDialog')[0];
        const canvasWidth = _frame.offsetWidth;
        const canvasHeight = _frame.offsetHeight;
        // console.log(imgs)
 
        // var originalHeight = imgs.HEIGHT||761 / 1;
        // var originalWidth = imgs.WIDTH||1523 / 1;
        var originalHeight = Number(properties.HEIGHT) || 800 / 1;
        var originalWidth = Number(properties.WIDTH) || 1600 / 1;
        // 画布宽高比
        const canvasRatio = canvasWidth / canvasHeight;
        // 图片的宽高比
        var whRatio = originalWidth / originalHeight;
        // 图片相对于画布的尺寸进行调整
        // 如果图片的宽高比大于画布的宽高比
        if (whRatio > canvasRatio) {
          imgWidth = canvasWidth;
          imgHeight = imgWidth / whRatio;
        } else {
          imgHeight = canvasHeight;
          imgWidth = imgHeight * whRatio;
        }
        whRatio = imgWidth / imgHeight;
        canvas.height = imgHeight;
        canvas.width = imgWidth;
        //绘制背景图
        ctx.drawImage(
          imgs,
          0,
          0,
          imgWidth,
          imgHeight
        )
 
        var scaleGridSizeX = imgWidth / originalWidth * gridSize[0];
        var scaleGridSizeY = imgHeight / originalHeight * gridSize[1];
        var scaleGridSize = [
          scaleGridSizeX, scaleGridSizeY
        ];
        that.drawMarker(ctx, scaleGridSize, properties);
      }
    },
    drawMarker(ctx, scaleGridSize, properties) {
      let width = scaleGridSize[0];
      let height = scaleGridSize[0];
      let _grids = [];
  
      var grid = properties.grids._value
      if (!Array.isArray(grid)) {
        _grids = JSON.parse(grid)
      } else {
        _grids =grid;
      }
      _grids.forEach(m => {
        let x = m[0] * width;
        let y = m[1] * height;
        let markerImg = new Image();
 
        let markerImgSrc = 'https://webapi.kuandeng.net/gs/pddemo/pdmarker/' + properties.type + '.png';
        markerImg.crossOrigin = 'Anonymous'
        markerImg.setAttribute('crossOrigin', 'Anonymous')
        markerImg.src = markerImgSrc;
 
        markerImg.onload = () => {
          ctx.drawImage(markerImg,
            x,
            y,
            width,
            height)
        }
 
      })
    }
  }
};
</script>
 
<style scoped lang="less">
.modelBox {
  width: 40%;
  height: 50%;
  border: 1px solid white;
  top: 25%;
  left: 30%;
 
  background-color: rgba(0, 0, 0, 0.6); // #0048fd69 !important
  z-index: 9999;
  position: absolute;
 
 
  .modleTitle {
    height: 42px;
    width: 90%;
    background: #0048fd69 !important;
    border-bottom: 1px solid white;
    color: white;
    font-weight: 700px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0% 5%;
 
    .modelClose {
      height: 16px;
      width: 16px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(128, 128, 128, 0.6);
      font-size: 14x;
 
    }
  }
 
  .modelContent {
    width: 100%;
    height: calc(100% - 42px);
    // margin: 1%;
    // display: flex;
    // justify-content: space-between;
 
 
 
 
   
  }
 
 
}
</style>