大屏-echarts地图的注册使用

我安装的版本是echarts@4.9.0 内含中国、各省核心js和JSON文件 可直接引用,但没有各市区地图文件,若更新到echarts5以上各省市地图文件也不自带了,需到三方库中自行下载,连接如下:

js文件获取 https://github.com/echarts-maps

JSON文件获取 DataV.GeoAtlas地理小工具系列

 script标签中 echarts注册:

  import echarts from 'echarts';
  import 'echarts/map/js/china.js' // 核心文件
  import  './components/city/cityfiles/yancheng.js' // 核心文件
  import  './components/city/cityfiles/changzhou.js' // 核心文件
  import  './components/city/cityfiles/wuxi.js' // 核心文件
  import yancheng from './components/city/cityfiles/yancheng.json' // 引入json文件
  import changzhou from './components/city/cityfiles/changzhou.json' // 引入json文件
  import wuxi from './components/city/cityfiles/wuxi.json' // 引入json文件
  echarts.registerMap('yancheng', yancheng) // 在echarts中注册使用这个文件
  echarts.registerMap('changzhou', changzhou) // 在echarts中注册使用这个文件
  echarts.registerMap('wuxi', wuxi) // 在echarts中注册使用这个文件

 给个宽高:

      <div id="Charts" style="width:100%; height:100%;position: relative;">

绘制方法:

