<!--
 * @Description: 高后果区热力图层
 * @Author: 王晓颖
 * @Date: 2021-06-03 14:28:05
 -->
<template>
  <div>
    <slot/>
  </div>
</template>

<script>
import commonMixin from '../base/mixins/common.js'
import { getHighConsequence } from '@/api/hca'
export default {
  name: 'HcaHeatLayer',
  mixins: [commonMixin('layer')],
  props: {
    show: {
      type: Boolean,
      default: false
    } // 是否可见
  },
  data() {
    return {
      layer: null, // 图层
      data: [] // 完整数据
    }
  },
  watch: {
    show(val) {
      console.log('watch show: ' + val)
      if (val) {
        this.initLayer()
      } else {
        this.removeLayer()
      }
    }
  },
  methods: {
    load() {
      console.log('load')
      if (this.show) this.initLayer()
    },
    initLayer() {
      const { map } = this
      if (map) {
        if (this.show) {
          if (this.layer) {
            this.removeLayer()
          }
        }
        // const graphicLayer = new mars3d.layer.GraphicLayer()
        // this.layer = graphicLayer
        // map.addLayer(graphicLayer)
        this.loadData()
      }
    },
    loadData() {
      const { mars3d, Cesium, map } = this
      getHighConsequence().then(res => {
        let data = res.data.filter(item => item['DES02'] !== '无')
        data = data.map(item => {
          return {
            '编号': item['DES07'],
            '经度': parseFloat(item['DES02']),
            '纬度': parseFloat(item['DES03']),
            '位置描述': item['DES05'],
            '行政区域': item['DES09'],
            '地区级别': item['DES10'],
            '高后果区特征描述': item['DES11'],
            '机构名称': item['DES12'],
            '高后果区长度': item['DES08'],
            '识别时间': item['WD01_03'],
            '高后果区级别': item['WD02_04'],
            '所属管理处': item['DES01'],
            '人数范围': item['WD58_03'],
            '识别单位及负责人': item['DES04']
          }
        })
        this.data = data.filter(item => item['高后果区级别'] !== '无')
        const heatLayer = new mars3d.layer.HeatLayer({
          name: 'heatLayer',
          positions: this.data.map(item => {
            return Cesium.Cartesian3.fromDegrees(item['经度'], item['纬度'], 1)
          }),
          heatStyle: {
            radius: 30, // 半径
            blur: 1 // 模糊因子
          },
          // 以下为矩形矢量对象的样式参数
          style: {
            opacity: 0.8,
            clampToGround: false,
            height: 10000,
            zIndex: 5
          },
          delayTime: 0.5
        })
        this.layer = heatLayer
        map.addLayer(heatLayer)
      })
    },
    // 移除图层
    removeLayer() {
      const { map, layer } = this
      if (this.layer) {
        map.removeLayer(layer)
        this.layer = null
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
