实现echarts的map显示,分为两步,第一步转换shp文件为geojson格式,第二步在echarts中显示
- 处理shp文件。
a) 利用arcMap打开shp文件,删除多余的polygon,剩下需要显示的区域。
b)修改shp文件的属性。geojson中需要的属性有:name、cp、childNum、polygon。我们可以利用arcMap提供的field Calculator实现shp属性的修改。修改后格式如图:
c)将处理好的shp转成geojson。 访问http://mapshaper.org/,可以将shp导出geojson。此时有一个问题,就是CP属性是字符串,需要将字符串转成数组 ,我是利用java程序转的
第二步利用echarts显示地图,直接上程序
$.getJSON("data/echart_standard_d.json",function(data){
echarts.registerMap('heilj', data);
//定义div#map,给定width和height
chart = echarts.init(document.getElementById('map'));
chart.setOption({
title: { text: 'title',},
toolbox:{
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature:{
saveAsImage: {
backgroundColor:'#fff',
excludeComponents: ['toolbox']
}
}
},
visualMap: {
type:'piecewise',
show:false, //图例
pieces: [
{value: 1,color:'#ff0000',label:'红色'},
{value: 2,color:'#FF8330',label:'橙色'}
],
right:0,
bottom:0,
align:'left',
padding:[30,10,10,10], //上、右、下、左
borderWidth:1 ,
borderColor:'#000',
itemGap:5,
itemSymbol:'rect',
itemWidth:30,
itemHeight:20,
inverse:true
},
series: [{
selectedMode:false,
silent:true,
type: 'map',
roam: true,
label:{
normal:{
show:true,
formatter:'{c}', //显示数值在地图上
textStyle:{
color:'#f00' ,
fontWeight:"bold"
}
}
},
data:[{name:"漠河县",value:3}] //这个需要程序处理
}]
});
})
通过上面就能显示效果,效果图如下: