1 注意新版 echarts 的引入方式为: import * as echarts from ‘echarts‘,这里我把 echarts 直接挂载到了Vue上,本项目使用echarts比较多,这样的话很方便,也可以在需要echarts的模块按需引入
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts;
import China from '@assets/js/100000';
1 想要实现3D效果,可以通过设置阴影和边框来搞定,但是发现echarts 给地图设置边框后,会导致所有省的边框都会改变,这不是我们想要的效果,另辟蹊径 ,其实就是把多个地图实例重叠错位显示,实现悬浮3D效果。
2 echarts image属性 支持 纹理图片,支持base64位图片
color: {
},
},
},
select: {
label: {
},
}
}
},
},
}
}
}
regions: [
{
name: “南海诸岛”,
value: 0,
normal: {
opacity: 0,
}
}
}
}
],
绑定点击事件 ,选中高亮散点图和底图
myChart.on('click', e => {
if (!e.data) {
this.scatterData.map(item => {
if (item.symbolSize == 30) {
item.selected = true;
}
})
myChart.setOption(this.option, true);
return
}
// this.$emit('handle-map', this.scatterData[e.dataIndex]);
this.scatterData.map(item => {
item.symbol = item.name == e.name ? scatterHImg : scatterImg
item.label = item.name == e.name ? { backgroundColor: { image: scatterHBg } } : { backgroundColor: { image: scatterBg } };
item.symbolSize = item.name == e.name ? 30 : 20
item.selected = item.name == e.name ? true : false;
})
myChart.setOption(this.option, true);
});
下面是代码部分,封装了一个Vue组件,包括给散点图添加点击事件,高亮图标,悬浮显示。
<template>
<div class="container">
<div class="xx-map" id="baseMap"></div>
</div>
</template>
<script>
import China from '@assets/js/100000';
var piePatternSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3NpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkF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hFMDNFNjI4MzExMjBCQkMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIxLjAgKFdpbmRvd3MpIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NGVhZTRmY2ItYzE1Ny1jNjQ1LTgzOTgtOTM2YTk0M2QxNDMxIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjI4MjBjNTEzLWFiOTktMTU0MS1hOTU2LWU5YTgwN2VlNjgzZSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PifD0UMAAAA4SURBVHjaLIvBDQAgDALB1O4/gfs0cSax1d6LcMAVm6T7JHCkwQINYWleKFJaS/1Olp8yvcAVYADRHwpwESUINQAAAABJRU5ErkJggg=='
var patternImg = new Image();
patternImg.src = patternSrc;
var scatterImg = 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAXCAYAAAAGAx/kAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDUgNzkuMTYzNDk5LCAyMDE4LzA4LzEzLTE2OjQwOjIyICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vc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clujOeT3g6Cv0ZOAv8qvi2hcHXj0ovMqtSWU7YUn8j4PWyjkr0ZHTYaWMr3fe2smflO2qL+yBGpeSRZxjSkaGJkrctRn6qzi14cWZBLkOuqQjaxbMvEnUq2qQh2I3lJ4FnwmmWVR1FDPN3o6CRMuiYUGLZYz1TcdZKn0vwhXrryI8+syXLvCjT5fr6X45ahgIepdwPFII9nA2QFDApYEigoFzAEoljgeSxoIQngS/xJNyShgYZEi8Dv2wTKLRJMhOGLs6FwZX/ANcWAu8hXbR0AAAAAElFTkSuQmCC'
export default {
name: 'xx-map',
components: {},
props: {
mapData: {
type: Array,
default: []
}
},
data() {
return {
map: China, // 加载地图
chinaData: [
{ name: "北京", value: [116.405289, 39.904987] },
{ name: "天津", value: [117.190186, 39.125595] },
{ name: "河北", value: [114.502464, 38.045475] },
{ name: "黑龙江", value: [126.642464, 45.756966] },
{ name: "吉林", value: [125.324501, 43.886841] },
{ name: "辽宁", value: [123.429092, 41.796768], },
{ name: "内蒙古", value: [111.75199, 40.84149] },
{ name: "山西", value: [112.549248, 37.857014] },
{ name: "山东", value: [117.000923, 36.675808] },
{ name: "河南", value: [113.665413, 34.757977] },
{ name: "陕西", value: [108.948021, 34.263161] },
{ name: "湖北", value: [114.298569, 30.584354] },
{ name: "江苏", value: [118.76741, 32.041546] },
{ name: "安徽", value: [117.283043, 31.861191] },
{ name: "上海", value: [121.472641, 31.231707] },
{ name: "湖南", value: [112.982277, 28.19409] },
{ name: "江西", value: [115.892151, 28.676493] },
{ name: "浙江", value: [120.15358, 30.287458] },
{ name: "福建", value: [119.306236, 26.075302] },
{ name: "广东", value: [113.28064, 23.125177] },
{ name: "台湾", value: [121.520076, 25.030724] },
{ name: "海南", value: [110.19989, 20.04422] },
{ name: "广西", value: [108.320007, 22.82402] },
{ name: "重庆", value: [106.504959, 29.533155] },
{ name: "云南", value: [102.71225, 25.040609] },
{ name: "贵州", value: [106.713478, 26.578342] },
{ name: "四川", value: [104.065735, 30.659462] },
{ name: "宁夏", value: [106.23248, 38.48644] },
{ name: "甘肃", value: [103.83417, 36.06138] },
{ name: "青海", value: [101.77782, 36.61729] },
{ name: "西藏", value: [91.1145, 29.64415] },
{ name: "新疆", value: [87.61688, 43.82663] },
{ name: "香港", value: [114.16546, 22.27534] },
{ name: "澳门", value: [113.54913, 22.19875] },
],
scatterData: [],
option: {
// backgroundColor: '#001f4833',
tooltip: {
show: true,
trigger: 'item',
textStyle: {
fontSize: 14
},
formatter: function (params) {
console.log(params)
if (params.componentSubType === 'scatter') {
return `项目总数:${params.data.count}`
}
},
},
animation: false,
geo: {
show: true,
map: 'china', // 要与 `registerMap()` 的第一个参数对应, 'china' 会显示南海诸岛
roam: false, // 鼠标缩放+平移
aspectScale: 0.9,
zoom: 1.16,
selectedMode: 'single', // 选中
// label: {
// show: false,
// fontSize: 22,
// color: '#fff',
// position: 'inside' // 注: 将地图 JSON 文件的 cp 坐标删掉才有效
// },
silent: true,
center: [105.194115019531, 36.582111640625],
regions: [
{
name: "南海诸岛",
value: 0,
itemStyle: {
normal: {
opacity: 0,
label: {
show: false
}
}
}
}
],
itemStyle: {
color: '#9bdbdc',
areaColor: '#9bdbdc',
// areaColor: {
// type: 'radial', // 径向渐变
// x: 0.5,
// y: 0.5,
// r: 0.8,
// colorStops: [
// // 0% 处的颜色
// {
// offset: 0,
// color: 'rgba(147, 235, 248, 0)'
// },
// // 100% 处的颜色
// {
// offset: 1,
// color: 'rgba(147, 235, 248, .2)'
// }
// ]
// },
// borderColor: 'rgba(147, 235, 248, 1)',
borderColor: '#71cdcb',
borderWidth: 7,
shadowColor: '#b6e7e5',
shadowBlur: 5,
shadowOffsetX: 5,
shadowOffsetY: 5,
},
},
series: [
{
type: 'map',
map: 'china',
roam: false, // 鼠标缩放+平移
aspectScale: 0.9,
zoom: 1.16,
center: [105.194115019531, 35.582111640625], // 设置地图中心
data: this.scatterData,
// geoIndex: 0, // 共享 geo 样式
itemStyle: {
color: {
image: piePatternImg,
repeat: 'repeat'
},
areaColor: {
image: piePatternImg,
repeat: 'repeat'
},
borderColor: '#bddee6',
borderWidth: 1,
},
select: {
label: {
show: false,
color: '#fff'
},
itemStyle: {
areaColor: {
image: patternImg,
repeat: 'repeat'
}
}
},
emphasis: {
label: {
show: false,
color: '#fff'
},
itemStyle: {
areaColor: {
image: patternImg,
repeat: 'repeat'
}
}
}
},
{
type: 'scatter',
coordinateSystem: 'geo',
data: this.scatterData,
symbol: function (params) {
return scatterImg
if (params[2] === '0') {
return 'pin'
} else {
return 'diamond'
}
},
symbolSize: 20,
symbolOffset: [0, '-100%'],
label: {
show: true,
formatter: '{b}',
fontSize: 12,
fontWeight: 'bold',
position: 'top',
backgroundColor: {
image: scatterBg
},
align: 'center',
padding: [8, 15],
color: "#fff",
},
itemStyle: {
color: '#1dfd28'
}
},
]
}
};
},
computed: {},
watch: {
mapData: {
handler(newName, oldName) {
this.initMap();
},
deep: true
}
},
created() { },
mounted() {
this.initMap();
},
methods: {
// 销毁图表实例, 防止内存泄漏
destroyChart() {
let chart = this.$echarts.getInstanceByDom(document.getElementById('baseMap'));
if (chart) {
chart.clear(); // 释放图形资源
chart.dispose(); // 销毁实例对象
}
},
// 图表初始化
initMap() {
this.scatterData = [];
this.mapData.map((item) => {
this.chinaData.map((city) => {
if (item.area == city.name) {
let obj = { ...item, ...city }
this.scatterData.push(obj)
}
})
})
if (this.scatterData.length) {
this.scatterData[0].selected = true;
this.scatterData[0].symbol = scatterHImg;
this.scatterData[0].label = {
backgroundColor: {
image: scatterHBg
}
}
this.scatterData[0].symbolSize = 30;
}
// console.log(this.scatterData)
// this.$emit('handle-map', this.scatterData[0]);
this.destroyChart();
let myChart = this.$echarts.init(document.getElementById('baseMap'));
// 注册地图
this.$echarts.registerMap(this.option.geo.map, this.map);
// 事件解绑
myChart.off('click');
this.$set(this.option.series[1], 'data', this.scatterData);
this.$set(this.option.series[0], 'data', this.scatterData);
myChart.setOption(this.option, true);
// 点击事件
myChart.on('click', e => {
if (!e.data) {
this.scatterData.map(item => {
if (item.symbolSize == 30) {
item.selected = true;
}
})
myChart.setOption(this.option, true);
return
}
// this.$emit('handle-map', this.scatterData[e.dataIndex]);
this.scatterData.map(item => {
item.symbol = item.name == e.name ? scatterHImg : scatterImg
item.label = item.name == e.name ? { backgroundColor: { image: scatterHBg } } : { backgroundColor: { image: scatterBg } };
item.symbolSize = item.name == e.name ? 30 : 20
item.selected = item.name == e.name ? true : false;
})
myChart.setOption(this.option, true);
});
window.addEventListener("resize", () => {
myChart.resize();
});
},
}
};
</script>
<style scoped lang="less">
.container {
position: relative;
width: 100%;
height: 100%;
.xx-map {
width: 100%;
height: 100%;
}
}
</style>
原文地址:https://blog.csdn.net/AisinGioroGouzi/article/details/127122743
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_43870.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!