1.安装echarts npm install echarts --save
2 挂载到vue原型上
3.编写3d地图组件即可
<template>
<div id="safetyMapct" class="project-map"></div>
</template>
<script>
//换成自己所需的行政区地图json
import ziji from "@/assets/json/ct.json";
export default {
data() {
return {
};
},
mounted() {
this.initEcharts();
},
methods: {
initEcharts() {
var data3d = [
{
name: '某地方',
value: [119.72385, 27.562508, 5],
pathName: require("@/assets/images/carousel1.jpg"),
lineName: '某地方'
},
{
name: '某地方',
value: [119.921587, 27.430135, 5],
pathName: require("@/assets/images/carousel1.jpg"),
lineName: '某地方'
},
{
name: '某地方',
value: [120.40004, 27.390077, 5],
pathName: require("@/assets/images/carousel1.jpg"),
lineName: '某地方'
},
{
name: '某地方',
value: [120.477368, 27.177313, 5],
pathName: require("@/assets/images/carousel1.jpg"),
lineName: '某地方'
}
];
var linesData = [{
fromName: "中心机房",
toName: "机房1",
coords: [
[119.72385, 27.562508],
[119.840283, 27.494724],
]
},
{
fromName: "中心机房",
toName: "机房2",
coords: [
[119.840283, 27.494724],
[119.894175, 27.460023],
]
},
{
fromName: "中心机房",
toName: "机房3",
coords: [
[119.894175, 27.460023],
[119.921587, 27.430135],
]
},
{
fromName: "中心机房",
toName: "机房4",
coords: [
[119.921587, 27.430135],
[120.052239, 27.412451],
]
},
{
fromName: "中心机房",
toName: "机房5",
coords: [
[85.74, 41.60, 1],
[85.50, 41.99, 1],
]
},
];
let iconUrl = document.createElement("img");
let labelUrl = document.createElement("img");
iconUrl.src = require("@/assets/images/digital-table-screen/safety-profile/ruihu-map-z-index.png");
labelUrl.src = require("@/assets/images/digital-table-screen/safety-profile/ruihu-map-z-index.png");
let option = {
geo3D: {
map: 'centerMap',
show: false,
zlevel: -10,
boxWidth: 200,
boxHeight: 4, //4:没有bar. 30:有bar,bar最高度30,按比例分配高度
regionHeight: 8,
shading: 'lambert',
left: "5%",
viewControl: {
projection: 'perspective',
autoRotate: false,
damping: 0,
rotateSensitivity: 2, //旋转操作的灵敏度
rotateMouseButton: 'left', //旋转操作使用的鼠标按键
zoomSensitivity: 2, //缩放操作的灵敏度
panSensitivity: 2, //平移操作的灵敏度
panMouseButton: 'right', //平移操作使用的鼠标按键
distance: 150, //默认视角距离主体的距离
center: [0, 0, 0],
animation: true,
animationDurationUpdate: 1000,
animationEasingUpdate: 'cubicInOut'
},
},
series: [
{
type: 'map3D',
map: 'centerMap',
show: true,
zlevel: 1,
boxWidth: 200,
//boxHeight: 4, //4:没有bar. 30:有bar,bar最高度30,按比例分配高度
regionHeight: 8,
shading: 'lambert',
label: { // 标签的相关设置
show: false,
},
left: "5%",
itemStyle: {
color: '#025894',
areaColor: '#025894',
opacity: 1,
borderWidth: 1,
borderColor: '#1cccff'
},
emphasis: {
label: {
show: false,
textStyle: {
color: '#fff',
fontSize: 14,
backgroundColor: 'transparent' // 字体背景色
}
},
borderColor: '#333',
borderWidth: 5,
itemStyle: {
color: '#025894',
areaColor: '#025894',
}
},
light: {
main: {
shadow: true,
shadowQuality: 'ultra',
},
},
viewControl: {
projection: 'perspective',
autoRotate: false,
damping: 0,
rotateSensitivity: 2, //旋转操作的灵敏度
rotateMouseButton: 'left', //旋转操作使用的鼠标按键
zoomSensitivity: 2, //缩放操作的灵敏度
panSensitivity: 2, //平移操作的灵敏度
panMouseButton: 'right', //平移操作使用的鼠标按键
distance: 150, //默认视角距离主体的距离
center: [0, 0, 0],
animation: true,
animationDurationUpdate: 1000,
animationEasingUpdate: 'cubicInOut'
},
},
{
type: 'scatter3D',
coordinateSystem: 'geo3D',
zlevel: 3,
//symbol: 'path://m232.99844,160.209511l15.863519,0l0,-14.211071l16.27296,0l0,14.211071l15.863521,0l0,14.577861l-15.863521,0l0,14.211069l-16.27296,0l0,-14.211069l-15.863519,0l0,-14.577861z',
symbol: 'circle',
symbolSize: 16,
label: {
normal: {
show: true,
position: 'right',
formatter: '{b}',
textStyle: {
color: '#fff',
fontSize: 14,
backgroundColor: 'transparent' // 字体背景色
},
}
},
data: data3d,
itemStyle: { //坐标点颜色
color: '#2681cf',
shadowBlur: 20,
shadowColor: '#fff'
},
emphasis: {
itemStyle: { //坐标点颜色
color: '#1ca1d2',
},
}
},
// 线 和 点
{
type: 'lines3D',
coordinateSystem: 'geo3D',
zlevel: 1, //设置这个才会有轨迹线的小尾巴
polyline: false,
effect: {
show: true,
period: 10,
trailLength: 0.1,
trailColor: '#17eafe',
color: '#fff', //流动点颜色
symbol: 'arrow',
symbolSize: 6
},
lineStyle: {
normal: {
color: '#fff', //线条颜色
width: 1,
curveness: 0.5,
shadowColor: '#fff',
}
},
blendMode: 'lighter',
data: linesData,
},
]
};
this.$echarts.registerMap('centerMap', ziji);
this.myChart = this.$echarts.init(document.getElementById("safetyMapct"));
this.myChart.setOption(option, true);
// img.onload = () => {
// this.myChart.setOption(option, true);
// }
window.addEventListener("resize", this.listenResize);
},
listenResize() {
this.myChart.resize();
},
},
beforeDestroy() {
window.removeEventListener("resize", this.listenResize);
}
};
</script>
<style scoped lang="scss">
.project-map {
width: rem(800);
height: vh(564);
position: absolute;
canvas {
width: rem(800) !important;
height: vh(564) !important;
}
}
::v-deep .tooltipArea {
width: rem(310);
height: rem(150);
padding: 0 rem(10);
background-color: rgba(8, 19, 51, 0.9);
.tooltip-header {
width: 100%;
height: rem(26);
line-height: rem(26);
text-align: center;
font-size: rem(16);
font-family: YouSheBiaoTiHei;
font-weight: 400;
color: #FFFFFF;
text-shadow: 0px 2px 0px rgba(0, 2, 3, 0.88);
background: linear-gradient(90deg, rgba(18, 33, 76, 0.04) 0%, rgba(35, 89, 170, 0.8) 50%, rgba(29, 45, 92, 0.03) 100%);
}
.tooltip-content {
display: flex;
.tooltip-content-left {
width: rem(90);
height: rem(100);
margin-top: rem(8);
}
.tooltip-content-right {
font-size: rem(14);
font-family: PingFang SC;
font-weight: bold;
color: #FFFFFF;
text-shadow: 0px 3px 0px rgba(0, 2, 3, 0.88);
padding: rem(10);
.right-item {
margin: rem(10) 0 rem(16);
span {
margin-right: rem(8);
}
}
.right-bottom {
display: flex;
justify-content: space-around;
align-items: center;
.right-line {
width: 2px;
height: 25px;
border: 2px solid #5F9BFF;
}
.bottom-number {
font-size: 20px;
font-family: PingFang SC;
font-weight: bold;
color: #00E4FF;
margin-bottom: rem(6);
text-shadow: 0px 3px 0px rgba(0, 2, 3, 0.88);
}
.bottom-unit {
font-size: 12px;
font-family: PingFang SC;
font-weight: bold;
color: #00E4FF;
text-shadow: 0px 3px 0px rgba(0, 2, 3, 0.88);
}
}
}
}
}
</style>
4. 来看看效果吧