<template>
<div class="echart_bmap_wrapper">
<div class="btn" type="primary" @click="goBack" size="mini">全国
</div>
<img src="../../assets/largeScreen/fullscreen.png" alt="" class="fullscreen-img" @click="amplify" v-if="typeInfo">
<img src="../../assets/largeScreen/reduce.png" alt="" class="fullscreen-img" @click="reduce" v-if="!typeInfo">
<div class="bmap-box" id="bmapChartBox"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
var provinceMapData = require('@/utils/china.geo.json');
import axios from 'axios'
export default {
name: 'echartBmap',
props: {
mapChange: {
type: Function,
default: null
},
typeInfo: {
type: Boolean,
require: true
},
},
data() {
return {
XY: [],
type: true,
pointData: [],
provinceCodeData: [],
mapStack: [],
nowChooseData: [],
publicUrl: "https://geo.datav.aliyun.com/areas_v3/bound/",
option: {
tooltip: {
show: true,
trigger: 'item',
backgroundColor: 'transparent',
padding: [0, 0, 0, 0],
className: 'custom-tooltip',
borderWidth: 0,
formatter: function (params) {
var str = `
车系:宝马
车型:SUV
姓名:王益
手机号:157368236868
交强险2021-11-11到期
设备脱离告警
车辆维保中
`
return str
},
},
geo: [{
map: 'js',
aspectScale: 0.9,
roam: true,
zoom: 4,
center: [116.405285, 39.904989],
label: {
normal: {
show: true,
textStyle: {
color: '#fff',
fontSize: "14",
}
},
emphasis: {
textStyle: {
color: '#fff'
}
}
},
itemStyle: {
areaColor: {
type: 'radial',
x: 0.7,
y: 0.5,
r: 0.4,
colorStops: [{
offset: 0,
color: '#24cff4'
}, {
offset: 0.5,
color: '#2babd9'
}, {
offset: 1,
color: '#236bb2'
}],
global: false
},
emphasis: {
areaColor: '#56dcf9',
borderWidth: 0
},
borderColor: '#37C1FD',
borderWidth: 2
},
emphasis: {
itemStyle: {
areaColor: '#0160AD'
},
label: {
show: 1,
color: '#fff'
}
},
zlevel: 3
}],
series: [{
type: 'effectScatter',
coordinateSystem: 'geo',
showEffectOn: 'render',
rippleEffect: {
period: 10,
scale: 6,
brushType: 'fill'
},
zlevel: 10,
hoverAnimation: true,
itemStyle: {
normal: {
color: function (params) {
if (params.name == '7300网关') {
return 'red';
}
if (params.name == '700网关') {
return 'yellow';
}
if (params.name == '5300网关') {
return 'green';
} else {
return 'pink';
}
},
shadowBlur: 10,
shadowColor: '#333'
}
},
data: []
},
{
type: 'scatter',
coordinateSystem: 'geo',
data: [],
showEffectOn: 'render',
symbolSize: 30,
label: {
normal: {
show: true,
formatter: function (params) {
return params.name;
},
lineHeight: 15,
backgroundColor: 'rgba(255,255,255,.9)',
borderColor: '#80cffd',
borderWidth: '1',
padding: [2, 2, 2, 2],
color: '#000000',
fontSize: 10,
borderRadius: '15',
fontWeight: 'normal',
},
emphasis: {
show: true
}
},
itemStyle: {
normal: {
color: '#32cd32',
shadowBlur: 10,
shadowColor: '#333'
}
},
emphasis: {
itemStyle: {
color: '#f4e925'
}
},
zlevel: 10,
symbol: 'image://' + require('../../assets/largeScreen/wiebao.png'),
},
{
type: 'scatter',
coordinateSystem: 'geo',
data: [],
showEffectOn: 'render',
symbolSize: 30,
label: {
normal: {
show: true,
formatter: function (params) {
return params.name;
},
lineHeight: 15,
backgroundColor: 'rgba(255,255,255,.9)',
borderColor: '#80cffd',
borderWidth: '1',
padding: [2, 2, 2, 2],
color: '#000000',
fontSize: 10,
borderRadius: '15',
fontWeight: 'normal',
},
emphasis: {
show: true
}
},
itemStyle: {
normal: {
color: '#32cd32',
shadowBlur: 10,
shadowColor: '#333'
}
},
emphasis: {
itemStyle: {
color: '#f4e925'
}
},
zlevel: 10,
symbol: 'image://' + require('../../assets/largeScreen/gaojing.png'),
},
{
type: 'scatter',
coordinateSystem: 'geo',
data: [],
showEffectOn: 'render',
symbolSize: 30,
label: {
normal: {
show: true,
formatter: function (params) {
return params.name;
},
lineHeight: 15,
backgroundColor: 'rgba(255,255,255,.9)',
borderColor: '#80cffd',
borderWidth: '1',
padding: [2, 2, 2, 2],
color: '#000000',
fontSize: 10,
borderRadius: '15',
fontWeight: 'normal',
},
emphasis: {
show: true
}
},
itemStyle: {
normal: {
color: '#32cd32',
shadowBlur: 10,
shadowColor: '#333'
}
},
emphasis: {
itemStyle: {
color: '#f4e925'
}
},
zlevel: 10,
symbol: 'image://' + require('../../assets/largeScreen/daoqi.png'),
},
]
},
gatewayPointData: {
'黑龙江省': [
{
name: '7300网关',
value: [126.642464, 45.756967]
},
],
'哈尔滨市': [
{
name: '7300网关',
value: [126.957401, 45.454116]
},
{
name: '700网关',
value: [126.394846, 45.778706]
},
{
name: '5300网关',
value: [126.606415, 45.807463]
},
{
name: '300网关',
value: [126.483958, 45.876779]
},
{
name: '2300网关',
value: [126.785501, 45.739871]
}
],
},
popShow: false,
popLeft: 0,
popTop: 0,
name: '',
};
},
mounted() {
this.drawMap(provinceMapData, 0, [126.82862, 49.296976]);
this.getProvinceCode();
this.mapStack = []
this.mapStack.push(provinceMapData)
},
methods: {
amplify() {
this.mapChange(1, this.XY)
},
reduce() {
this.mapChange(2, this.XY)
},
getProvinceCode() {
provinceMapData.features.forEach(item => {
this.provinceCodeData.push({
name: item.properties.name,
coordinateCenter: item.properties.center,
cityCode: item.properties.adcode
})
});
},
goBack() {
this.popShow = false
this.mapStack = []
this.mapStack.push(provinceMapData)
this.drawMap(provinceMapData, 0, [126.82862, 49.296976]);
},
setMapCenterZoomData(data, zoom, center, info, info1, info2) {
this.option.series[0].data = data;
this.option.series[1].data = info;
this.option.series[2].data = info1;
this.option.series[3].data = info2;
this.option.geo[0].zoom = zoom;
this.option.geo[0].center = center;
if (this.mapStack.length <= 1) {
this.option.geo[0].layoutSize = '100%';
this.option.geo[0].layoutCenter = ['85%', '20%'];
} else {
this.option.geo[0].layoutSize = '';
this.option.geo[0].layoutCenter = [];
}
},
drawMap(json, type = 0, city) {
if (document.getElementById('bmapChartBox') == null) {
return
}
echarts.dispose(document.getElementById('bmapChartBox'))
this.echarts = echarts;
this.dom = document.getElementById('bmapChartBox');
this.myChart = this.echarts.init(this.dom);
this.echarts.registerMap('js', json);
if (type == 1) {
this.pointData = this.gatewayPointData[city];
if (this.pointData) {
console.log(this.pointData, 1)
this.setMapCenterZoomData(this.pointData, 1.2, this.pointData[0].value, this.pointData,);
} else {
this.nowChooseData.forEach(i => {
i.value = i.coordinateCenter
})
this.pointData = this.nowChooseData
console.log(this.pointData, 2)
var center = this.nowChooseData[0].coordinateCenter;
this.setMapCenterZoomData(this.pointData, 1.2, center, this.pointData,);
}
} else {
this.myChart.clear();
console.log(this.pointData, 3)
this.setMapCenterZoomData([[111.670801, 40.818311], [109.840405, 40.658168]],
1.3,
[127.82862, 49.296976],
[[112.670801, 40.818311], [117.840405, 40.658168], [113.670801, 38.818311], [116.840405, 42.658168]],
[[118.670801, 49.818311], [119.840405, 30.658168], [111.670801, 31.818311], [116.840405, 49.658168]],
[[102.670801, 40.818311], [109.840405, 40.658168], [112.670801, 36.818311], [121.840405, 40.658168]],
);
}
this.myChart.setOption(this.option);
this.myChart.off('click');
this.myChart.on('click', (param) => {
let data = this.myChart.convertFromPixel('geo', [param.event.event.offsetX, param.event.event.offsetY])
console.log(data, 111111111)
this.XY = data
this.popLeft = param.event.event.offsetX
this.popTop = param.event.event.offsetY
this.name = param.name
this.popShow = true
if (param.componentType == "geo") {
} else {
return;
}
if (this.mapStack.length >= 3) {
this.$notify({
message: '没有更多啦!',
type: 'warning',
duration: 2000
});
return;
}
const city = param.name;
var cityCode = ''
if (this.mapStack.length <= 1) {
this.provinceCodeData.forEach(i => {
if (i.name == city) {
cityCode = i.cityCode
}
})
} else {
this.nowChooseData.forEach(i => {
if (i.name == city) {
cityCode = i.cityCode
}
})
}
this.getHomeMapData(city, cityCode)
});
},
getHomeMapData(city, cityCode) {
var cityMapData
var data
if (cityCode == 710000) {
data = cityCode
} else {
data = cityCode + '_full.json'
}
axios.get(this.publicUrl + data).then(res => {
console.log(res)
if (res) {
cityMapData = res.data
if (this.mapStack.length < 3) {
this.mapStack.push(cityMapData);
}
this.nowChooseData = []
cityMapData.features.forEach(item => {
this.nowChooseData.push({
name: item.properties.name,
coordinateCenter: item.properties.center,
cityCode: item.properties.adcode
})
});
cityMapData && this.myChart.clear();
cityMapData && this.drawMap(cityMapData, 1, city);
}
}).catch((err) => {
this.$message(err.message);
});
},
}
};
</script>
<style lang="scss" scoped>
.fullscreen-img {
width: 1.5vw;
height: 1.5vw;
display: block;
position: absolute;
left: 15%;
top: 20px;
cursor: pointer;
z-index: 2;
}
.echart_bmap_wrapper {
position: relative;
.btn {
position: absolute;
left: 8%;
top: 20px;
z-index: 1;
padding: 0.5vh 0.5vw;
color: #C3CDE5;
box-shadow: inset 0px 0px 11px 0px rgba(143, 239, 252, 0.5);
border-radius: 3px;
border: 1px solid #2EA8D0;
cursor: pointer;
}
.bmap-box {
width: 100%;
height: 100%;
}
.popWin {
position: absolute;
left: 0;
top: 0;
background: #00305c;
background-size: 100% 100%;
width: 408px;
height: 300px;
z-index: 100;
.popLine {
width: 340px;
height: 1px;
background: linear-gradient(90deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
opacity: 0.3;
margin-left: 30px;
}
.titleInfos {
text-align: center;
margin-left: 30px;
font-size: 22px;
font-family: YouSheBiaoTiHei;
font-weight: 400;
color: #00FDFE;
height: 50px;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
.pop_close {
color: #bbb;
cursor: pointer;
padding: 5px;
font-size: 12px;
position: absolute;
top: 5px;
right: 10px;
}
}
}
.infoBody {
width: 100%;
padding: 3%;
.homeTable {
border: 1px solid #0376ae;
border-radius: 10px;
}
}
.infoBody ::v-deep .plTableBox .el-table .cell.el-tooltip {
border-bottom: 1px solid #086896;
}
.infoBody ::v-deep .el-table,
.el-table__expanded-cell {
background-color: transparent;
}
.infoBody ::v-deep .el-table tr {
background-color: #0b4d73;
}
.infoBody ::v-deep .el-table--enable-row-transition .el-table__body td,
.el-table .cell {
background-color: transparent;
}
.el-table::before {
left: 0;
bottom: 0;
width: 100%;
height: 0px;
}
.infoBody ::v-deep .plTableBox .el-table .el-table__header th {
background-color: transparent;
}
.infoBody ::v-deep .plTableBox .el-table--enable-row-hover .el-table__body tr:hover>td {
background-color: rgba(0, 77, 167, 1);
}
.infoBody ::v-deep .plTableBox .el-table--border td,
.infoBody ::v-deep .plTableBox .el-table--border th,
.infoBody ::v-deep .plTableBox .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed {
border: none;
color: #4daad3
}
.infoBody ::v-deep .plTableBox .el-table--medium td {
padding: 0;
}
.infoBody ::v-deep .plTableBox .el-table__header-wrapper {
background-color: transparent;
}
.infoBody ::v-deep .plTableBox .el-table--striped .el-table__body tr.el-table__row--striped td {
background-color: #103c5c;
}
}
</style>