<template>
<div class="map">
<div id="map" :style="{ height: height, width: width }"></div>
</div>
</template>
initChart() {
let myChart = echarts.init(document.getElementById("map"), "macarons");
window.addEventListener("resize", () => {
myChart.resize();
});
console.log(myChart);
echarts.registerMap("china", china);
const points = [
{ name: "大同市", value: ["125.03", "46.58", "10"] },
{ name: "九江市", value: ["115.97", " 29.71", "2"] },
{ name: "海南省", value: ["116.821983", "34.929515", "5"] },
];
const geoCoordMap = china.features;
console.log(geoCoordMap);
const convertData = function (data) {
const res = [];
for (let i = 0; i < data.length; i++) {
let dataItem = data[i];
let fromCoord, toCoord;
geoCoordMap.map((g) => {
if (dataItem[0].name == g["properties"]["name"]) {
fromCoord = g["properties"]["centroid"];
}
if (dataItem[1].name == g["properties"]["name"]) {
toCoord = g["properties"]["centroid"];
}
if (fromCoord && toCoord) {
res.push([
{
coord: fromCoord,
},
{
coord: toCoord,
},
]);
}
});
}
return res;
};
const option = {
visualMap: {
type: "continuous",
min: 0,
max: 12,
splitNumber: 3,
inRange: {
color: ["#dec674", "#ffc20e"],
},
textStyle: {
color: "#fff",
},
show: false,
},
geo: {
map: "china",
roam: true,
center: [110.97, 35.71],
layoutCenter: ["100%", "100%"],
zoom: 2,
scaleLimit: {
min: 1,
max: 6,
},
label: {
normal: {
show: true,
textStyle: {
color: "#fff",
fontSize: 8,
},
},
emphasis: {
show: true,
textStyle: {
color: "#fff",
},
},
},
itemStyle: {
normal: {
borderColor: "rgba(15, 168, 255, 0.5)",
areaColor: "['rgba(0,23,58,0.8)']",
color: "rgba(0,23,58,0.8)",
},
emphasis: {
borderWidth: 1,
borderColor: "rgba(0,3,58,0.8)",
areaColor: "rgba(0,123,58,0.8)",
label: {
show: false,
textStyle: {
color: "#fff",
},
},
},
},
},
bmap: {
center: [104.114129, 37.550339],
zoom: 5,
roam: true,
},
series: [
{
name: "",
type: "effectScatter",
coordinateSystem: "geo",
data: points,
symbolSize: function (val) {
return val[2] * 5;
},
itemStyle: {
normal: {
color: "#ddb926",
},
},
},
{
type: "lines",
zlevel: 10,
symbol: ["none", "arrow"],
lineStyle: {
normal: {
type: "dashed",
color: "rgb(204,102,51)",
width: 1,
curveness: 0.4,
},
},
data: convertData([
[{ name: "北京市" }, { name: "江苏省" }],
[{ name: "浙江省" }, { name: "辽宁省" }],
[{ name: "辽宁省" }, { name: "海南省" }],
]),
},
],
};
console.log(324523, option);
myChart.setOption(option);
myChart.on("georoam", function (params) {
var option = myChart.getOption();
if (params.zoom != null && params.zoom != undefined) {
option.geo[1].zoom = option.geo[0].zoom;
option.geo[1].center = option.geo[0].center;
} else {
option.geo[1].center = option.geo[0].center;
}
myChart.setOption(option);
});
},