<style lang="scss" scoped>
.o-echarts {
  min-width: 30px;
  min-height: 30px;
  width: 100%;
  height: 100%;
  // background-color: aqua;
}
</style>
<template>
  <div id="echarts_map" class="o-echarts"></div>
</template>

<script>
import tianjin from "./map/tianjin.json";

export default {
  name: "echart-map",
  props: ["mapData"],
  data() {
    return {
      echartObj: null,
      option: {
        layoutCenter: ["50%", "43%"], //位置
        layoutSize: "80%", //大小
        tooltip: {
          trigger: "item",
          formatter: (params) => {
            // console.log(params, "params");
            return (
              "<div>库存总量:" +
              params.data.inventoryTotal +
              "吨<br>市级储备总量:" +
              params.data.provincial +
              "吨<br/>区级储备总量:" +
              params.data.municipal +
              "吨<br/>承储企业:" +
              params.data.inventoryCount +
              "家"
            );
          },
        },

        toolbox: {
          show: false,
          orient: "vertical",
          left: "right",
          top: "center",
          feature: {
            dataView: { readOnly: false },
            restore: {},
            saveAsImage: {},
          },
        },
        geo: {
          show: true,
          map: "天津",
          lable: {
            color: "white",
            normal: {
              show: false,
            },
            emphasis: {
              show: false,
            },
          },
          itemStyle: {
            normal: {
              //阴影
              areaColor: "#7dc1d5",
              borderWidth: 0,
              borderColor: "#0395fc",
              shadowColor: "#0395fc",
              shadowBlur: 0,
              opacity: 0.8,
              // shadowOffsetX: 0,
              // shadowOffsetY: 0,
            },
          },
        },
        series: [
          {
            name: "天津",
            type: "map",
            map: "天津",
            zoom: 1,
            label: {
              show: true,
              color: "#fff",
              fontSize: 16,
              fontWeight: "bold",
            },
            itemStyle: {
              normal: {
                color: "#fff",
                borderWidth: 1, //边际线大小
                borderColor: "#73dcff", //边界线颜色
                areaColor: "#4490f1", //默认区域颜色
              },
              emphasis: {
                show: true,
                color: "#fff",
                areaColor: "#3077ca", //鼠标滑过区域颜色
                label: {
                  show: true,
                  textStyle: {
                    color: "#fff",
                  },
                },
              },
            },
            data: [],
          },
        ],
      },
    };
  },
  created() {},
  mounted() {
    this.echartObj = this.$echarts.init(document.getElementById("echarts_map"));
    this.$echarts.registerMap("天津", tianjin);
    this.option.series[0].data = this.mapData;
    this.echartObj.setOption(this.option);
    // window.addEventListener("resize", () => {
    //   if (this.echartObj && this.echartObj.resize) {
    //     this.echartObj.resize();
    //   }
    // });
  },
  methods: {},
};
</script>
