echarts引入json地图(乡镇级)

BIGEMAP
Bigemap系列产品-GIS行业基础软件kml\shp
下载地图数据。 KML 格式 (不能直接导出KML格式,先导出bmv格式。用Bigemap 逐个打开bmv格式,选中对应的乡镇右键导出kml格式)

第二步(导入kml文件获取geoJson)
geojson.io
http://geojson.io/#map=2/20.0/0.0

导入第一步下载好的kml
在这里插入图片描述
导入所有的街道、镇数据的效果
在这里插入图片描述
右边红色圈的json数据就是我们需要放到echarts展示地图的geoJson数据新建 js 文件
复制右边的geoJson数据(ctrl a + ctrl + c),

注意:

var dongpingMap =  这是在geojson 数据中新增内容,其他不用修改  .此文件是dongpingMap.js
var dongpingMap = {
    "type": "FeatureCollection",
    "features": [
    {
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        116.3792225860848,
                        35.84428433445964
                    ],
                    [
                        116.37802058633571,
                        35.84351933200378
                    ],
                    [
                        116.37767758620403,
                        35.84296333094403
                    ],
                    [
                        116.37707658632951,
                        35.84331033197616,

代码: HTML     

<!DOCTYPE html>
<html lang="en">

<head>

    
    <meta charset="UTF-8">
    <!-- 适配移动端 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
  <style>
   #map  {
  width: 1000px;
  height: 1000px;
  margin: auto;
  }
  </style>
  <script src="js/jquery.min.js"></script>
  <script src="js/echarts.min.js"></script>
    <script src="js/dongpingMap.js"></script>
  <script src="js/map.js"></script>

</head>
<body>
<div id="map"></div>
</body>
</html>

map.js文件 内容:

$(function () {

    function dongpingChart () {

        var dongpingMapChart = echarts.init(document.getElementById('map'))

        // echarts.registerMap('dongping', dongpingMap, {})

        echarts.registerMap('dongping', dongpingMap, {})

        option = {

            geo: {

                // map: 'dongping',

                label: {

                    emphasis: {

                        show: false

                    }

                },

                roam: false,

                // zoom: 0.8,

            },

            series: [{

                type: 'map',

                mapType: 'dongping', //名称需要echarts.registerMap('dongping',dongpingMap,{})中的名称一致

                zoom: 1,

                itemStyle: {

                    normal: {

                        areaColor: 'rgba(2,37,101,.5)',

                        borderColor: 'rgba(112,187,252,.5)'

                    },

                    emphasis: {

                        areaColor: 'rgba(2,37,101,.8)',

                    }

                },

                label: {

                    show: true,

                    color: '#ffff'

                }, //显示文字

                roam: true,

                data: [],

            },],

        }

        dongpingMapChart.setOption(option, true)

        window.addEventListener('resize', function () {

            dongpingMapChart.resize()

        })

    }

    dongpingChart()

})

实现的效果图

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、付费专栏及课程。

余额充值