drawCharts () {
        let myChart = echarts.init(document.getElementById('Charts'))
        let seriesData = [];
        let points1 = []
        let points2 = []
        console.log('-----this.regionData-----',this.regionData);
        
        for (let item of this.regionData) {
          if(this.citycode==320900){  //盐城
            if(item.name=='亭湖区'){
              points1 = [[120.213202,33.393723],[120.213202,33.393723]];
              points2 = [[120.213202,33.393723],[122.016138,33.806525]];
            }else if(item.name=='盐都区'){
              points1 = [[119.938393,33.233457],[119.708427,33.268239]];
              points2 = [[119.708427,33.268239],[119.354279,33.10774]];
            }else if(item.name=='大丰区'){
              points1 = [[120.513308,33.173522],[120.823763,33.304938]];
              points2 = [[120.823763,33.304938],[121.318191,33.326177]];
            }else if(item.name=='响水县'){
              points1 = [[119.675198,34.195351],[119.52342,34.302298]];
              points2 = [[119.52342,34.302298],[119.234309,34.29353]];
            }else if(item.name=='滨海县'){
              points1 = [[119.888563,34.028752],[120.153024,34.328834]];
              points2 = [[120.153024,34.328834],[120.45658,34.351726]];
            }else if(item.name=='阜宁县'){
              points1 = [[119.766681,33.769859],[119.766681,33.769859]];
              points2 = [[119.766681,33.769859],[118.747931,33.883103]];
            }else if(item.name=='射阳县'){
              points1 = [[120.24731,33.787144],[120.59226,33.994279]];
              points2 = [[120.59226,33.994279],[121.010799,33.975121]];
            }else if(item.name=='建湖县'){
              points1 = [[119.791978,33.552548],[119.414833,33.552548]];
              points2 = [[119.414833,33.552548],[118.747931,33.490908]];
            }else if(item.name=='东台市'){
              points1 = [[120.43972,32.849936],[120.954844,32.888752]];
              points2 = [[120.954844,32.888752],[121.676938,32.811103]];
            }else{
              continue
            }
          }else if(this.citycode==320400){   //常州
            if(item.name=='天宁区'){
              points1 = [[120.022793,31.790442],[120.057692,31.838859]];
              points2 = [[120.057692,31.838859],[120.234322,31.84612]];
            }else if(item.name=='钟楼区'){
              points1 = [[119.905534,31.806643],[120.06766,31.751636]];
              points2 = [[120.06766,31.751636],[120.440205,31.664146]];
            }else if(item.name=='戚墅堰区'){
              continue
            }else if(item.name=='新北区'){
              points1 = [[119.935429,31.893015],[119.761312,31.888846]];
              points2 = [[119.761312,31.888846],[119.511745,31.977227]];
            }else if(item.name=='武进区'){
              points1 = [[119.89806,31.641523],[120.226911,31.503204]];
              points2 = [[120.226911,31.503204],[120.308549,31.429283]];
            }else if(item.name=='溧阳市'){
              points1 = [[119.469748,31.463294],[119.257029,31.415971]];
              points2 = [[119.257029,31.415971],[118.984519,31.413999]];
            }else if(item.name=='金坛市'){
              points1 = [[119.600828,31.753601],[119.352465,31.731982]];
              points2 = [[119.352465,31.731982],[119.140896,31.734931]];
            }else if(item.name=='其它区'){
              continue
            }else{
              continue
            }
          }else if(this.citycode==320200){   //无锡
            if(item.name=='锡山区'){
              points1 = [[120.424466,31.673273],[120.527951,31.717024]];
              points2 = [[120.527951,31.717024],[120.800461,31.812074]];
            }else if(item.name=='惠山区'){
              points1 = [[120.212323,31.691957],[120.127235,31.746999]];
              points2 = [[120.127235,31.746999],[119.936937,31.76493]];
            }else if(item.name=='滨湖区'){
              points1 = [[120.264639,31.455685],[120.307758,31.447306]];
              points2 = [[120.307758,31.447306],[120.449762,31.267715]];
            }else if(item.name=='梁溪区'){
              points1 = [[120.276713,31.587678],[120.181493,31.592199]];
              points2 = [[120.181493,31.592199],[119.490229,31.579311]];
            }else if(item.name=='新吴区'){
              points1 = [[120.433953,31.487715],[120.504954,31.44632]];
              points2 = [[120.504954,31.44632],[120.692376,31.413289]];
            }else if(item.name=='江阴市'){
              points1 = [[120.278654,31.87143],[120.049334,31.936263]];
              points2 = [[120.049334,31.936263],[119.885915,31.946865]];
            }else if(item.name=='宜兴市'){
              points1 = [[119.818505,31.282036],[119.429143,31.31243]];
              points2 = [[119.429143,31.31243],[119.23748,31.375592]];
            }else if(item.name=='经济开发区'){
              continue
            }else{
              continue
            }
          }
        
        seriesData.push(
          {
          type:'lines',
          symbol:['image://http-----_point.png'], //起点终点样式
          coordinateSystem :'geo',  //坐标系类型 geo:地理坐标系
          symbolSize:[15,15],
          lineStyle:{
            opacity:1,
            color:'#00C705',
            width:0.5
          },
          data:[{
              coords:points1
              },
          ]
        },{
          type:'lines',
          coordinateSystem :'geo',  //坐标系类型 geo:地理坐标系
          label:{
            show:true,
            width:this.autowidth/16,
            // padding:[30,20],
            height:25,
            color:'#ffffff',
            backgroundColor: {
              image: 'http://------/bg.png'
            },
          },
          lineStyle:{
            opacity:1,
            width:0.5,
            color:'#00C705',
          },
          data:[
            {
              name:item.name,
              coords:points2,
              label: {
                lineHeight:17,
                // padding:[25,20],
                padding:[this.autowidth/112,this.autoheight/144],
                formatter:[
                '{all|已办证:}{one|'+item.papersNum + '\n}{all2|审批中:}{two|'+item.checkNum +'}'
                ].join('\n'),
                rich:{
                  all:{
                    align:'left',
                    color: '#fff',
                    verticalAlign:'top',
                    fontSize:this.fontSize(0.13)

                  },
                  all2:{
                    align:'left',
                    color: '#fff',
                    verticalAlign:'top',
                    fontSize:this.fontSize(0.13)

                  },
                  one:{
                    color: '#00C705',
                    align:'left',
                    verticalAlign:'top',
                    fontSize:this.fontSize(0.13)

                  },
                  two:{
                    color: '#FFC233',
                    align:'left',
                    verticalAlign:'top',
                    fontSize:this.fontSize(0.13)

                  },
             
                }
              }
          }]
        },

        
        );
    }
    if(this.citycode==320900){
        //盐城
        myChart.setOption({
            tooltip: {
              show:true,
              // trigger: 'item',
              // formatter: '{c}'
            },
            series:seriesData,
            geo: {
                map: 'yancheng',
                roam: false, //不开启缩放和平移
                zoom: 1, //视角缩放比例
                label: {
                    show: true,
                    fontSize: '10',
                    color: '#EAEDFF',
                    emphasis: {  //鼠标悬浮相关样式
                      show:false,
                      textStyle: {
                          color: '#F9F9F9'
                      }
                  }
                },
                itemStyle: {
                    normal:{
                    areaColor:'#031C6A',
                    borderColor:'#00FFFF',
                    borderWidth:0.4
                  },
                emphasis: {
                    areaColor: '#5D78F2', //鼠标选择区域颜色
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
                }
            },
        })
    }else if(this.citycode==320400){
      //常州
      myChart.setOption({
            tooltip: {
              show:true,
              // trigger: 'item',
              // formatter: '{c}'
            },
            series:seriesData,
            geo: {
                map: 'changzhou',
                roam: false, //不开启缩放和平移
                zoom: 1.1, //视角缩放比例
                label: {
                    show: true,
                    fontSize: '10',
                    color: '#EAEDFF',
                    emphasis: {  //鼠标悬浮相关样式
                      show:false,
                      textStyle: {
                          color: '#F9F9F9'
                      }
                  }
                },
                itemStyle: {
                    normal:{
                    areaColor:'#031C6A',
                    borderColor:'#00FFFF',
                    borderWidth:0.4
                  },
                emphasis: {
                    areaColor: '#5D78F2', //鼠标选择区域颜色
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
                }
            },
        })
    }else if(this.citycode==320200){
      //无锡
      myChart.setOption({
            tooltip: {
              show:true,
              // trigger: 'item',
              // formatter: '{c}'
            },
            series:seriesData,
            geo: {
                map: 'wuxi',
                roam: false, //不开启缩放和平移
                zoom: 1.1, //视角缩放比例
                label: {
                    show: true,
                    fontSize: '10',
                    color: '#EAEDFF',
                    emphasis: {  //鼠标悬浮相关样式
                      show:false,
                      textStyle: {
                          color: '#F9F9F9'
                      }
                  }
                },
                itemStyle: {
                    normal:{
                    areaColor:'#031C6A',
                    borderColor:'#00FFFF',
                    borderWidth:0.4
                  },
                emphasis: {
                    areaColor: '#5D78F2', //鼠标选择区域颜色
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
                }
            },
        })
    }

        window.addEventListener('resize', function() {
          myChart.resize();
        });
   
    },

 给每个区域添加提示框中间的连接线的的时候,是push了两个对象,直接数组生成折线的方法对本项目不适用;另外需要注意的一点是整个echarts图表中文字的自适应,我在项目中自定义的fontsize方法在需要自适应的地方使用:

fontSize(res) { // 如在1920屏宽下字体设置为12px,就可以传入0.12给fontSize fontSize(0.12)
        let docEl = document.documentElement,
          clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        if (!clientWidth) return;
        let fontSize = 100 * (clientWidth / 1920);
        return res * fontSize;
      },

监听窗口变化:

window.addEventListener('resize', function() {
        _this.autoWidth();
        _this.autoHeight()
      });

//解决window.resize 不生效的问题

 效果如下:

 先这样吧

  • 2
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ECharts是一款功能强大的开源数据可视化库,它提供了丰富的图表类型和交互功能,可以用于实现江苏地图的可视化。 要实现江苏地图,首先需要准备地图数据。可以通过ECharts提供的第三方地图工具或者自行寻找江苏地图的地理数据,获取到地图的边界和各个区域的经纬度坐标。 接下来,使用ECharts的地图组件,将地理数据导入到地图中。可以通过`echarts.registerMap`方法注册江苏地图的数据,然后将地图展示在页面上的指定容器中。 在地图中展示区域的数据,可以使用ECharts的系列(series)功能。通过配置series的type为`map`,设置mapType为`江苏`,并设置data属性为需要展示的数据,即可在地图上展示各个区域的信息,如人口分布、GDP等。 为了增加交互性,可以使用ECharts的视觉映射(visualMap)功能。通过配置visualMap的范围和颜色,可以通过颜色的深浅来表示数据的差异。例如,可以使用不同的颜色来区分各个地区的人口密度。 此外,还可以通过ECharts提供的其他功能,如标记(markPoint)、线条(lines)等来进一步扩展地图的展示效果。比如,在地图上标注重要城市或景点的位置,或者展示不同地区之间的交通流量等。 最后,通过ECharts的配置项,可以调整地图的样式、颜色、字体等,以及添加图表的标题、图例等,以满足个性化的需求。 总之,通过ECharts可以很方便地实现江苏地图的可视化展示,展示地区数据的分布和差异,提升数据的可解释性和交互性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值