效果图
准备个div放map
地图的展示
var uploadedDataURL = "https://geo.datav.aliyun.com/areas_v2/bound/361000_full.json" ;
var mapChart = echarts. init ( document. getElementById ( 'container1' ) ) ;
function showMap ( seriesCheckin, seriesDemandSq, seriesServiceProject ) {
var option;
mapChart. showLoading ( ) ;
$. getJSON ( uploadedDataURL,
function ( geoJson ) {
mapChart. hideLoading ( ) ;
echarts. registerMap ( '抚州市' , geoJson) ;
mapChart. setOption ( option = {
tooltip : {
trigger : 'item' ,
formatter : function ( params ) {
var res = params. name
+ '<br />' ;
areaName = params. name;
var myseries = option. series;
for ( var i = 0 ; i < myseries. length; i++ ) {
for ( var k = 0 ; k < myseries[ i] . data. length; k++ ) {
if ( myseries[ i] . data[ k] . name == params. name) {
res += myseries[ i] . name
+ ':'
+ myseries[ i] . data[ k] . value
+ '<br />' ;
}
}
}
return res;
} ,
} ,
series : [
{
name : '养老机构入住申请' ,
type : 'map' ,
mapType : '抚州市' ,
aspectScale : 0.9 ,
layoutCenter : [ '60%' ,
'50%' ] ,
layoutSize : '100%' ,
label : {
normal : {
show : true ,
textStyle : {
color : "#000000FF" ,
fontStyle : "normal" ,
fontWeight : "normal" ,
fontSize : 12 ,
}
}
} ,
itemStyle : {
normal : {
borderWidth : 1 ,
borderColor : '#0653C6E1' ,
areaColor : '#bdd4f4' ,
shadowColor : "#000" ,
shadowBlur : 1 ,
opacity : 1 ,
}
} ,
emphasis : {
label : {
show : true ,
textStyle : {
color : '#FFFFFFFF' ,
fontSize : 15 ,
}
} ,
itemStyle : {
areaColor : '#006cff' ,
}
} ,
data : seriesCheckin,
} ,
{
name : '社区居家养老服务' ,
type : 'map' ,
mapType : '抚州市' ,
data : seriesDemandSq,
} ,
{
name : '服务项目数量' ,
type : 'map' ,
mapType : '抚州市' ,
data : seriesServiceProject,
} ]
} ) ;
cycleShow ( mapChart, option) ;
} ) ;
} ;
轮播功能
var search_num = 0 ;
var lb_areaname = "" ;
function cycleShow ( mapChart, option ) {
var app = { } ;
app. currentIndex = - 1 ;
var timer;
setTimeout ( startTimer, 500 ) ;
function changeStyle ( ) {
var option = mapChart. getOption ( ) ;
var dataLen = option. series[ 0 ] . data. length;
mapChart. dispatchAction ( {
type : 'downplay' ,
seriesIndex : 0 ,
dataIndex : app. currentIndex
} ) ;
app. currentIndex = ( app. currentIndex + 1 ) % dataLen;
mapChart. dispatchAction ( {
type : 'highlight' ,
seriesIndex : 0 ,
dataIndex : app. currentIndex
} ) ;
lb_areaname = option. series[ 0 ] . data[ app. currentIndex] . name
mapChart. dispatchAction ( {
type : 'showTip' ,
seriesIndex : 0 ,
dataIndex : app. currentIndex
} ) ;
}
function startTimer ( ) {
stopTimer ( ) ;
timer = setInterval ( changeStyle, 2000 ) ;
}
function stopTimer ( ) {
clearInterval ( timer) ;
}
var mouse_flag = false ;
mapChart. on ( 'mouseover' , function ( params ) {
search_num = 0 ;
mouse_flag = true ;
if ( lb_areaname!= params. name) {
mapChart. dispatchAction ( {
type : 'downplay' ,
seriesIndex : 0 ,
dataIndex : app. currentIndex
} ) ;
}
stopTimer ( ) ;
mapChart. on ( 'click' , function ( params ) {
stopTimer ( ) ;
search_num += 1 ;
if ( search_num == 1 ) {
queryListLineChart ( ) ;
}
} )
} )
mapChart. on ( 'mouseout' , function ( params ) {
if ( params. name != "南城县" || params. name != "黎川县"
|| params. name != "南丰县" || params. name != "崇仁县"
|| params. name != "乐安县" || params. name != "宜黄县"
|| params. name != "金溪县" || params. name != "资溪县"
|| params. name != "东乡区" || params. name != "广昌县" ) {
mouse_flag = false ;
} else {
mouse_flag = true ;
}
} ) ;
container1. ondblclick = function ( ) {
if ( mouse_flag) {
stopTimer ( ) ;
queryListLineChart ( ) ;
} else {
areaName = "" ;
queryListLineChart ( ) ;
startTimer ( ) ;
}
}
option && mapChart. setOption ( option) ;
} ;