geo_info_platform/demo.html

1474 lines
51 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>map</title>
<link href="./css/demo.css" rel="stylesheet">
<link href="./css/slider.css" rel="stylesheet">
<link href="./font/iconfont.css" rel="stylesheet">
<!-- 引入 echarts.js -->
<!-- 这里是加载刚下好的echarts.min.js注意路径 -->
<!-- <link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> -->
<script src="echarts.min.js"></script>
<!-- 引入 china.js -->
<script src="china.js"></script>
</head>
<body>
<div class="div-a">
<!-- 放大或缩小左侧图层-->
<div class="screen-btn screen-open" id="btn">
<span class="screen_icon iconfont icon-kuoda"></span>
</div>
<div class="div-b" id="mainGraph">知识图谱</div>
<!-- 视频与图片 -->
<div class="div-c">
<div class="div-video">
<video width="100%" height="100%" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
</div>
<div class="slider slider_one_big_picture">
<div>
<img src="./image/1.jpg" />
</div>
<div>
<img src="./image/2.jpg" />
</div>
<div>
<img src="./image/3.jpg" />
</div>
<div>
<img src="./image/4.jpg" />
</div>
<div>
<img src="./image/5.jpg" />
</div>
<div>
<img src="./image/6.jpg" />
</div>
<div>
<img src="./image/7.jpg" />
</div>
<div>
<img src="./image/8.jpg" />
</div>
<div>
<img src="./image/9.jpg" />
</div>
<div class="next_button"></div>
<div class="prev_button"></div>
<div class="nav_indicators"></div>
</div>
</div>
</div>
<!-- 搜索,径纬度 区域 -->
<div class="search-area">
<div class="show_detail">
<span class="iconfont icon-gengduo more_icon"></span>
<ul class="detail_info">
<li class="info_txt" data-key="prov">地点</li>
<li class="info_txt" data-key="lon">经纬度</li>
</ul>
</div>
<div class="search-prov">
<input class="search_input" placeholder="请输入地点" />
<span class="search_icon iconfont icon-search"></span>
</div>
<div class="lat_lon_sec">
<input
onkeyup="this.value=this.value.replace(/[^\d.]/g, '')"
class="search_input_common lon" placeholder="经度" />
<input
onkeyup="this.value=this.value.replace(/[^\d.]/g, '')"
class="search_input_common lat" placeholder="纬度" />
<span class="iconfont icon-search lat_lon_search"></span>
</div>
</div>
<!-- 为ECharts准备一个具备大小宽高的Dom -->
<div id="main" style="width: 100%;height:100vh;"></div>
<script type="text/javascript" src="./js/jQuery-1.8.3.min.js"></script>
<script type="text/javascript" src="./js/jquery.easy_slides.js"></script>
<script type="text/javascript">
// 基于准备好的dom初始化echarts实例地图
var myChart = echarts.init(document.getElementById('main'));
// 知识图谱
var myChartGraph = echarts.init(document.getElementById('mainGraph'));
function tooltipCharts() {
console.log(arguments[0]);
var myChart1 = echarts.init(document.getElementById('tooltipBarId'));
var option = {
tooltip: {},
dataset: {
source: [
['xAxis', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13'],
['amount', 41.1, 30.4, 65.1, 53.3, 53.8, 98.7, 65.1, 53.3, 41.1, 30.4, 53.3, 41.1, 53.3, 53.8]
]
},
xAxis: {
type: 'category',
interval: true,
axisLabel: {
rotate: 45
},
axisTick: {
show: false
}
},
yAxis: {},
color: ['#4FA8F9', '#F5A623'],
grid: {
show: true,
backgroundColor: '#1D346F',
left: 30,
right: 10,
top: 10,
bottom: 20,
},
series: [{
type: 'bar',
smooth: true,
seriesLayoutBy: 'row',
barWidth: 10
}]
};
myChart1.setOption(option);
}
// 各省份经纬度
var chinaGeoCoordMap = {
'黑龙江': [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],
"西藏": [91.11, 29.97],
"四川": [103.9526, 30.7617],
"重庆": [108.384366, 30.439702],
"山东": [117.1582, 36.8701],
"河南": [113.4668, 34.6234],
"江苏": [118.8062, 31.9208],
"安徽": [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.48, 31.22],
"香港": [114.15, 22.15],
"澳门": [113.5, 22.2],
'台湾': [121.31, 25.03]
};
// 各省份对应的浮框数据信息,不包括浮框中的柱状图
var chinaDatas = [
[{
name: '黑龙江',
value: 0,
ave:"黑",
provincialcapital:"哈尔滨",
diqu:"中国东北地区",
qihou:"温带大陆性季风气候、寒温带气候",
people:"3773.1万人" ,
num:"47.3万平方公里" ,
GDP:"16361.6亿元",
renjunGDP:"43274元"
}],
[{
name: '内蒙古',
value: 0,
ave:"内蒙古",
provincialcapital:"呼和浩特",
diqu:"中国北部边疆",
qihou:"温带大陆性气候、温带季风气候",
people:"2534万人" ,
num:"118.3万平方公里" ,
GDP:"17289.2亿元",
renjunGDP:"68302元"
}],
[{
name: '吉林',
value: 0,
ave:"吉",
provincialcapital:"长春",
diqu:"中国东北地区",
qihou:"温带季风气候",
people:"2704.06万人" ,
num:"18.74万平方公里" ,
GDP:"15074.62亿元",
renjunGDP:"55611元"
}],
[{
name: '北京',
value: 0,
ave:"京",
provincialcapital:"直辖市",
diqu:"中国华北地区",
qihou:"温带季风性气候",
people:"2154.2万人" ,
num:"1.64万平方公里" ,
GDP:"30320亿元",
renjunGDP:"140000元"
}],
[{
name: '辽宁',
value: 0,
ave:"辽",
provincialcapital:"沈阳",
diqu:"中国东北地区",
qihou:"温带季风气候",
people:"4359.3万人" ,
num:"14.86万平方公里" ,
GDP:"25315.4亿元",
renjunGDP:"58008元"
}],
[{
name: '河北',
value: 0,
ave:"冀",
provincialcapital:"石家庄",
diqu:"中国华北地区",
qihou:"温带大陆性季风气候",
people:"7556.30万人" ,
num:"18.88万平方公里" ,
GDP:"36010.3亿元",
renjunGDP:"47772元"
}],
[{
name: '天津',
value: 0,
ave:"黑",
provincialcapital:"哈尔滨",
diqu:"中国华北地区",
qihou:"温带大陆性季风气候",
people:"3773.1万人" ,
num:"47.3万平方公里" ,
GDP:"16361.6亿元",
renjunGDP:"120000元"
}],
[{
name: '山西',
value: 0,
ave:"晋",
provincialcapital:"太原",
diqu:"中国华北地区",
qihou:"温带大陆性季风气候",
people:"3718.34万人" ,
num:"15.67万平方公里" ,
GDP:"16818.1亿元",
renjunGDP:"45328元"
}],
[{
name: '陕西',
value: 0,
ave:"“陕”或“秦”",
provincialcapital:"西安",
diqu:"中国西北地区",
qihou:"温带季风气候、亚热带季风气候",
people:"3864.40万" ,
num:"20.56万平方公里" ,
GDP:"24438.32亿元",
renjunGDP:"63477元"
}],
[{
name: '甘肃',
value: 0,
ave:"“甘”或“陇”",
provincialcapital:"兰州",
diqu:"中国西北地区",
qihou:"温带大陆性气候、高原山地气候",
people:"2637.26万人" ,
num:"42.58万平方公里" ,
GDP:"8246.1亿元",
renjunGDP:"31336元"
}],
[{
name: '宁夏',
value: 0,
ave:"宁",
provincialcapital:"银川",
diqu:"中国西北地区",
qihou:"温带大陆性气候",
people:"688.11万人" ,
num:"6.64万平方公里" ,
GDP:"3705.18亿元",
renjunGDP:"54094元"
}],
[{
name: '青海',
value: 0,
ave:"青",
provincialcapital:"西宁",
diqu:"中国西北地区",
qihou:"高原大陆性气候",
people:"603.23万人" ,
num:"72万平方公里" ,
GDP:"2865.23亿元",
renjunGDP:"47689元"
}],
[{
name: '新疆',
value: 0,
ave:"新",
provincialcapital:"乌鲁木齐",
diqu:"中国西北地区",
qihou:"温带大陆性气候",
people:"2486.76万人" ,
num:"166万平方公里" ,
GDP:"12199.08亿元",
renjunGDP:"49474元"
}],
[{
name: '西藏',
value: 0,
ave:"藏",
provincialcapital:"拉萨",
diqu:"中国西南地区",
qihou:"西北严寒、东南温暖湿润",
people:"343.82万人" ,
num:"122.84万平方公里" ,
GDP:"1477.63亿元",
renjunGDP:"43397元"
}],
[{
name: '四川',
value: 0,
ave:"“川”或“蜀”",
provincialcapital:"成都",
diqu:"中国西南地区",
qihou:"亚热带季风气候、高原山地气候",
people:"8341万人" ,
num:"47.3万平方公里" ,
GDP:"40678.13亿元",
renjunGDP:"48883元"
}],
[{
name: '重庆',
value: 0,
ave:"渝",
provincialcapital:"直辖市",
diqu:"中国西南地区",
qihou:"亚热带季风性湿润气候",
people:"3101.79万人" ,
num:"48.6万平方公里" ,
GDP:"20363.19亿元",
renjunGDP:"65933元"
}],
[{
name: '山东',
value: 0,
ave:"鲁",
provincialcapital:"济南",
diqu:"中国华北地区",
qihou:"温带季风气候",
people:"10047.24万人" ,
num:"15.79万平方公里" ,
GDP:"76469.7亿元",
renjunGDP:"76267元"
}],
[{
name: '河南',
value: 0,
ave:"豫",
provincialcapital:"郑州",
diqu:"中国华中地区",
qihou:"温带季风气候,亚热带季风气候",
people:"9605万人" ,
num:"16.7万平方公里" ,
GDP:"48055.86亿元",
renjunGDP:"50152元"
}],
[{
name: '江苏',
value: 0,
ave:"黑",
provincialcapital:"南京",
diqu:"中国华东地区",
qihou:"亚热带季风气候,温带季风气候",
people:"8050.7万人" ,
num:"10.72万平方公里" ,
GDP:"92595.4亿元",
renjunGDP:"115000元"
}],
[{
name: '安徽',
value: 0,
ave:"皖",
provincialcapital:"合肥",
diqu:"中国华北地区",
qihou:"温带季风气候、亚热带季风气候",
people:"6323.6万人" ,
num:"14.01万平方公里" ,
GDP:"30006.8亿元",
renjunGDP:"47712元"
}],
[{
name: '湖北',
value: 0,
ave:"鄂",
provincialcapital:"武汉",
diqu:"中国中部地区",
qihou:"亚热带季风气候、高原山地气候",
people:"5917万人" ,
num:"18.59万平方公里" ,
GDP:"39366.55亿元",
renjunGDP:"66615元"
}],
[{
name: '浙江',
value: 0,
ave:"浙",
provincialcapital:"杭州",
diqu:"中国华东地区",
qihou:"亚热带季风气候",
people:"5737万人" ,
num:"10.55万平方公里" ,
GDP:"56197亿元",
renjunGDP:"98643元"
}],
[{
name: '福建',
value: 0,
ave:"闽",
provincialcapital:"福州",
diqu:"中国华东地区",
qihou:"亚热带季风气候",
people:"3941万人" ,
num:"12.4万平方公里" ,
GDP:"35804.04亿元",
renjunGDP:"91197元"
}],
[{
name: '江西',
value: 0,
ave:"赣",
provincialcapital:"南昌",
diqu:"中国华东地区",
qihou:"亚热带季风性湿润气候",
people:"4647.6万人" ,
num:"16.69万平方公里" ,
GDP:"21984.8亿元",
renjunGDP:"47433元"
}],
[{
name: '湖南',
value: 0,
ave:"湘",
provincialcapital:"长沙",
diqu:"中南地区",
qihou:"亚热带季风气候",
people:"6898.8万人" ,
num:"21.18万平方公里" ,
GDP:"36425.8亿元",
renjunGDP:"53097元"
}],
[{
name: '贵州',
value: 0,
ave:"贵",
provincialcapital:"贵阳",
diqu:"西南地区",
qihou:"亚热带季风气候",
people:"3600.0万人" ,
num:"17.6167万平方公里" ,
GDP:"14806.4亿元",
renjunGDP:"41400元"
}],
[{
name: '云南',
value: 0,
ave:"云",
provincialcapital:"昆明",
diqu:"西南地区",
qihou:"亚热带季风气候、热带季风气候、高原山地气候",
people:"4829.5万人" ,
num:"47.3万平方公里" ,
GDP:"14869.9亿元",
renjunGDP:"31358元"
}],
[{
name: '广东',
value: 0,
ave:"粤",
provincialcapital:"广州",
diqu:"华南地区",
qihou:"亚热带季风气候",
people:"11346.0万人" ,
num:"17.97万平方公里" ,
GDP:"89879.2亿元",
renjunGDP:"81089元"
}],
[{
name: '广西',
value: 0,
ave:"桂",
provincialcapital:"南宁",
diqu:"华南地区",
qihou:"亚热带季风气候",
people:"4926万人" ,
num:"23.76万平方公里" ,
GDP:"20396.2亿元",
renjunGDP:"41752元"
}],
[{
name: '海南',
value: 0,
ave:"琼",
provincialcapital:"海口",
diqu:"华南地区",
qihou:"热带海洋性季风气候",
people:"934.32万人" ,
num:"3.54万平方公里" ,
GDP:"4832.05亿元",
renjunGDP:"52195.5元"
}],
[{
name: '上海',
value: 0,
ave:"沪",
provincialcapital:"上海",
diqu:"华东地区",
qihou:"亚热带季风气候",
people:"2423.78万人" ,
num:"6340.5平方公里" ,
GDP:"32679.87亿元",
renjunGDP:"135000元"
}],
[{
name: '香港',
value: 0,
ave:"港",
provincialcapital:"香港",
diqu:"华南地区",
qihou:"亚热带季风气候",
people:"748.25万人" ,
num:"1106.34平方公里" ,
GDP:"24042.15亿元",
renjunGDP:"343595.02元"
}],
[{
name: '澳门',
value: 0,
ave:"澳",
provincialcapital:"澳门",
diqu:"华南地区",
qihou:"亚热带季风气候",
people:"67.2万" ,
num:"32.8平方公里" ,
GDP:"4448.88亿元",
renjunGDP:"676564.63元"
}],
[{
name: '台湾',
value: 0,
ave:"台",
provincialcapital:"台湾",
diqu:"华东地区",
qihou:"北回归线以北属亚热带季风气候,以南属热带季风气候",
people:"2358万人" ,
num:"36192.8155平方公里" ,
GDP:"3.9万亿元人民币",
renjunGDP:"165400元"
}]
]
// 设置 series 内容
let redName = '上海';
var series = [];
[ ['北京', chinaDatas] ].forEach(function(item, i) {
series.push(
{
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 2,
rippleEffect: { //涟漪特效
period: 4, //动画时间,值越小速度越快
brushType: 'fill', //波纹绘制方式 stroke, fill
scale: .5 //波纹圆环最大限制,值越大波纹越大
},
label: {
normal: {
show: true,
position: 'right', //显示位置
offset: [5, 0], //偏移设置
formatter: function(params) { //圆环显示文字
return params.data.name;
},
fontSize: 14
},
},
symbol: 'circle',
symbolSize: function(val) {
return 10; //圆环大小
},
itemStyle: {
normal: {
show: false,
// color: '#f00'
color: function(params) { //圆环显示文字
if (params.data.dataItem[0].name == redName) {
return '#2bd291'
} else {
return '#70c4eb'
}
},
}
},
// 在这里修改悬浮框,加了一个show:true
tooltip: {
show:true,
trigger: 'item',
backgroundColor: 'rgba(8, 18, 42, 0.85)',
borderColor: '#040616',
showDelay: 0,
hideDelay: 0,
enterable: true,
transitionDuration: 0,
extraCssText: 'z-index:100',
formatter: function(params, ticket, callback) {
// 根据业务自己拓展要显示的内容
//console.log('params--2',params)
let res = "";
let name = params.data.dataItem[0].name;
let ave = params.data.dataItem[0].ave;
let provincialcapital= params.data.dataItem[0].provincialcapital;
let diqu = params.data.dataItem[0].diqu;
let qihou = params.data.dataItem[0].qihou;
let people = params.data.dataItem[0].people;
let num = params.data.dataItem[0].num;
let GDP = params.data.dataItem[0].GDP;
let renjunGDP = params.data.dataItem[0].renjunGDP;
res = "<div style='color:#fff;padding:10px;'><span>名称:" + name + "</span><br/><span>中文名:" + ave + "</span><br/><span>外文名:" + provincialcapital + "</span><br/><span>所属地区:" + diqu + "</span><br/><span>气候:" + qihou + "</span><br/><span>面积:" + people + "</span><br/><span>语言:" + num + "</span><br/><span>海拔:" + GDP + "</span><br/><span>著名景点:" + renjunGDP +
' </div>' +
' </div>' +
'<div id="tooltipBarId" style="height:100px;width:100%;border-radius:0 0 5px 0;background:#D79D3D"></div>'+ "</span><br/><span>演示表格可以任意定制输入及其他参数";
setTimeout(function() {
tooltipCharts(params.name);
}, 10);
return res;
}
},
data: item[1].map(function(dataItem) {
return {
dataItem: dataItem,
name: dataItem[0].name,
value: chinaGeoCoordMap[dataItem[0].name].concat([dataItem[0].value])
};
}),
},
{
type: 'map',
geoIndex: 0
}
);
});
// 关键!!!!在这里修改悬浮框,把 show:true 改为 show:false
option = {
tooltip: {
show:false,
trigger: 'item',
position: 'top',
backgroundColor: 'rgba(166, 200, 76, 0.82)',
borderColor: '#040616',
showDelay: 0,
hideDelay: 0,
enterable: true,
transitionDuration: 0,
extraCssText: 'z-index:100'
},
backgroundColor: "#1D346F",
geo: {
show: true,
map: 'china',
label: {
normal: {
show: false
},
emphasis: {
show: false,
}
},
// roam: false,//地图设置不可拖拽,固定的
itemStyle: {
normal: {
areaColor: '#1D346F',
borderWidth: 0,
shadowColor: '#D79D3D',
shadowBlur: 30,
shadowOffsetX: -5,
shadowOffsetY: 10
}
}
},
series: series
};
// 中国地图上各区域随鼠标移动,亮或不亮
myChart.on('mouseover', function(params) {
var city = params.name;
if (city == '广东' || city == '广西' || city == '海南'|| city == '云南' || city == '湖南' || city == '贵州') {
myChart.dispatchAction({
type: 'highlight',
name: "广东"
});
myChart.dispatchAction({
type: 'highlight',
name: "广西"
});
myChart.dispatchAction({
type: 'highlight',
name: "海南"
});
myChart.dispatchAction({
type: 'highlight',
name: "云南"
});
myChart.dispatchAction({
type: 'highlight',
name: "湖南"
});
myChart.dispatchAction({
type: 'highlight',
name: "贵州"
});
}
if (city == '江西' || city == '江苏' || city == '浙江' || city == '安徽' || city == '福建' || city == '上海') {
myChart.dispatchAction({
type: 'highlight',
name: "江西"
});
myChart.dispatchAction({
type: 'highlight',
name: "江苏"
});
myChart.dispatchAction({
type: 'highlight',
name: "浙江"
});
myChart.dispatchAction({
type: 'highlight',
name: "安徽"
});
myChart.dispatchAction({
type: 'highlight',
name: "福建"
});
myChart.dispatchAction({
type: 'highlight',
name: "上海"
});
}
if (city == '北京' || city == '天津' || city == '河北' || city == '河南' || city == '山西' || city == '陕西' || city == '湖北') {
myChart.dispatchAction({
type: 'highlight',
name: "北京"
});
myChart.dispatchAction({
type: 'highlight',
name: "天津"
});
myChart.dispatchAction({
type: 'highlight',
name: "河北"
});
myChart.dispatchAction({
type: 'highlight',
name: "河南"
});
myChart.dispatchAction({
type: 'highlight',
name: "山西"
});
myChart.dispatchAction({
type: 'highlight',
name: "陕西"
});
myChart.dispatchAction({
type: 'highlight',
name: "湖北"
});
}
if (city == '四川' || city == '甘肃' || city == '青海' || city == '宁夏' || city == '新疆' || city == '西藏' || city == '重庆') {
myChart.dispatchAction({
type: 'highlight',
name: "四川"
});
myChart.dispatchAction({
type: 'highlight',
name: "甘肃"
});
myChart.dispatchAction({
type: 'highlight',
name: "青海"
});
myChart.dispatchAction({
type: 'highlight',
name: "宁夏"
});
myChart.dispatchAction({
type: 'highlight',
name: "新疆"
});
myChart.dispatchAction({
type: 'highlight',
name: "西藏"
});
myChart.dispatchAction({
type: 'highlight',
name: "重庆"
});
}
if (city == '辽宁' || city == '山东' || city == '吉林' || city == '黑龙江' || city == '内蒙古') {
myChart.dispatchAction({
type: 'highlight',
name: "辽宁"
});
myChart.dispatchAction({
type: 'highlight',
name: "山东"
});
myChart.dispatchAction({
type: 'highlight',
name: "吉林"
});
myChart.dispatchAction({
type: 'highlight',
name: "黑龙江"
});
myChart.dispatchAction({
type: 'highlight',
name: "内蒙古"
});
}
if (city == '台湾' || city == '香港' || city == '澳门') {
myChart.dispatchAction({
type: 'highlight',
name: "台湾"
});
myChart.dispatchAction({
type: 'highlight',
name: "香港"
});
myChart.dispatchAction({
type: 'highlight',
name: "澳门"
});
}
});
myChart.on('mouseout', function(params) {
var city = params.name;
if (city == '广东' || city == '广西' || city == '海南'|| city == '云南' || city == '湖南' || city == '贵州') {
myChart.dispatchAction({
type: 'downplay',
name: "广东"
});
myChart.dispatchAction({
type: 'downplay',
name: "广西"
});
myChart.dispatchAction({
type: 'downplay',
name: "海南"
});
myChart.dispatchAction({
type: 'downplay',
name: "云南"
});
myChart.dispatchAction({
type: 'downplay',
name: "湖南"
});
myChart.dispatchAction({
type: 'downplay',
name: "贵州"
});
}
if (city == '江西' || city == '江苏' || city == '浙江' || city == '安徽' || city == '福建' || city == '上海') {
myChart.dispatchAction({
type: 'downplay',
name: "江西"
});
myChart.dispatchAction({
type: 'downplay',
name: "江苏"
});
myChart.dispatchAction({
type: 'downplay',
name: "浙江"
});
myChart.dispatchAction({
type: 'downplay',
name: "安徽"
});
myChart.dispatchAction({
type: 'downplay',
name: "福建"
});
myChart.dispatchAction({
type: 'downplay',
name: "上海"
});
}
if (city == '北京' || city == '天津' || city == '河北' || city == '河南' || city == '山西' || city == '陕西' || city == '湖北') {
myChart.dispatchAction({
type: 'downplay',
name: "北京"
});
myChart.dispatchAction({
type: 'downplay',
name: "天津"
});
myChart.dispatchAction({
type: 'downplay',
name: "河北"
});
myChart.dispatchAction({
type: 'downplay',
name: "河南"
});
myChart.dispatchAction({
type: 'downplay',
name: "山西"
});
myChart.dispatchAction({
type: 'downplay',
name: "陕西"
});
myChart.dispatchAction({
type: 'downplay',
name: "湖北"
});
}
if (city == '四川' || city == '甘肃' || city == '青海' || city == '宁夏' || city == '新疆' || city == '西藏' || city == '重庆') {
myChart.dispatchAction({
type: 'downplay',
name: "四川"
});
myChart.dispatchAction({
type: 'downplay',
name: "甘肃"
});
myChart.dispatchAction({
type: 'downplay',
name: "青海"
});
myChart.dispatchAction({
type: 'downplay',
name: "宁夏"
});
myChart.dispatchAction({
type: 'downplay',
name: "新疆"
});
myChart.dispatchAction({
type: 'downplay',
name: "西藏"
});
myChart.dispatchAction({
type: 'downplay',
name: "重庆"
});
}
if (city == '辽宁' || city == '山东' || city == '吉林' || city == '黑龙江' || city == '内蒙古') {
myChart.dispatchAction({
type: 'downplay',
name: "辽宁"
});
myChart.dispatchAction({
type: 'downplay',
name: "山东"
});
myChart.dispatchAction({
type: 'downplay',
name: "吉林"
});
myChart.dispatchAction({
type: 'downplay',
name: "黑龙江"
});
myChart.dispatchAction({
type: 'downplay',
name: "内蒙古"
});
}
if (city == '台湾' || city == '香港' || city == '澳门') {
myChart.dispatchAction({
type: 'downplay',
name: "台湾"
});
myChart.dispatchAction({
type: 'downplay',
name: "香港"
});
myChart.dispatchAction({
type: 'downplay',
name: "澳门"
});
}
});
graphList = {"keyword":{
"nodes":[],
"links":[]
}}
currentGraph = {
nodes: {},
links: {},
};
nodeMap = {};
category = 1
level = "level"
symbolSize = 40
myChart.on('click', function(params) {
var city = params.name;
graphList = {"keyword":{
"nodes":[],
"links":[]
}}
currentGraph = {
nodes: {},
links: {},
}
nodeMap = {};
category = 1
symbolSize = 40
init(city)
});
myChart.setOption(option);
function fillInfo(result, name) {
// graphList = {"keyword":{
// "nodes":[],
// "links":[]
// }}
if (graphList.keyword.nodes.length == 0) {
formNode = {"name":name, "category":category, "symbolSize":symbolSize}
graphList.keyword.nodes[0]=formNode
category += 1
symbolSize -= 5
}
else if (graphList.keyword.nodes[0].name == name) {
return 0
}
else {
// console.log(name)
category = nodeMap[name].category + 1
symbolSize = nodeMap[name].symbolSize - 5
}
nodeLen = graphList.keyword.nodes.length
linkLen = graphList.keyword.links.length
source = name
for (i = 0; i < result.data.avp.length; i++) {
if (source == result.data.avp[i][1]) {
nodeLen--
linkLen--
continue
}
formNode = {"name":result.data.avp[i][1], "category":category, "symbolSize":symbolSize}
graphList.keyword.nodes[nodeLen+i]=formNode
formLink = {"source":source, "target":result.data.avp[i][1]}
graphList.keyword.links[linkLen+i]=formLink
}
}
// 页面加载时,第一次初始化图,以及点击省份后更换数据
function sync_request(url){
//实例化XmlHttpRequest对象
var xhr=new XMLHttpRequest();
//使用GET方式请求指定网址的页面
xhr.open("GET",url,false);
//发送空内容请求
xhr.send(null);
if(xhr.status===200){//200状态码表示正常
result = xhr.responseText
// console.log(JSON.parse(result))
return JSON.parse(result)
}else{
alert("Error occurred:"+xhr.statusText);
}
}
function init(name) {
result = sync_request('https://api.ownthink.com/kg/knowledge?entity='+name)
if (!result.data) {
alert("nothing")
return 0
}
fillInfo(result, name)
nodeMap = {};
graph = graphList.keyword
for (let i = 0; i < graph.nodes.length; i++) {
if (graph.nodes[i].category === 1) {
currentGraph.nodes[graph.nodes[i].name] = graph.nodes[i];
}
nodeMap[graph.nodes[i].name] = graph.nodes[i];
nodeMap[graph.nodes[i].name]['links'] = {};
nodeMap[graph.nodes[i].name]['nodes'] = {};
nodeMap[graph.nodes[i].name]['hasAppend'] = false;
}
for (let i = 0; i < graph.links.length; i++) {
let link = graph.links[i];
if (nodeMap[link.source] !== undefined && nodeMap[link.target] !== undefined) {
nodeMap[link.source].links[link.target] = link;
nodeMap[link.source].nodes[nodeMap[link.target].name] = nodeMap[link.target];
}
}
for (let i = 0; i < graph.nodes.length; i++) {
graph.nodes[i].itemStyle = null;
graph.nodes[i].label = {
normal: {
show: graph.nodes[i].symbolSize > 15
}
};
}
redrawGraph();
}
function loadData(name) {
result = sync_request('https://api.ownthink.com/kg/knowledge?entity='+name)
if (JSON.stringify(result.data) == '{}'){
alert("nothing")
return 0
}
fillInfo(result, name)
nodeMap = {};
graph = graphList.keyword
for (let i = 0; i < graph.nodes.length; i++) {
nodeMap[graph.nodes[i].name] = graph.nodes[i];
nodeMap[graph.nodes[i].name]['links'] = {};
nodeMap[graph.nodes[i].name]['nodes'] = {};
nodeMap[graph.nodes[i].name]['hasAppend'] = false;
}
for (let i = 0; i < graph.links.length; i++) {
let link = graph.links[i];
if (nodeMap[link.source] !== undefined && nodeMap[link.target] !== undefined) {
nodeMap[link.source].links[link.target] = link;
nodeMap[link.source].nodes[nodeMap[link.target].name] = nodeMap[link.target];
}
}
for (let i = 0; i < graph.nodes.length; i++) {
graph.nodes[i].itemStyle = null;
graph.nodes[i].label = {
normal: {
show: graph.nodes[i].symbolSize > 15
}
};
}
append(name)
}
// 处理点击节点展开
function append(nodeName) {
// 根据nodeName从nodeMap里拿出对应的nodes和links并append到currentGraph.nodes currentGraph.links
let node = nodeMap[nodeName];
if (node.hasAppend === true || Object.keys(node.nodes).length === 0 || Object.keys(node.links).length === 0) {
alert("无法继续展开");
return
}
Object.values(node.nodes).forEach(n => {
currentGraph.nodes[n.name] = n;
});
Object.values(node.links).forEach(l => {
currentGraph.links[l.source + "_" + l.target] = l;
});
node.hasAppend = true;
redrawGraph();
}
// 处理点击节点收缩
function remove(nodeName) {
//根据nodeName从nodeMap里拿出对应的nodes和links从currentGraph.nodes currentGraph.links删除当前节点的nodes和links并且递归
let node = nodeMap[nodeName];
Object.values(node.nodes).forEach(n => {
delete currentGraph.nodes[n.name];
if (n.hasAppend === true && Object.keys(n.nodes).length > 0) {
remove(n.name);
}
});
Object.values(node.links).forEach(l => {
delete currentGraph.links[l.source + '_' + l.target];
});
// 设置flag 等于false
node.hasAppend = false;
redrawGraph();
}
// 根据更新后的option重新画图
function redrawGraph() {
optionGraph.series[0].data = Object.values(currentGraph.nodes);
optionGraph.series[0].links = Object.values(currentGraph.links);
myChartGraph.setOption(optionGraph);
}
const optionGraph = {
title: {
title:'知识图谱',
top: 'top',
left: 'center',
},
tooltip: {},
legend: [],
animation: false,
series: [{
type: 'graph',
layout: 'force',
data: Object.values(currentGraph.nodes),
links: Object.values(currentGraph.links),
categories: [
{
name: 1,
itemStyle: {
color: '#c23531'
},
},
{
name: 2,
itemStyle: {
color: '#2f4554'
},
},
{
name: 3,
itemStyle: {
color: '#61a0a8'
},
},
{
name: 4,
itemStyle: {
color: '#999ea4'
},
},
{
name: 5,
itemStyle: {
color: '#555555'
},
}
],
roam: true,
focusNodeAdjacency: false,
itemStyle: {
normal: {
borderColor: '#fff',
borderWidth: 1,
shadowBlur: 10,
shadowColor: 'rgba(0, 0, 0, 0.3)'
}
},
label: {
position: 'right',
formatter: '{b}'
},
lineStyle: {
color: 'target',
opacity: 0.6,
curveness: 0.3
},
emphasis: {
lineStyle: {
width: 10
}
},
force: {
layoutAnimation: false,
repulsion: 500
}
}]
};
myChartGraph.on('click', function(params) {
if (params.dataType === "node") {
const node = nodeMap[params.data.name];
if (node.hasAppend === true) {
remove(node.name)
} else {
loadData(node.name);
}
}
});
</script>
<script>
window.onload = function () {
var oBtn = document.querySelector('#btn');
oBtn.addEventListener('click', function () {
var oText = this.innerHTML;
var oParent = this.parentNode;
if (oParent.classList.contains('active')) {
oParent.classList.remove('active');
$('.screen_icon').addClass('icon-kuoda').removeClass('icon-suoxiao');
$('.search-area').show();
} else {
oParent.classList.add('active');
$('.screen_icon').addClass('icon-suoxiao').removeClass('icon-kuoda');
$('.search-area').hide();
}
}, false);
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$('.slider_one_big_picture').EasySlides({
'autoplay': true,
'stepbystep': false,
'show': 5,
'loop': true
});
// 左侧全屏
$('.search-prov').on('mouseover', function () {
$('.search_input').addClass('active');
}).on('mouseout', function () {
$('.search_input').removeClass('active');
});
$('.more_icon').on('mouseover', function () {
$('.detail_info').show();
}).on('mouseout', function () {
var timer = setTimeout(function () {
$('.detail_info').on('mouseover', function () {
$('.detail_info').show();
}).on('mouseout', function () {
$('.detail_info').hide();
});
}, 500);
$('.detail_info').hide();
})
// 根据省份查找
function searchProvince (value) {
console.log('查找的省份:', value);
}
$('.search_icon').on('click', function () {
var $val = $(this).val();
searchProvince($val)
});
$('.search_input').on('keydown', function (e) {
if (e.keyCode === 13) {
// 调用查找接口
var $val = $(this).val();
searchProvince($val)
}
})
$('.detail_info').on('click', 'li', function () {
console.log($(this).attr('data-key'));
$('.detail_info').hide();
var key = $(this).attr('data-key');
if (key === 'prov') {
$('.search-prov').show();
$('.lat_lon_sec').hide();
} else {
$('.search-prov').hide();
$('.lat_lon_sec').show();
}
});
function latOrLonSearch () {
var lat = $('.lat').val(); // 纬度
var lon = $('.lon').val(); // 经度
if (!lat || !lon) {
if (!lat) $('.lat').focus();
if (!lon) $('.lon').focus();
return;
}
console.log('经度', lon);
console.log('纬度', lat);
};
$('.search_input_common').on('keydown', function (e) {
if (e.keyCode === 13) {
latOrLonSearch();
}
})
$('.lat_lon_search').on('click', function () {
latOrLonSearch();
})
});
</script>
</body>
</html>