whyczyk
2021-07-21 6e32b8f6cf5dd63eafdb372729b29fb37abaccc6
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
<template>
    <div class="echarts-wrapper">
        <div class="echarts-content" ref="chart"></div>
    </div>
</template>
 
<script>
    import * as echarts from 'echarts';
 
    export default {
        name: "chinaMap",
        chart: "",
        chartData: [],
        props: {
            id: {
                type: String,
                required: true,
            },
            name: {
                type: String,
                required: true,
            }
        },
        data() {
            return {
 
            }
        },
        methods: {
            setOption(opt) {
                this.$options.chart.setOption(opt);
            },
            setData(sendData) {
                this.$options.chartData = sendData;
                let geoJson = require(`../../../public/mapJson/${this.name}.json`);
                echarts.registerMap('map', geoJson);
                let option = {
                    tooltip: {
                        trigger: 'item',
                        formatter: function (params) {
                            if (params.componentSubType == "map") {
                                return ''
                            } else if (params.componentSubType == "scatter") {
                                return params.name;
                            }
                        }
                    },
                    visualMap: {
                        show: false,
                        min: 0,
                        max: 500,
                        left: 'left',
                        top: 'bottom',
                        text: ['高', '低'], // 文本,默认为数值文本
                        calculable: true,
                        seriesIndex: [1],
                        inRange: {}
                    },
                    geo: {
                        map: "map",
                        layoutCenter: ["55%", "50%"],
                        layoutSize: "100%",
                        label: {
                            normal: {
                                show: true,
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                            emphasis: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        },
                        roam: true, //是否允许缩放
                        mapLocation: {
                            width: "110%",
                            height: "97%"
                        },
                        itemStyle: {
                            normal: {
                                borderColor: 'rgba(147, 235, 248, 1)',
                                borderWidth: 1,
                                areaColor: {
                                    type: 'radial',
                                    x: 0.5,
                                    y: 0.5,
                                    r: 0.8,
                                    colorStops: [{
                                        offset: 0,
                                        color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色
                                    }, {
                                        offset: 1,
                                        color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色
                                    }],
                                    globalCoord: false // 缺省为 false
                                },
                                shadowColor: 'rgba(128, 217, 248, 1)',
                                shadowOffsetX: -2,
                                shadowOffsetY: 2,
                                shadowBlur: 10
                            },
                            emphasis: {
                                areaColor: '#1ecee5',
                                borderWidth: 0,
                                label: {
                                    show: false
                                }
                            }
                        }
                    },
                    series: sendData
                };
                this.setOption(option);
            },
            resize() {
                setTimeout(() => {
                    this.$options.chart.resize();
                }, 0);
            }
        },
        mounted() {
            // 基于准备好的dom,初始化echarts实例
            this.$options.chart = echarts.init(this.$refs.chart);
            window.addEventListener('resize', this.resize);
        },
        destroyed() {
            window.removeEventListener('resize', this.resize);
        }
    }
</script>
 
 
<style scoped>
    /* echarts css */
    .echarts-wrapper,
    .echarts-content {
        width: 100%;
        height: 100%;
    }
</style>