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
| <template>
| <div class="map-container">
| <div ref="map" class="map-style"></div>
| </div>
|
| </template>
|
| <script>
| import * as echarts from 'echarts';
| import 'echarts-gl';
| import mapData from '@/assets/map/dujiangyan.json';
| echarts.registerMap('dujiangyan', mapData);
| console.log(mapData);
| let mapChart = null;
| let tempName = '';
| const mapConfig = {
| series: [{
| map: "dujiangyan", //注册地图的名字
| type: "map3D",
| bottom: 0,
| left: 0,
| top: 0,
| right: 0,
| itemStyle: {
| color: "#4189f2", // 背景
| opacity: 1, //透明度
| borderWidth: 1.5, // 边框宽度
| borderColor: "#fff", // 边框颜色
| fontSize: 16, //
| },
|
| // 标签
| label: {
| show: true,
| color: "#fff", //地图初始化区域字体颜色
| fontSize: 18,
| },
| // 控制器
| viewControl: {
| beta: 82,
| alpha: 90,
| distance: 180,
| maxBeta: 180
| },
| // 鼠标移入时样式
| emphasis: {
| itemStyle: {
| color: "#F63545"
| }
| },
|
| // 数据
| data: mapData.features.map((item) => {
| return {
| name: item.properties.name,
| itemStyle: {
| color: "#4189f2"
| }
| }
| }),
| }
| ]
|
| };
| export default {
| name: 'DataMap',
| data() {
| return {
|
| }
| },
| components: {
| },
| methods: {
| filterData(name) {
| this.initConfig();
| let temp = mapConfig.series[0].data.find(item => item.name === name);
| temp.itemStyle.color = '#F63545';
| mapChart.setOption(mapConfig, true);
| this.$emit('filterData', name);
| },
| initConfig() {
| mapConfig.series[0].data.forEach(item => {
| item.itemStyle.color = '#4189f2';
| });
| }
| },
| mounted() {
| mapChart = echarts.init(this.$refs.map);
| mapChart.setOption(mapConfig, true);
| mapChart.on('click', (params) => {
| if (tempName === params.name) {
| tempName = '';
| this.initConfig();
| mapChart.setOption(mapConfig, true);
| this.$emit('filterData', '');
| } else {
| tempName = params.name;
| this.filterData(params.name);
| }
| })
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .map-container {
| width: 100%;
| height: 100%;
|
| .map-style {
| width: 100%;
| height: 100%;
| }
| }
| </style>
|
|