2025-06-27 10:04:22 +08:00

533 lines
23 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="../lib/jquery/dist/jquery.js"></script>
<script src="../lib/vuejs/vue.js"></script>
<script src="../lib/echarts5temp/composition-api1.0.0-rc.js"></script>
<script src="../lib/echarts5temp/echarts5.0.2.js"></script>
<script src="../lib/echarts5temp/vue-echarts6.0.0-beta.js"></script>
<script src="../lib/vuejs/axios.min.js"></script>
<script src="../lib/elementui/index.js"></script>
<link href="../lib/elementui/index.css" rel="stylesheet" />
<script src="../map/china.js"></script>
</head>
<body>
<div id="app" style="background-color:#013954;">
<el-container>
<!--<el-header>-->
<!--{{geoJson}}-->
<!--</el-header>-->
<el-main>
<div id="main" style="width: 100%;height:700px;">
</div>
</el-main>
</el-container>
</div>
</body>
</html>
<script>
var app = new Vue({
el: '#app',
data() {
return {
d1: {},
geoJson: {}
}
},
mounted() {
var _this = this; //this指向vue
let sendArr = [
axios.get('../map/data-qianxi.json'),
axios.get('./home/SearchQianXi?year=2020')
]
axios.all(sendArr).then(axios.spread(function (res1, res2) {
_this.geoJson = res1.data
_this.d1 = res2.data
_this.refreshMap()
}));
},
methods: {
//图形计算
refreshMap() {
var _this = this; //this指向vue
var year = ["2020"];
var mapData = [
[],
[],
];
/*柱子Y名称*/
var categoryData = [];
var barData = [];
for (var key in geoCoordMap) {
mapData[0].push({
"year": '2020',
"name": key,
"value": _this.d1[key],
"value1": _this.d1[key],
});
}
for (var i = 0; i < mapData.length; i++) {
mapData[i].sort(function sortNumber(a, b) { return a.value - b.value });
barData.push([]);
categoryData.push([]);
for (var j = 0; j < mapData[i].length; j++) {
barData[i].push(mapData[i][j].value1);
categoryData[i].push(mapData[i][j].name);
}
}
console.log(_this.geoJson);
echarts.registerMap('china', _this.geoJson);
var convertData = function (data) {
var res = [];
for (var i = 0; i < data.length; i++) {
var geoCoord = geoCoordMap[data[i].name];
if (geoCoord) {
res.push({
name: data[i].name,
value: geoCoord.concat(data[i].value)
});
}
}
return res;
};
var convertToLineData = function (data, gps) {
var res = [];
for (var i = 0; i < data.length; i++) {
var dataItem = data[i];
var toCoord = geoCoordMap[dataItem.name];
var fromCoord = gps; //郑州
// var toCoord = geoGps[Math.random()*3];
if (fromCoord && toCoord) {
if (t == 1) {
res.push([{
coord: toCoord,
}, {
coord: fromCoord,
value: dataItem.value
}]);
} else {
res.push([{
coord: fromCoord,
value: dataItem.value
}, {
coord: toCoord,
}]);
}
}
}
if (t == 0) {
t = 1;
} else {
t = 1;
}
return res;
};
optionXyMap01 = {
timeline: {
data: year,
axisType: 'category',
autoPlay: false,
playInterval: 5000,
left: '10%',
right: '10%',
bottom: '3%',
width: '80%',
//height: null,
//设定现实不现实时间轴的参数
show: false,
label: {
normal: {
textStyle: {
color: '#ddd'
}
},
emphasis: {
textStyle: {
color: '#fff'
}
}
},
symbolSize: 10,
lineStyle: {
color: '#555'
},
checkpointStyle: {
borderColor: '#777',
borderWidth: 2
},
controlStyle: {
showNextBtn: true,
showPrevBtn: true,
normal: {
color: '#666',
borderColor: '#666'
},
emphasis: {
color: '#aaa',
borderColor: '#aaa'
}
},
},
baseOption: {
animation: true,
animationDuration: 1000,
animationEasing: 'cubicInOut',
animationDurationUpdate: 1000,
animationEasingUpdate: 'cubicInOut',
grid: {
right: '2%',
top: '12%',
bottom: '12%',
width: '18%'
},
backgroundColor: '#2c343c',
tooltip: {
trigger: 'axis', // hover触发器
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
shadowStyle: {
color: 'rgba(150,150,150,0.1)' //hover颜色
}
}
},
visualMap: {
min: 0,
max: 150,
left: 'left',
top: 'bottom',
text: ['高', '低'],
textStyle: {
color: 'white'
},
calculable: true,
colorLightness: [0.8, 100],
color: ['#c05050', '#e5cf0d', '#5ab1ef'],
dimension: 0,
},
geo: {
show: true,
map: 'china',
roam: true,
zoom: 1,
center: [113.83531246, 34.0267395887],
label: {
emphasis: {
show: true
}
},
itemStyle: {
normal: {
borderColor: 'rgba(147, 235, 248, 1)',
borderWidth: 1,
areaColor: {
type: 'radial',
x: 0.5,
y: 0.5,
r: 0.8,
colorStops: [{
offset: 0,
color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色
}, {
offset: 1,
color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色
}],
globalCoord: false // 缺省为 false
},
shadowColor: 'rgba(128, 217, 248, 1)',
// shadowColor: 'rgba(255, 255, 255, 1)',
shadowOffsetX: -2,
shadowOffsetY: 2,
shadowBlur: 10
},
emphasis: {
areaColor: '#389BB7',
borderWidth: 0
}
}
},
},
options: []
};
for (var n = 0; n < year.length; n++) {
var statistic_name = "各省" + "数量";
optionXyMap01.options.push({
title:
[{
text: '2020年采样数据流向图',
//subtext: ' ',
left: '11%',
top: '1%',
textStyle: {
color: '#fff',
fontSize: 25
}
},
{
id: 'statistic',
text: statistic_name,
left: '75%',
top: '3%',
textStyle: {
color: '#fff',
fontSize: 16
}
}
],
xAxis: {
type: 'value',
scale: true,
position: 'top',
min: 0,
boundaryGap: false,
splitLine: {
show: false
},
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
margin: 1,
textStyle: {
color: '#aaa'
}
},
},
yAxis: {
type: 'category',
// name: 'TOP 20',
nameGap: 16,
axisLine: {
show: true,
lineStyle: {
color: '#ddd'
}
},
axisTick: {
show: false,
lineStyle: {
color: '#ddd'
}
},
axisLabel: {
interval: 0,
textStyle: {
color: '#ddd'
}
},
data: categoryData[n]
},
series: [
//未知作用
{
//文字和标志
name: 'light',
type: 'scatter',
coordinateSystem: 'geo',
data: convertData(mapData[n]),
symbolSize: function (val) {
return 6;
},
label: {
normal: {
formatter: '{b}',
position: 'right',
show: true
},
emphasis: {
show: true
}
},
itemStyle: {
normal: {
color: colors[n]
}
}
},
//地图?
{
type: 'map',
map: 'china',
geoIndex: 0,
aspectScale: 1, //长宽比
showLegendSymbol: false, // 存在legend时显示
label: {
normal: {
show: false
},
emphasis: {
show: false,
textStyle: {
color: '#fff'
}
}
},
roam: true,
itemStyle: {
normal: {
areaColor: '#031525',
borderColor: '#FFFFFF',
},
emphasis: {
areaColor: '#2B91B7'
}
},
animation: false,
data: mapData
},
//地图点的动画效果
{
// name: 'Top 5',
type: 'effectScatter',
coordinateSystem: 'geo',
data: convertData(mapData[n].sort(function (a, b) {
return b.value - a.value;
}).slice(0, 20)),
symbolSize: function (val) {
return 5;
},
showEffectOn: 'render',
rippleEffect: {
brushType: 'stroke'
},
hoverAnimation: true,
label: {
normal: {
formatter: '{b}',
position: 'right',
show: true
}
},
itemStyle: {
normal: {
color: colors[n],
shadowBlur: 10,
shadowColor: colors[n]
}
},
zlevel: 1
},
//地图线的动画效果
{
type: 'lines',
zlevel: 2,
effect: {
show: true,
period: 5, //箭头指向速度,值越小速度越快
trailLength: 0.2, //特效尾迹长度[0,1]值越大,尾迹越长重
symbol: 'arrow', //箭头图标
symbolSize: 6, //图标大小
},
lineStyle: {
normal: {
color: colors[n],
width: 1, //尾迹线条宽度
opacity: 0.2, //尾迹线条透明度
curveness: .3 //尾迹线条曲直度
}
},
data: convertToLineData(mapData[n], geoGpsMap)
},
//柱状图
{
zlevel: 1.5,
type: 'bar',
barMaxWidth: 8,
symbol: 'none',
itemStyle: {
normal: {
color: colors[n],
barBorderRadius: [0, 30, 30, 0]
}
},
data: barData[n]
}
]
});
if (r == 0) {
r = 1;
} else {
r = 0;
}
}
myChart.setOption(optionXyMap01);
}
}
}
)
var myChart = echarts.init(document.getElementById('main'));
//var uploadedDataURL = "../map/data-qianxi.json";
//var geoGpsMap = [120.38, 36.07];
var geoGpsMap = [121.4648, 31.2891];
var t = 1;//流入流出控制
var r = 1;//右侧流入流出文字控制
var geoCoordMap = {
"江苏省": [118.8062, 31.9208],
'黑龙江省': [127.9688, 45.368],
'内蒙古自治区': [110.3467, 41.4899],
"吉林省": [125.8154, 44.2584],
'北京市': [116.4551, 40.2539],
"辽宁省": [123.1238, 42.1216],
"河北省": [114.4995, 38.1006],
"天津市": [117.4219, 39.4189],
"山西省": [112.3352, 37.9413],
"陕西省": [109.1162, 34.2004],
"甘肃省": [103.5901, 36.3043],
"宁夏回族自治区": [106.3586, 38.1775],
"青海省": [101.4038, 36.8207],
"新疆维吾尔自治区": [87.9236, 43.5883],
"四川省": [103.9526, 30.7617],
"重庆市": [108.384366, 30.439702],
"山东省": [117.1582, 36.8701],
"河南省": [113.4668, 34.6234],
"安徽省": [117.29, 32.0581],
"湖北省": [114.3896, 30.6628],
"浙江省": [119.5313, 29.8773],
"福建省": [119.4543, 25.9222],
"江西省": [116.0046, 28.6633],
"湖南省": [113.0823, 28.2568],
"贵州省": [106.6992, 26.7682],
"云南省": [102.9199, 25.4663],
"广东省": [113.12244, 23.009505],
"广西壮族自治区": [108.479, 23.1152],
"海南省": [110.3893, 19.8516],
'上海市': [121.4648, 31.2891]
//"西藏": [91.11, 29.97]
};
var colors =
["#1DE9B6", "#EEDD78"];
var colorIndex = 0;
</script>