quanyawei
2024-03-27 a5e288eead42db17f8715bc21326465648bc1c04
src/views/hotMap/index.vue
@@ -22,11 +22,10 @@
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-select
          <!-- <el-select
            v-model="orgId"
            size="small"
            placeholder="请选择"
            disabled
            @change="regionData"
          >
            <el-option
@@ -35,7 +34,15 @@
              :label="item.name"
              :value="item.id"
            />
          </el-select>
          </el-select> -->
          <el-cascader
            v-model="orgId"
            size="small"
            :options="orgData"
            :props="props"
            clearable
            @change="regionData"
          />
        </el-form-item>
        <el-form-item>
          <el-radio-group
@@ -78,7 +85,7 @@
        class="buttomColorLine"
      />
      <Main
        v-if="dateTimes.length > 0&&formInline.city!==''"
        v-if="dateTimes.length > 0"
        :options="options"
        :date-times="dateTimes"
        :date-type="formInline.dayType"
@@ -89,7 +96,7 @@
</template>
<script>
import dayjs from 'dayjs'
// import dayjs from 'dayjs'
import _ from 'lodash'
import selectHour from './components/selectHour.vue'
import Main from './components/timeLinePlay.vue'
@@ -102,11 +109,12 @@
      heatmap: null,
      markerClusterer: null,
      orgData: [],
      orgId: 71,
      props: { checkStrictly: true, label: 'name', value: 'id', children: 'children' },
      orgId: [],
      city: '苏州',
      formInline: {
        city: '鞍山市',
        cityCode: '210300',
        city: '',
        cityCode: '',
        dayType: 'hour',
        starTime: '',
        endTime: '',
@@ -118,13 +126,13 @@
        maxNumber: 500,
        src: require('@/assets/images/tl_PM10.png'),
        gradient: {
          '0': '#12a112',
          '0.1': '#12a112',
          '0.3': '#feff01',
          '0.5': '#fd8200',
          '0.7': '#fd0001',
          '0.84': '#95014b',
          '1': '#7e0226'
          0: '#12a112',
          0.1: '#12a112',
          0.3: '#feff01',
          0.5: '#fd8200',
          0.7: '#fd0001',
          0.84: '#95014b',
          1: '#7e0226'
        }},
      sensorArr: [
        { code: 'a34002',
@@ -132,91 +140,93 @@
          maxNumber: 500,
          src: require('@/assets/images/tl_PM10.png'),
          gradient: {
            '0': '#12a112',
            '0.1': '#12a112',
            '0.3': '#feff01',
            '0.5': '#fd8200',
            '0.7': '#fd0001',
            '0.84': '#95014b',
            '1': '#7e0226'
            0: '#12a112',
            0.1: '#12a112',
            0.3: '#feff01',
            0.5: '#fd8200',
            0.7: '#fd0001',
            0.84: '#95014b',
            1: '#7e0226'
          }},
        { code: 'a34004',
          name: 'PM2.5',
          maxNumber: 350,
          src: require('@/assets/images/tl_PM2.5.png'),
          gradient: {
            '0': '#12a112',
            '0.1': '#12a112',
            '0.21': '#feff01',
            '0.32': '#fd8200',
            '0.42': '#fd0001',
            '0.71': '#95014b',
            '1': '#7e0226'
            0: '#12a112',
            0.1: '#12a112',
            0.21: '#feff01',
            0.32: '#fd8200',
            0.42: '#fd0001',
            0.71: '#95014b',
            1: '#7e0226'
          } },
        { code: 'a21026',
          name: 'SO2',
          maxNumber: 2100,
          maxNumber: 150,
          src: require('@/assets/images/tl_SO2.png'),
          gradient: {
            '0': '#12a112',
            '0.02': '#12a112',
            '0.07': '#feff01',
            '0.22': '#fd8200',
            '0.38': '#fd0001',
            '0.76': '#95014b',
            '1': '#7e0226'
          } },
            1: '#feff01',
            0.3: '#12a112',
          }
        },
        { code: 'a21004',
          name: 'NO2',
          maxNumber: 750,
          maxNumber: 400,
          src: require('@/assets/images/tl_NO2.png'),
          gradient: {
            '0': '#12a112',
            '0.05': '#12a112',
            '0.1': '#feff01',
            '0.24': '#fd8200',
            '0.37': '#fd0001',
            '0.75': '#95014b',
            '1': '#7e0226'
            0: '#12a112',
            0.1: '#12a112',
            0.15: '#feff01',
            0.19: '#feff01',
            0.20: '#fd8200',
            0.25: '#fd8200',
            0.45: '#fd8200',
            0.5: '#fd0001',
            0.7: '#95014b',
            1: '#7e0226'
          }},
        { code: 'a21005',
          name: 'CO',
          maxNumber: 48,
          src: require('@/assets/images/tl_CO.png'),
          gradient: {
            '0': '#12a112',
            '0.04': '#12a112',
            '0.083': '#feff01',
            '0.29': '#fd8200',
            '0.5': '#fd0001',
            '0.75': '#95014b',
            '1': '#7e0226'
            0.0: '#12a112',
            0.04: '#12a112',
            0.083: '#feff01',
            0.29: '#fd8200',
            0.5: '#fd0001',
            0.75: '#95014b',
            1: '#7e0226'
          }},
        { code: 'a05024',
          name: 'O3',
          maxNumber: 1000,
          maxNumber: 500,
          src: require('@/assets/images/tl_O3.png'),
          gradient: {
            '0': '#12a112',
            '0.16': '#12a112',
            '0.2': '#feff01',
            '0.3': '#fd8200',
            '0.4': '#fd0001',
            '0.8': '#95014b',
            '1': '#7e0226'
            0: '#12a112',
            0.32: '#12a112',
            0.33: '#feff01',
            0.4: '#feff01',
            0.41: '#fd8200',
            0.6: '#fd8200',
            0.61: '#fd0001',
            0.8: '#fd0001',
            0.9: '#95014b',
            1: '#7e0226'
          } },
        { code: 'a99054',
          name: 'TVOC',
          maxNumber: 4,
          src: require('@/assets/images/tl_TVOCNew.png'),
          gradient: {
            '0': '#12a112',
            '0.12': '#12a112',
            '0.25': '#feff01',
            '0.375': '#fd8200',
            '0.5': '#fd0001',
            '0.75': '#95014b',
            '1': '#7e0226'
            0: '#12a112',
            0.12: '#12a112',
            0.25: '#feff01',
            0.375: '#fd8200',
            0.5: '#fd0001',
            0.75: '#95014b',
            1: '#7e0226'
          }}
      ],
      heatMapData: [],
