使用echarts渲染乡镇街道地图

使用echarts生成乡镇级地图显示(因大多地图数据获取网站只显示区县级数据)

1.获取各个街(乡镇)地图json数据

1.1 下载街道json数据这里使用bigemap软件

bigemap下载地址 下载全能版

安装打开后,点击地图高清,选择任意地区,后面在行政区域选择具体目标区域
请添加图片描述

选择地方高清后进行所需的区域进行数据的下载

请添加图片描述请添加图片描述

选择合适的级别下载完成后找到对应文件夹中kml文件

请添加图片描述

1.2 重复下载步骤下载玩所有街道数据,使用合并网站geojson.io进行数据合并

将下载的kml数据导入,全部导入后,save使用geojson格式导出,导出后 的geojson使用时无效,格式检测显示违反多边形右手原则,这里猜测与导入顺序有关。
请添加图片描述

使用geojson编辑工具导入直接导出即可,该网站不稳定偶尔进不去。导出之后json数据就可以用了

请添加图片描述

在这里插入图片描述

自此echarts所需地图数据处理完毕

2. 使用echarts在地图中进行渲染

2.1引入echarts.js 和jquery(用于获取我们的geojson数据)
	<script src="<c:url value="自己定义echarts路径,也可以通过其他方式引入"/>"></script>
	<script src="<c:url value="自己定义jquery路径,也可以通过其他方式引入"/>"></script>
2.2定义一个有高度的div块,指定id,用于echarts渲染地图使用
  <div id="townsMap" style="width: 100%; height: 800px;></div>
2.3初始化echarts实例
<script>
// 基于准备好的dom,初始化echarts实例
         var myChart = echarts.init(document.getElementById('townsMap'));
</script>
2.4因为echarts库里没有街道地图数据,我们导入json数据,需要注册一下

这里将我们上面的处理得到的街道地图json数据存放在项目里,使用jquery获取并使用

<script>
$.getJSON('项目中地图数据存放完整路径及文件名', function (data) {
    // 指定图表的配置项和数据

    // 注册街道地图数据
    echarts.registerMap('town', data);}</script>
<script>
var option = {
        geo: {
            map: 'town',//表示使用的是我们注册的地图
            roam: true,//可以拖拽
        },
        // 其他配置项...
    };
</script>
<script>
// 使用刚指定的配置项和数据显示地图。
myChart.setOption(option);
</script>

到这里基本流程及结束了,暂时是在已有的代码上修改获取的经验,如有错误不足请多多指点。主要解决json数据的获取问题,echarts使用这里不够清晰可以参考其他文章或者参考官方文档。
function getGzMap(_data) { if (_chinaMap == undefined) { var dom = document.getElementById("container"); _chinaMap = echarts.init(dom); _chinaMap.on('click', function(params) { console.log(params); var _type = params.seriesType; if (_type == "map") { //window.parent.aaa('aa') //调用父页面方法 } else if (_type == "effectScatter") { window.parent.showMap(); } }) } var option = { backgroundColor: 'rgba(0,0,0,0)', visualMap: { type: 'piecewise', show: false, min: 0, max: 300, splitNumber: 3, itemWidth: 10, itemHeight: 10, itemGap: 5, seriesIndex: [1], pieces: [ { min: 0, max: 100, label: '优' }, { min: 101, max: 200, label: '良' }, { min: 201, max: 300, label: '高风险' } ], //color: ['#FA4D08', '#4BD94F', '#FBD32B'], //红、绿、黄 color: ['#F8DAE6', '#FEF9B5', '#B0D8B3'], //红、黄、绿 textStyle: { color: '#9EA8B1', fontSize: 10 } }, tooltip: { formatter: '{b}' }, geo: { map: 'guangdong', roam: true, aspectScale: 1, zoom: 1.5, layoutCenter: ['55%', '40%'], layoutSize: 500, label: { normal: { show: true }, emphasis: { show: true } }, itemStyle: { normal: { areaColor: '#323c48', borderColor: '#111', borderColor: '#3BB4DF', shadowColor: '#25A3FC', shadowBlur: 10 }, emphasis: { areaColor: '#ddb926' } } }, series: [{ type: 'effectScatter', coordinateSystem: 'geo', data: unitData, symbolSize: 10, symbol: 'image://../../../../Content/images/One/fire.png', //symbolRotate: 35, rippleEffect: { period: 4, scale: 5, brushType: 'fill', }, label: { normal: { formatter: '{b}', position: 'right', show: false }, emphasis: { show: false } }, itemStyle: { normal: { color: '#fff' } } }, { name: '', type: 'map', geoIndex: 0, mapType: 'guangdong', // 自定义扩展图表类型 label: { normal: { show: true, } }, itemStyle: { normal: { label: { show: true, fontSize: 10, color: '#111' }, shadowColor: '#ddb926', shadowBlur: 5, }, emphasis: { label: { show: true }, shadowColor: 'rgba(0, 0, 0, 0.5)', shadowBlur: 10 } }, data: _data }, { type: 'effectScatter', coordinateSystem: 'geo', data: windData, symbolSize: 10, symbol: 'image://../../../../Content/images/One/wind.png', //symbolRotate: 35, rippleEffect: { period: 4, scale: 5, brushType: 'fill', }, label: { normal: { formatter: '{b}', position: 'right', show: false }, emphasis: { show: false } }, itemStyle: { normal: { color: '#fff' } } }, ] }; $.getJSON('../../MapCN/guangdong.json', function(chinaJson) { echarts.registerMap('guangdong', chinaJson); _chinaMap.setOption(option, true); }); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值