前段时间我们的项目有使用到echarts集成中国地图的功能,实际上这个功能我进项目组的时候人家就已经完成了,我这边只是简单复刻了一遍,先看看效果图;
上代码,走起
<template>
<!-- 第一步:设置地图容器 -->
<div id="map" style="width: 100vw; height: 100vh"></div>
</template>
<script setup lang="ts">
// 第二步:导入模块
import * as echarts from 'echarts'
import { onMounted, ref, reactive } from 'vue'
import { getCityJson } from '@/apis/map'
import { options } from './index'
// 第三步:存储中国地图JSON数据
let mapData = ref([])
// 第三步:存放echarts实例
let myMap = reactive({})
// 第三步:Vue挂载DOM后执行回调
onMounted(async () => {
initMap() // 第四步:初始化地图
// 点击中国地图的事件回调
myMap.on('click', function (event) {
if (event?.data?.adcode) {
switch (event.data.level) {
// 国/省/市/区
case 'nation':
case 'country':
case 'province':
case 'city':
uploadMapData(event.data.adcode + '_full')
break
// 县
case 'district':
uploadMapData(event.data.adcode)
break
// 其他
default:
break
}
}
})
// 空白区域点击回调
myMap.getZr().on('click', function (event) {
// 没有 target 意味着鼠标/指针不在任何一个图形元素上,它是从“空白处”触发的。
if (!event.target) {
// 点击在了空白处,做些什么。
uploadMapData()
}
})
// 视图变化既重新渲染
window.addEventListener('resize', function () {
myMap.resize()
})
})
// 第六步:加载地图数据,注册地图
const loadMapData = async (id: string = '100000_full'): Promise<any> => {
const mapJson = await getCityJson(id) // 获取json数据
echarts.registerMap('china', mapJson) // 注册地图
mapData = mapJson.features.map(item => item.properties) // 获取地图数据(一定要加上,不加上的话,通过点击事件下钻时,event内的data数据会是空的)
myMap.setOption(options(mapData)) //数据渲染
}
// 第五步:更新数据
const uploadMapData = async (id: string = '100000_full'): Promise<void> => {
await loadMapData(id)
}
// 地图初始化
const initMap = () => {
// 基于准备好的dom,初始化echarts实例
myMap = echarts.init(document.getElementById('map'))
uploadMapData() // 第五步:更新数据(这个方法可以写一些其他逻辑,比如loading,或者加载一些其他数据)
}
</script>
<style scoped lang="scss"></style>
options文件,都是echarts的option配置属性,常量属性symbol 是一个icon来着,你可以删掉
const sym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C5L71CYThmX5cohCOY9XU+0olYCe6rzV73OAERVUtx1YQLGx+N93cIDIs+cQld4BiC6EpNcLwLm8HndA1X4SwiPlnYBMNg/bDhcX+o1Awj/kjYA8S871zsBGlwA0wyfzDwLCzwMBMxMYoBIosBzRCJMRbcGIAm+BgYiDKHDBhSveThNQPW2VjBcId4XZgASr7zN0zImAQOQjL0wM9x4JWAAEq+8zdMyJgEDkIy9MDPceCVgABKvvM3TMiaB/wdZStv1Nmy5bQAAAABJRU5ErkJggg=='
export const options = (
data: any,
layoutCenter: string[] = ['50%', '50%'],
layoutSize: string = '130%'
) => {
return {
backgroundColor: 'transparent',
visualMap: {
type: 'continuous',
show: false,
inRange: {
color: ['#1858a3', '#1b549f', '#2aa7d1'],
},
outOfRange: {
color: ['#1858a3'],
},
splitNumber: 0,
},
geo: [
{
aspectScale: 0.8,
layoutCenter: ['50%', '50%'], // 地图中心
layoutSize, // 地图大小
show: true,
map: 'china', // 地图类型-与registerMap注册地图的名字相同
roam: false, // 是否开启鼠标缩放和平移漫游
zoom: 0.65, // 当前视角的缩放比例
label: {
show: false, // 是否显示标签
color: '#fff', // 标签字体颜色
},
itemStyle: {
areaColor: '#1b549f',
borderColor: '#c0f3fb', // 地图边框颜色
borderWidth: 1.5, // 地图边框宽度
shadowColor: 'rgba(44, 171, 213, 0.3)',
shadowOffsetY: 10,
shadowBlur: 10,
},
emphasis: {
itemStyle: {
areaColor: 'rgba(0,254,233,0.6)',
},
},
regions: [
{
name: '南海诸岛',
itemStyle: {
areaColor: 'rgba(0, 10, 52, 1)',
borderColor: 'rgba(0, 10, 52, 1)',
normal: {
opacity: 0,
label: {
show: false,
color: '#009cc9',
},
},
},
label: {
show: false,
color: '#FFFFFF',
fontSize: 12,
},
},
],
},
{
type: 'map',
map: 'china',
zlevel: -2,
aspectScale: 0.8,
zoom: 0.65,
layoutCenter: ['50%', '53%'],
layoutSize,
roam: false,
silent: true,
itemStyle: {
borderWidth: 1,
borderColor: 'rgba(58,149,253,0.6)',
shadowColor: 'rgba(27,84,159,1)',
shadowOffsetY: 5,
shadowBlur: 15,
areaColor: '#0c235b',
},
regions: [
{
name: '南海诸岛',
itemStyle: {
areaColor: 'rgba(0, 10, 52, 1)',
borderColor: 'rgba(0, 10, 52, 1)',
normal: {
opacity: 0,
label: {
show: false,
color: '#009cc9',
},
},
},
label: {
show: false,
color: '#FFFFFF',
fontSize: 12,
},
},
],
},
],
series: [
{
type: 'map', // 系列类型-地图
map: 'china', // 地图类型-与registerMap注册地图的名字相同
geoIndex: 0,
roam: true, // 是否开启鼠标缩放和平移漫游
zlevel: 0,
aspectScale: 0.8,
zoom: 0.65, // 当前视角的缩放比例
animation: false,
layoutCenter,
layoutSize,
data,
},
{
type: 'map', // 系列类型-地图
map: '中国', // 地图类型-与registerMap注册地图的名字相同
geoIndex: 0,
aspectScale: 0.8,
zoom: 0.65,
showLegendSymbol: true,
roam: true,
label: {
color: '#fff',
fontSize: '120%',
show: true,
},
// select: {
// disabled: true, // 数据项图形是否能被选中
// },
itemStyle: {
// areaColor: {
// type: 'linear',
// x: 1200,
// y: 0,
// x2: 0,
// y2: 0,
// colorStops: [
// {
// offset: 0,
// color: 'rgba(3,27,78,0.75)',
// },
// {
// offset: 1,
// color: 'rgba(58,149,253,0.75)',
// },
// ],
// global: true,
// },
borderColor: '#fff',
borderWidth: 0.2,
},
layoutCenter,
layoutSize, // 地图大小
animation: false,
markPoint: {
symbol: 'none',
},
data: [],
},
{
type: 'scatter',
coordinateSystem: 'geo', // 对应上面定义的地图
geoIndex: 0,
zlevel: 5,
label: {
show: true,
formatter: '',
color: '#54f7f9',
fontSize: 16,
fontWeight: 'bold',
},
itemStyle: {
opacity: 1,
},
symbol: symbol,
symbolSize: [20, 20],
symbolOffset: [0, -20],
z: 999,
// data: [[113.280637, 23.125178]],
},
],
}
}
加载中国地图的json接口
import require from '@/utils/require'
export const getCityJson = (id: string) => {
return require({
url: `https://geo.datav.aliyun.com/areas_v3/bound/${id}.json`,
method: 'GET',
})
}
目录结构