@@ -225,6 +235,7 @@
        speed: 2
      },
      polygon: null,
      districtSearch: null,
      dateTimes: [],
      activeItem: {},
      markerList: []
@@ -249,36 +260,31 @@
      },
      deep: true
    },
    'formInline.city': {
      handler: function (newVal, oldVal) {
        console.log('newVal', newVal === '')
        if (newVal !== '') {
          this.init1()
          if (!!this.formInline.starTime && !!this.formInline.endTime) {
            this.onSubmit()
          }
        }
      },
      deep: true
    },
    // 'formInline.city': {
    //   handler: function (newVal, oldVal) {
    //     console.log('newVal', newVal === '')
    //     if (newVal !== '') {
    //       this.init1()
    //       if (!!this.formInline.starTime && !!this.formInline.endTime) {
    //         this.onSubmit()
    //       }
    //     }
    //   },
    //   deep: true
    // },
    activeItem: {
      handler (newVal, oldVal) {
        if (this.markerList.length > 0) {
          console.log('2222', this.map.getAllOverlays('marker'))
          this.map.remove(this.markerList)
          this.markerList = []
          // this.markerClusterer = null
        }
        this.getData(newVal.name)
      },
      deep: true
    }
  },
  created () {
  },
  mounted () {
    this.$nextTick(() => {
      this.initMap()
      this.createHeatMap()
    })
    // let dataTime = dayjs().format('YYYY-MM-DD')
    this.getOrganizationId()
    // this.getData(`${dataTime} 00`)
  },
  destroyed () {
@@ -304,9 +310,13 @@
    getDateFun (item) {
      console.log(item)
      this.activeItem = item
      if (this.orgId.length > 0) {
        this.getData(item.name)
      }
    },
    getPollutant (data) {
      this.selectSensor = _.find(this.sensorArr, { name: data })
      this.dateTimes = []
      if (this.heatmap) {
        this.map.remove(this.heatmap)
        this.heatmap = null
@@ -315,37 +325,80 @@
    },
    // 初始化地图
    initMap () {
      let zoom = 10
      if (this.formInline.cityCode === '320900') {
        zoom = this.formInline.areName === 'dafengqu' ? 15 : 13
      }
      var map = new AMap.Map('mapd', {
        resizeEnable: true,
        zooms: [10, 10],
        zoom: 10,
        zoomEnable: false,
        zoom: zoom
      })
      this.map = map
      map.on('click', function (e) {
        console.log('e.lnglat.getLng() + ', ' + e.lnglat.getLat()', e.lnglat.getLng() + ',' + e.lnglat.getLat())
      })
      this.init1()
      // let that = this
    },
    init1 () { // 区域遮盖
      var that = this
      this.map.setCity(this.formInline.city)
      console.log('this.formInline.city', this.formInline.cityCode)
      if (that.polygon) {
        that.map.remove(that.polygon)
        that.map.remove(that.districtSearch)
        that.polygon = null
        that.districtSearch = null
      }
      console.log('that.polygon', that.polygon)
      AMap.plugin('AMap.DistrictSearch', function () {
      this.districtSearch = AMap.plugin('AMap.DistrictSearch', function () {
        new AMap.DistrictSearch({
          extensions: 'all',
          subdistrict: 0
        }).search(that.formInline.city, function (status, result) { // 外多边形坐标数组和内多边形坐标数组
        }).search(that.formInline.cityCode, function (status, result) { // 外多边形坐标数组和内多边形坐标数组
          var outer = [
            new AMap.LngLat(-360, 90, true),
            new AMap.LngLat(-360, -90, true),
            new AMap.LngLat(360, -90, true),
            new AMap.LngLat(360, 90, true)
          ]
          var holes = result.districtList[0].boundaries
          var pathArray = [outer]
          pathArray.push.apply(pathArray, holes)
          let ycPoints = {
            areas: [{ // 围栏1
              rejectTexture: true, // 是否屏蔽自定义地图的纹理
              path: [[
                [120.06316306, 33.41753995999999],
                [120.2617243421, 33.41753995999999],
                [120.2617243421, 33.308387182],
                [120.06316306, 33.308387182],
                [120.06316306, 33.41753995999999]
              ]]
            }]
          }
          var holes = result.districtList[0].boundaries
          console.log('that.formInline', that.formInline)
          if (that.formInline.cityCode === '320900') {
            // 盐城
            that.map.setCenter([120.16, 33.36])
            if (that.formInline.areName === 'dafengqu') {
              that.map.setCenter([120.435345, 33.203704])
              ycPoints = {
                areas: [{ // 围栏1
                  rejectTexture: true, // 是否屏蔽自定义地图的纹理
                  path: [[ [120.41615942, 33.215693],
                    [120.45416756599998, 33.215693],
                    [120.45416756599998, 33.192137742599996],
                    [120.41615942000003, 33.19213774259998],
                    [120.41615942, 33.215693] ]]
                }]
              }
            }
            pathArray.push.apply(pathArray, ycPoints.areas[0].path)
          } else {
            pathArray.push.apply(pathArray, holes)
            that.map.setCity(that.formInline.city)
          }
          // pathArray.push.apply(pathArray, holes)
          that.polygon = new AMap.Polygon({
            pathL: pathArray,
            strokeColor: 'red', // 城市边界颜色
@@ -363,7 +416,7 @@
        url: '/heatMap/query',
        method: 'get',
        params: {
          id: this.orgId,
          id: this.orgId[0],
          startTime: newVal,
          type: this.selectSensor.code,
          form: this.formInline.dayType
@@ -374,21 +427,59 @@
            if (this.heatmap === null) {
              this.createHeatMap()
            }
            this.heatMapData = []
            this.heatMapData = res.data
            this.dataProcessing(this.heatMapData)
            this.heatmap.setDataSet({
              data: this.heatMapData,
              max: this.selectSensor.maxNumber
            })
            console.log('000', this.map.getZoom())
            console.log('1111', this.heatmap.getDataSet())
          } else {
            this.map.remove(this.heatmap)
            this.heatmap = null
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    dataProcessing (heatMapData) {
      // 获取最大值
      console.log('this.heatMapData', this.heatMapData)
      const max = heatMapData.reduce((prev, current) => (prev.count > current.count ? prev : current)).count
      // so2
      if (this.selectSensor.code === 'a21026') {
        if (max > 150 && max <= 475) {
          this.selectSensor.maxNumber = 475
          this.heatmap.setOptions({
            gradient: {
              0.1: '#12a112',
              0.2: '#feff01',
              0.3: '#feff01',
              0.32: '#fd8200',
              0.4: '#fd8200',
              1: '#fd8200'
            }
          })
        }
        if (max > 475 && max <= 1000) {
          this.selectSensor.maxNumber = 1000
          this.heatmap.setOptions({
            gradient: {
              0: '#12a112',
              0.05: '#12a112',
              0.15: '#feff01',
              0.47: '#fd8200',
              0.5: '#fd0001',
              0.8: '#fd0001',
              0.9: '#95014b',
              1: '#7e0226'
            }
          })
        }
      } else if (this.selectSensor.code === 'a05024') {
        if (max > 150 && max <= 475) {}
      }
    },
    // 聚合点
    setMarkers (curData) {
@@ -487,7 +578,18 @@
        method: 'get'
      })
        .then(res => {
          this.orgData = res.data
          this.orgData = res.data.map(item => {
            if (item.id === 73) {
              item.children = [{
                id: 'shiqu',
                name: '市区'
              }, {
                id: 'dafengqu',
                name: '大丰区'
              }]
            }
            return item
          })
        })
        .catch(err => {
          console.log(err)
@@ -495,10 +597,12 @@
    },
    createHeatMap () {
      let that = this
      let radius = this.formInline.areName === 'shiqu' ? 100 : 100
      console.log('radius', radius)
      this.map.plugin(['AMap.Heatmap'], function () {
        // 初始化heatmap对象
        that.heatmap = new AMap.Heatmap(that.map, {
          radius: 100, // 给定半径
          radius: radius, // 给定半径
          opacity: [0.5, 1],
          gradient: that.selectSensor.gradient
        })
@@ -507,10 +611,16 @@
    onSubmit () {
      if (!!this.formInline.city && !!this.formInline.starTime && !!this.formInline.endTime) {
        this.map.clearMap()
        // this.map.clearMap()
        this.getDayListData()
        if (this.map) {
          this.map.destroy()
        }
        this.initMap()
        this.createHeatMap()
        this.getData(this.formInline.starTime)
        this.init1()
        // this.map.setZoom(12)
      } else {
        this.$message({
@@ -522,19 +632,27 @@
      }
    },
    regionData (id) {
      let cityData = _.find(this.orgData, { id: id })
      this.formInline.city = cityData.cityName
      this.formInline.cityCode = cityData.cityCode
      console.log('id', id)
      let cityData = _.find(this.orgData, { id: id[0] })
      if (id[0] === 73) {
        if (id[1]) {
          this.formInline.areName = id[1]
        }
        this.formInline.city = cityData.cityName
        this.formInline.cityCode = String(cityData.cityCode)
      } else {
        this.formInline.city = cityData.areaName
        this.formInline.cityCode = String(cityData.areaCode)
      }
    },
    selectHourData (data) {
      console.log('ccccc', this.formInline)
      if (data) {
        this.formInline.starTime = data[0]
        this.formInline.endTime = data[1]
        console.log('selectHourData', data)
        let dataTime = dayjs().format('YYYY-MM-DD')
        this.getOrganizationId()
        this.getDayListData()
        this.getData(`${dataTime} 00`)
        if (this.formInline.city) {
          this.getDayListData()
        }
      } else {
        this.formInline.starTime = ''
        this.formInline.endTime = ''