2023-11-30 10:48:06 +08:00
|
|
|
<template>
|
2023-12-01 11:19:43 +08:00
|
|
|
<div :id="'mapEcharts' + idType" style="width: 100%;height: 100%;" ></div>
|
2023-11-30 10:48:06 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import * as echarts from 'echarts'
|
2023-12-01 11:19:43 +08:00
|
|
|
const propsVal: any = defineProps({
|
|
|
|
|
idType: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '0'
|
2023-11-30 20:18:54 +08:00
|
|
|
},
|
2023-12-01 11:19:43 +08:00
|
|
|
jsonData: {
|
2023-11-30 20:18:54 +08:00
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-11-30 10:48:06 +08:00
|
|
|
title: {//标题
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
itemStyle: {//地图项样式
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
areaColor: '#186894',//区域颜色
|
|
|
|
|
shadowColor: '#2894c9',//边缘阴影颜色
|
|
|
|
|
color: 'rgba(255, 255, 255, 1)'//文字颜色
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
emphasisLabelStyle: {//鼠标移入 文本 label 高亮的样式
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
color: "rgba(255, 255, 255, 1)"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
emphasisItemStyle: {//鼠标移入 地图高亮样式
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
areaColor: '#39baf6',
|
|
|
|
|
shadowColor: '#2894c9',
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
labelInfo: {
|
|
|
|
|
type: Object,//地图标签配置 如 云南省等
|
|
|
|
|
default: {
|
|
|
|
|
show: true,
|
|
|
|
|
color: 'rgba(255,255,255,0.6)',
|
|
|
|
|
position: 'inside',
|
|
|
|
|
distance: 0,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
rotate: 0,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
rippleEffect: {//点的闪烁配置
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
number: 4,
|
|
|
|
|
period: 4,
|
|
|
|
|
scale: 4.5,
|
|
|
|
|
brushType: 'fill'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tooltipProps: {//鼠标移动提示框的样式
|
|
|
|
|
type: Object,
|
|
|
|
|
default: {
|
|
|
|
|
show: false,//是否显示,默认不显示
|
|
|
|
|
backgroundColor: '#fff'//提示框的背景色
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tooltipFormat: {//提示 格式
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => { }
|
|
|
|
|
},
|
|
|
|
|
itemColorFormat: {//颜色格式化
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => { }
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
seriesData: {//地图点标记数据
|
|
|
|
|
type: Array,
|
|
|
|
|
default: []
|
2023-12-01 11:19:43 +08:00
|
|
|
},
|
|
|
|
|
effectScatterCallBack: {//effectScatter 点击事件
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => { }
|
|
|
|
|
},
|
2023-11-30 10:48:06 +08:00
|
|
|
})
|
|
|
|
|
const initEcharts = () => {
|
2023-11-30 20:18:54 +08:00
|
|
|
echarts.registerMap('guangdong', propsVal.jsonData)
|
2023-11-30 10:48:06 +08:00
|
|
|
nextTick(() => {
|
2023-12-01 11:19:43 +08:00
|
|
|
const domitem = document.getElementById("mapEcharts" + propsVal.idType)
|
2023-11-30 20:18:54 +08:00
|
|
|
const map = echarts.init(domitem, null, {
|
2023-11-30 10:48:06 +08:00
|
|
|
renderer: 'canvas',
|
|
|
|
|
})
|
|
|
|
|
const option = {
|
|
|
|
|
title: propsVal.title,
|
|
|
|
|
// 悬浮窗
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'item',//触发条件
|
|
|
|
|
},
|
|
|
|
|
geo: {
|
|
|
|
|
map: 'guangdong',
|
|
|
|
|
zoom: 1,
|
2023-12-01 09:54:11 +08:00
|
|
|
roam: '',
|
2023-11-30 10:48:06 +08:00
|
|
|
label: propsVal.labelInfo,
|
|
|
|
|
// 所有地图的区域颜色
|
|
|
|
|
itemStyle: propsVal.itemStyle,
|
|
|
|
|
emphasis: {
|
|
|
|
|
label: propsVal.emphasisLabelStyle,
|
|
|
|
|
itemStyle: propsVal.emphasisItemStyle
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
...propsVal.tooltipProps,
|
|
|
|
|
formatter: (params: any) => {
|
|
|
|
|
return propsVal.tooltipFormat(params)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Top 5',
|
|
|
|
|
type: 'effectScatter',
|
|
|
|
|
colorBy: 'series',
|
|
|
|
|
effectType: 'ripple',
|
|
|
|
|
showEffectOn: 'render',
|
|
|
|
|
rippleEffect: propsVal.rippleEffect,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
color: (params: any) => {
|
|
|
|
|
return propsVal.itemColorFormat(params)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
coordinateSystem: 'geo',
|
2023-12-01 11:19:43 +08:00
|
|
|
data: propsVal.seriesData,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'eventDom',
|
|
|
|
|
type: 'scatter',
|
|
|
|
|
coordinateSystem: 'geo',
|
|
|
|
|
data: propsVal.seriesData,
|
|
|
|
|
symbolSize: 32,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
color:"rgba(255,255,255,0)"
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-11-30 10:48:06 +08:00
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
map.setOption(option)
|
2023-12-01 11:19:43 +08:00
|
|
|
chartClickEventListener(map)
|
2023-11-30 10:48:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
console.log("propsval", propsVal)
|
|
|
|
|
initEcharts()
|
2023-12-01 11:19:43 +08:00
|
|
|
|
2023-11-30 10:48:06 +08:00
|
|
|
})
|
2023-12-01 11:19:43 +08:00
|
|
|
const chartClickEventListener = (mychart: any) => {
|
|
|
|
|
mychart.on("click", (parmas: any) => {
|
|
|
|
|
propsVal.effectScatterCallBack(parmas)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 10:48:06 +08:00
|
|
|
|
2023-12-01 11:19:43 +08:00
|
|
|
const chagneJSON = (item: any) => {
|
2023-11-30 20:18:54 +08:00
|
|
|
console.log("propsval", propsVal)
|
2023-12-01 11:19:43 +08:00
|
|
|
propsVal.idType = item.navId
|
|
|
|
|
setTimeout(() => {
|
2023-11-30 20:18:54 +08:00
|
|
|
initEcharts()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
defineExpose({
|
|
|
|
|
chagneJSON
|
|
|
|
|
})
|
|
|
|
|
|
2023-11-30 10:48:06 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.map-echart {
|
|
|
|
|
height: 600px;
|
|
|
|
|
width: 900px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|