张卓
2022-09-29 4ef1c909df36c48f7f040e9ec408fc15e6745e71
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<template>
  <div class="main_body">
    <el-container style="height: 100%">
      <el-aside width="300px" style="background-color: rgb(238, 241, 246)">
        <el-date-picker
          v-model="value1"
          style="margin-left: 10px; width: 280px; height: 40px"
          type="date"
          placeholder="选择日期"
          :picker-options="pickerOptions"
        />
      </el-aside>
      <el-main>
        <div
          style="
          position: fixed;
          z-index: 20;
          padding-left: 20px;
          height: 75px;
          line-height: 80px;
          width: 100%;
          font-size: 18px;
          font-weight: bold;
          background-color: rgba(    192,192,192, 0.4);"
        >
          <el-radio-group v-model="defautRadio.name" size="medium" @change="selectRedio">
            <el-radio-button v-for="(item, key) in radio" :key="key" :label="item.name" />
          </el-radio-group>
        </div>
        <div id="container" style="width:100%; height:100%;resize:both;z-index: 0" />
      </el-main>
    </el-container>
  </div>
</template>
 
<script>
 
import axios from 'axios'
import { getToken } from '@/utils/auth'
 
export default {
  data() {
    return {
      dates: [], // 存放date数组
      // 禁用指定日期
      value1: '',
      value: [],
      map: null,
      radio: [
        { code: 'a34004', name: 'PM2.5' },
        { code: 'a34002', name: 'PM10' },
        { code: 'a21026', name: 'SO2' },
        { code: 'a21004', name: 'NO2' },
        { code: 'a21005', name: 'CO' },
        { code: 'a05024', name: 'O3' },
        { code: 'a99054', name: 'TVOC' }
      ],
      defautRadio: { code: 'a34004', name: 'PM2.5' },
      Layler: null, // 存放图层
      textMarkers: { code: '', markers: [] }, // 存放文本标注
      levelSensor: [35, 75, 115, 150, 250]
    }
  },
  // 改变时触发计算属性
  computed: {
    pickerOptions: function() {
      var _this = this
      return {
        disabledDate(time) {
          // console.log(time.getFullYear() + '-' + ((time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)) + '-' + (time.getDate() < 10 ? '0' + time.getDate() : time.getDate()))
          // console.log(_this.dates)
          for (let i = 0; i < _this.dates.length; i++) {
            if (time.getTime() === _this.dates[i]) {
              // console.log(_this.dates[i])
              return false
            } else {
              return true
            }
          }
        }
      }
    }
  },
  mounted() {
    this.initMap()
    this.getDate()
  },
  methods: {
    lnglatToG20(lnglat) {
      lnglat = this.map.lngLatToGeodeticCoord(lnglat)
      lnglat.x = AMap.Util.format(lnglat.x, 3)
      lnglat.y = AMap.Util.format(lnglat.y, 3)
      return lnglat
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    // 选中redio
    selectRedio(item) {
      this.map.remove(this.textMarkers.markers)
      this.map.remove(this.Layler)
      this.addLayers(item)
    },
    // 初始化地图
    initMap() {
      var map = new AMap.Map('container', {
        resizeEnable: true,
        rotateEnable: true,
        pitchEnable: true,
        zoom: 17,
        pitch: 80,
        rotation: -15,
        viewMode: '3D', // 开启3D视图,默认为关闭
        buildingAnimation: true, // 楼块出现是否带动画
        expandZoomRange: true,
        zooms: [3, 20],
        center: [120.9781494, 31.4265156]
      })
      this.map = map
    },
    // 添加图层
    addLayers(name) {
      let code = ''
      for (let i = 0; i < this.radio.length; i++) {
        if (name === this.radio[i].name) {
          code = this.radio[i].code
        }
      }
      if (code === 'a34002') {
        this.levelSensor = [50, 150, 250, 350, 420]
      } else if (code === 'a21026') {
        this.levelSensor = [150, 500, 650, 800, 1600]
      } else if (code === 'a21004') {
        this.levelSensor = [100, 200, 700, 1200, 2340]
      } else if (code === 'a21005') {
        this.levelSensor = [5, 10, 35, 60, 90]
      } else if (code === 'a05024') {
        this.levelSensor = [160, 200, 300, 400, 800]
      } else if (code === 'a99054') {
        this.levelSensor = [1.5, 3, 5]
      }
      console.log('=======================')
      console.log(this.value)
      var object3Dlayer = new AMap.Object3DLayer({ zIndex: 110, opacity: 1 })
      var points3D = new AMap.Object3D.RoundPoints({
        eventSupport: true
      })
      points3D.transparent = true
 
      var lines = new AMap.Object3D.Line()
      var lineGeo = lines.geometry
      var geometry = points3D.geometry
      for (let i = 0; i < this.value.length; i++) {
        const obj = (this.value[i])
        console.log(66)
        if (!(obj.flylon === undefined)) {
          var center = this.lnglatToG20([obj.flylon, obj.flylat])
          if (i < this.value.length - 1) {
            const obj1 = (this.value[i + 1])
            if (!(obj1.flylon === undefined)) {
              var center1 = this.lnglatToG20([obj1.flylon, obj1.flylat])
              // 连线
              lineGeo.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              lineGeo.vertexColors.push(0.0497, 0.3419, 0.9301, 1)
              lineGeo.vertices.push(center1.x, center1.y, -(obj1.flyhig * 10))
              lineGeo.vertexColors.push(0.0497, 0.3419, 0.9301, 1)
              //
              // const distance = Math.sqrt((center1.x - center.x) * (center1.x - center.x) + (center1.y - center.y) * (center1.y - center.y) + (obj1.flyhig * 10 - obj.flyhig * 10) * (obj1.flyhig * 10 - obj.flyhig * 10))
              // console.log(distance)
            }
          }
          // 随机高度。Z 轴正方向指向地下,因此这里设置高度要添加负号指向反方向
          if (obj[code]) {
            if (Number(obj[code]) < this.levelSensor[0] && this.levelSensor[0] !== undefined) {
              geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              geometry.pointSizes.push(40)
              geometry.vertexColors.push(0, 0.8941, 0, 0.6)
            } else if (Number(obj[code]) < this.levelSensor[1] && this.levelSensor[1] !== undefined) {
              geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              geometry.pointSizes.push(40)
              geometry.vertexColors.push(1, 1, 0, 0.8)
            } else if (Number(obj[code]) < this.levelSensor[2] && this.levelSensor[2] !== undefined) {
              geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              geometry.pointSizes.push(40)
              geometry.vertexColors.push(1, 0.4941, 0, 0.8)
            } else if (Number(obj[code]) < this.levelSensor[3] && this.levelSensor[3] !== undefined) {
              geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              geometry.pointSizes.push(40)
              geometry.vertexColors.push(1, 0, 0, 0.8)
            } else if (Number(obj[code]) < this.levelSensor[4 && this.levelSensor[4] !== undefined]) {
              geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
              geometry.pointSizes.push(40)
              geometry.vertexColors.push(0.6000, 0, 0.2980, 0.8)
            } else {
              if (this.levelSensor[0] !== undefined) {
                geometry.vertices.push(center.x, center.y, -(obj.flyhig * 10))
                geometry.pointSizes.push(40)
                geometry.vertexColors.push(0.4941, 0.4941, 0.1373, 0.8)
              } else {
                continue
              }
            }
          }
 
          var A = new AMap.Text({
            text: obj[code],
            position: [obj.flylon, obj.flylat],
            height: (obj.flyhig * 10),
            verticalAlign: 'center',
            map: this.map,
            style: {
              'background-color': 'rgba(0,0,0,0)',
              'position': 'relative',
              'top': '-18px',
              'left': '6px',
              'width': '32px',
              'height': '32px',
              'font-size': '12px',
              'line-height': '32px',
              'border-radius': '100%',
              'border': 'none'
            }
            // 'border': 'none',
          })
          A.on('click', () => {
            alert(JSON.stringify(obj))
          })
          this.textMarkers.code = obj
          this.textMarkers.markers.push(A)
        }
        // geometry.pointAreas.push(0.3,0,0.7,0.5);
      }
      points3D.borderWeight = 3
      object3Dlayer.add(lines)
      object3Dlayer.add(points3D)
      this.map.add(object3Dlayer)
      this.Layler = object3Dlayer
    },
    // 获取组织下存在飞行记录的日期
    getDate() {
      axios.get('http://47.99.64.149:8081/uav/test', {
        params: {
          batch: '2021-07-08 01:00:00'
        },
        headers: {
          token: getToken()
        }
      }).then(res => {
        console.log('--------------------------------------')
        console.log(res)
        if (res.data.code === 0) {
          for (let i = 0; i < res.data.data.length; i++) {
            this.value.push(JSON.parse(res.data.data[i].value))
          }
        }
        this.addLayers('PM2.5')
      })
      // axios.get('http://47.99.64.149:8081/uav/queryDate', {
      //   params: {
      //     organizationId: this.$store.state.orgId
      //   },
      //   headers: {
      //     token: getToken()
      //   }
      // }).then(res => {
      //   this.dates = JSON.parse(JSON.stringify(res.data.data.datesStr))
      //   console.log('------------------------')
      //   // console.log(this.dates)
      //   const dates = []
      //   for (let i = 0; i < this.dates.length; i++) {
      //     const date = this.dates[i].replace(/-/g, '/')
      //     var timestamp = new Date(date).getTime()
      //     dates.push(timestamp)
      //   }
      //   this.dates = dates
      //   console.log(this.dates)
      // })
    }
 
  }
}
</script>
 
<style  lang="scss" scoped>
.main_body {
  border: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  position: relative;
}
.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
 
.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: left;
  line-height: 52px;
}
 
/deep/ .el-input__inner {
  height:40px;
}
/deep/ .el-picker-panel__body {
  width: 280px;
 }
.el-main {
  padding: 0;
  width: 100%;
  height: 100%;
}
 
body > .el-container {
  margin-bottom: 40px;
}
 
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}
 
.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-radio-button--medium .el-radio-button__inner {
  padding: 16px 20px;
  font-size: 14px;
  height: 38px;
  border-radius: 0;
  width: 80px;
}
</style>