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
<template>
<div id="map" ref="areaRankingAll"></div>
</template>
<script>
import * as echarts from "echarts"
import china from "./china.json"
import allCode from "./allCode.json"
export default {
data() {
return {
//线上请求JSON文件数据地址
// publicUrl: "https://geo.datav.aliyun.com/areas_v3/bound/",
//allCode 区域行政编码信息
allCode: allCode,
locate: [
{
name: "安徽",
value: [117.29, 32.0581, 0],
},
],
}
},
watch: {},
mounted() {
this.initChart() //初始化地图
},
methods: {
initEcharts(geoJson, name, chart) {
// console.log(JSON.stringify(geoJson))
let self = this
echarts.registerMap(name, geoJson)
let option = {
title: {
text: "", // 地图名称
},
tooltip: {
show: true,
formatter: function (params) {
if (params.value.length > 1) {
return params.name + ":" + params.value[2] + "人"
}
return `${params.name} : ${params.value ? params.value : 0}人`
},
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.5,
center: [105, 34.0267395887],
label: {
emphasis: {
show: false,
},
},
itemStyle: {
normal: {
areaColor: "#EDEFFF",
borderColor: "#7597FA",
borderWidth: 1,
},
emphasis: {
areaColor: "#4E68FF", //悬浮背景
},
},
},
series: [
//小点
{
//文字和标志
name: "light",
type: "scatter",
coordinateSystem: "geo",
data: this.locate,
symbolSize: function (val) {
return val[2] / 8
},
label: {
normal: {
// formatter: "{b}",
formatter: "",
position: "right",
show: true,
},
emphasis: {
show: true,
},
},
itemStyle: {
normal: {
color: "#FFCF4E",
},
},
},
{
type: "map",
map: "china",
geoIndex: 0,
aspectScale: 0.75, //长宽比
showLegendSymbol: false, // 存在legend时显示
label: {
normal: {
show: false,
},
emphasis: {
show: false,
textStyle: {
color: "#fff",
},
},
},
roam: true,
itemStyle: {
normal: {
areaColor: "#031525",
borderColor: "#FFFFFF",
},
emphasis: {
areaColor: "#2B91B7",
},
},
animation: false,
data: [{ name: "安徽省", value: 0 }],
},
],
}
chart.setOption(option, true) //加个true解决下钻的视角偏移
chart.off("click")
},
//带头函数-初始化
initChart() {
let chart = echarts.init(this.$refs.areaRankingAll)
this.initEcharts(china, "中国", chart)
},
},
}
</script>
<style lang="scss" scoped></style>