<script>
import { getXheliJLChart } from "@/api/index.js";
export default {
data() {
return {
mapData: [],
inline: [],
chart: null,
place: "浙江省",
inStartPoint: {
浙江省: [118.552791, 31.267446],
杭州市: [118.852791, 30.867446],
湖州市: [119.452791, 31.267446],
嘉兴市: [120.482791, 31.067446],
绍兴市: [120.132791, 30.327446],
舟山市: [121.652791, 30.867446],
宁波市: [120.902791, 30.567446],
温州市: [119.852791, 28.667446],
丽水市: [118.852791, 28.967446],
台州市: [120.552791, 29.367446],
衢州市: [118.152791, 29.567446],
金华市: [119.552791, 29.767446],
},
};
},
created() {
this.init();
},
mounted() {},
methods: {
init() {
getXheliJLChart({
year: 2022,
industry: "产业",
address: this.place,
}).then((res) => {
this.mapData = res.regionDetailList;
this.mapData = this.mapData.map((item, index) => {
return {
name: item.regionName,
value: item.needPeopleMagnification,
};
});
if (this.chart) {
this.setMapOption();
} else {
this.initMap();
}
});
},
initMap() {
let that = this;
this.chart = this.$echarts.init(document.getElementById("map"));
this.chart.getZr().on("click", function (params) {
if (!params.target) {
if (that.place !== "浙江省") {
that.place = "浙江省";
that.init("浙江省");
}
}
});
this.chart.on("click", function (params) {
console.log(params.name);
that.$emit("place", params.name);
if (that.place === "浙江省") {
that.place = params.name;
that.init();
}
});
this.setMapOption();
},
setMapOption() {
this.chart.clear();
let hz, hz_bg;
if (this.place === "浙江省") {
hz = require("../../../../static/china_province/330000_full.json");
hz_bg = require("../../../../static/china_province/330000.json");
} else {
hz = require(`../../../../static/zhejiang/${this.place}.json`);
hz_bg = require(`../../../../static/zhejiang/bg/${this.place}.json`);
}
let arr = [];
hz.features.forEach((element, index) => {
arr.push([this.inStartPoint[this.place], element.properties.center]);
});
this.inline = arr;
this.$echarts.registerMap("hz", hz);
this.$echarts.registerMap("hz_bg", hz_bg);
this.option = {
tooltip: {
show: false,
formatter: "{b}:{c}",
},
geo: [
{
geoIndex: 1,
map: "hz_bg",
itemStyle: {
areaColor: {
type: "linear",
x: 0.2,
y: 0,
x2: 1,
y2: 0.5,
colorStops: [
{
offset: 0,
color: "rgba(0, 162, 247, 1)",
},
{
offset: 1,
color: "rgba(0, 36, 109, 1)",
},
],
global: false,
},
borderWidth: 2,
borderColor: "rgba(255,174,59,0.6)",
},
emphasis: {
disabled: true,
},
tooltip: {
show: false,
},
},
{
map: "hz",
show: true,
itemStyle: {
areaColor: "rgba(0,0,0,0)",
color: "rgba(0,0,0,0)",
shadowColor: "#00002A",
shadowBlur: 10000,
opacity: 1,
borderWidth: 1,
borderColor: "rgba(255,174,59,0.6)",
},
},
],
series: [
{
type: "map",
mapType: "hz",
label: {
show: true,
formatter: "{c}\n {b}",
color: "#fff",
},
itemStyle: {
normal: {
areaColor: "rgba(0,0,0,0)",
color: "rgba(0,0,0,0)",
},
emphasis: {
show: false,
},
},
data: this.mapData,
nameMap: {
临安区: "临安市",
奉化区: "奉化市",
玉环市: "玉环县",
龙港市: "龙岗市",
},
},
{
type: "lines",
coordinateSystem: "geo",
zlevel: 15,
effect: {
show: true,
period: 3,
delay: function () {
return Math.ceil(Math.random() * 1000);
},
trailLength: 0.3,
symbol: "arrow",
color: "#fff791",
symbolSize: 6,
},
lineStyle: {
normal: {
width: 1,
opacity: 0.1,
curveness: 0.3,
color: "#C2E9E7",
type: "solid",
},
},
data: this.inline,
},
],
};
this.chart.setOption(this.option);
},
},
};
</script>
|