<template>
  <div id="city" ref="city" class="impactchart"></div>
</template>
<script>
let echarts = require("echarts/lib/echarts");
import CONST from '../../assets/js/CONST.js';
  let mapData = {};
  export default {
    name: 'cityMap',
    data() {
      return {
        chart: {},
        geoCoordMap: []
      }
    },
    beforeDestroy() {
      if (this.chart.dispose) {
        this.chart.dispose();
      }
    },
    created() {

    },
    props:{
      unit: String,
      provide: String,
      city: String,
      datas: Array
    },
    mounted() {
      this.loadData()
    },
    methods: {
      loadData() {
        //注册地图
        mapData = require('../../assets/map/json/cityArea/' + this.provide + '/'+this.city+'.json')
        echarts.registerMap(this.city, mapData,true);
        mapData.features.map(res => {
          this.geoCoordMap[res.properties.name] = res.properties.cp;
        })
        this.chart = echarts.init(this.$refs.city);
        this.chart.setOption({
          backgroundColor: '#fff',
          title: {
            subtext: '',
            left: 'center',
            textStyle: {
              color: '#333'
            }
          },
          visualMap: {
            type: 'piecewise',
            show: false,
            left: 'left',
            top: 'bottom',
            text: ['高', '低'], // 文本，默认为数值文本
            calculable: true,
            seriesIndex: [0]
          },
          xAxis: {
            axisLabel: {show: false},
            axisLine: {show: false},
            splitLine: {show: false},
            axisTick: {show: false},
            min: -1,
            max: 1
          },
          yAxis: {
            axisLabel: {show: false},
            axisLine: {show: false},
            splitLine: {show: false},
            axisTick: {show: false},
            min: -1,
            max: 1
          },
          tooltip: {
            trigger: 'item',
            formatter:'{b}:{c}'+this.unit,
            backgroundColor: '#ffffff',
            textStyle: {
              color: '#333'
            }
          },
          legend: {
            // orient: 'vertical',
            // top: 'bottom',
            // left: 'right',
            // textStyle: {
            //   color: '#fff'
            // },
            // selectedMode: 'single',

          },
          geo: {
            map: CONST.city.zh,
            layoutSize: "80%",
            label: {
              normal: {
                show: true,
                color: '#fff',
                lineHeight: 60,
                position:'right',
                fontSize: '10'
              },
              emphasis: {
                show: false,
                color: '#fff'
              }
            },
            roam: false,
            itemStyle: {
              normal: {
                areaColor: '#aed4d8',
                borderColor: '#B0E0E6',
                borderWidth: '1',
              },
              emphasis: {
                areaColor: '#b3d0d6'
              }
            },
            silent: false,
          },
          series: this.datas
        });
    }
  }
  }
</script>
<style lang="scss" scoped>
  .impactchart {
    // height: 770px;
  }
</style>
