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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<template>
<div id="map" ref="areaRankingAll"></div>
</template>
<script>
import geoList from "./geo"
import * as echarts from "echarts"
import hospital from "./hospital"
import china from "./china.json"
// import allCode from "./allCode.json"
// import data from "./data"
export default {
data() {
return {
echart: null,
//线上请求JSON文件数据地址
// publicUrl: "https://geo.datav.aliyun.com/areas_v3/bound/",
//allCode 区域行政编码信息
// allCode: allCode,
locate: [
{
name: "安徽省",
value: 50,
},
],
hospital: hospital,
}
},
props: {
mapData: {
type: Array,
},
},
watch: {
mapData(v) {
this.initChart()
},
},
mounted() {
this.initChart() //初始化地图
},
methods: {
initEcharts(geoJson, name, chart) {
// console.log(JSON.stringify(geoJson))
// let handleLocate = (arr) => {
// for
// }
// 处理data
let viewHospital = []
for (let i = 0; i < this.mapData.length; i++) {
let obj = {}
this.hospital.forEach((e) => {
if (e.name == this.mapData[i].name) {
obj = e
obj.value = this.mapData[i].value
viewHospital.push(obj)
}
})
}
echarts.registerMap(name, geoJson)
let option = {
title: {
text: "", // 地图名称
},
tooltip: {
show: true,
formatter: function (params) {
let str =
params.value === 0 || params.value
? params.name + ":" + params.value
: params.name
return str
},
// valueFormatter: (value) => value + "%",
backgroundColor: "rgba(50,50,50,0.7)",
textStyle: {
color: "#fff",
},
// textStyle: { fontSize: 14, fontFamily: "fzzz", color: "#fff" },
// backgroundColor: "rgba(0,0,0,0.3)",
// borderColor: "rgba(0,0,0,0.3)",
},
geo: {
show: true,
map: name,
// roam: true,
zoom: 1.2,
center: [105, 36],
label: {
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
areaColor: "#2197FF",
borderColor: "#9DCCF5",
borderWidth: 1,
},
emphasis: {
areaColor: "#4E68FF", //悬浮背景
},
},
},
series: [
// 设置地图样式
{
type: "map",
map: "china",
geoIndex: 0,
aspectScale: 0.75, //长宽比
label: {
normal: {
show: false,
},
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
areaColor: "#031525",
borderColor: "#FFFFFF",
},
emphasis: {
areaColor: "#2B91B7",
},
},
animation: false,
data: [],
},
{
type: "lines",
z: 3,
coordinateSystem: "geo",
symbol: "circle",
symbolSize: [6, 0],
// color: "#17A597",
opacity: 1,
// polyline: true,
label: {
show: true,
position: "end",
formatter: `{value|{c}} {title|{b}} `,
rich: {
title: {
align: "center",
fontSize: 14,
color: "#fff",
},
value: {
fontSize: 14,
align: "center",
color: "#3DF2CD",
backgroundColor: "rgba(61,244,206,0.1)",
width: 64,
height: 20,
lineHeight: 20,
borderRadius: [4, 4, 0, 0],
},
},
},
lineStyle: {
type: "solid",
opacity: 1,
color: "#A6D5FF",
curveness: 0.1,
},
data: viewHospital,
},
],
}
chart.setOption(option, true) //加个true解决下钻的视角偏移
chart.off("click")
window.addEventListener(
"resize",
() => {
window.onresize = this.echart.resize()
},
false
)
},
//带头函数-初始化
initChart() {
let chart = echarts.init(this.$refs.areaRankingAll)
this.echart = chart
this.initEcharts(china, "中国", chart)
},
},
}
</script>
<style lang="scss" scoped></style>