echarts地图显示数据处理arcgis合并乡镇

在echarts中实现地图展示

显示效果

根据自己的需求可调整样式,比如阴影立体效果。
在这里插入图片描述

实现代码

import mapjson from '@/assets/mapjson/431123.json'
// vue初始化地图方法
 initecharts() {
      var this_ = this//this失效处理
      let myChart = this.$echarts.init(this.$refs.XZMAP)
      myChart.on('click', function (e) {
      //地图点击事件,写自己的业务需求

      })
      this.$echarts.registerMap('China', mapjson)
      var dataArr = mapjson.features
      var data = []
      //处理得到mapjson 里面每个乡镇的范围
      for (let i = 0; i < dataArr.length; i++) {
        var c = this.color16()//设置背景颜色
        var data_list = {
          name: dataArr[i].properties.name,
          value: dataArr[i].properties.value,
          itemStyle: {
            normal: {
              areaColor: c,
              borderColor: c,
            },
          },
        }
        data.push(data_list)
      }
      
      myChart.hideLoading()
      let option_tmp = {
        baseOption: {
          grid: {
            right: '2%',
            top: '10%',
            bottom: '10%',
            width: '18%',
          },
          tooltip: {
            trigger: 'axis', // hover触发器
            axisPointer: {
              // 坐标轴指示器,坐标轴触发有效
              type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
              shadowStyle: {
                color: 'rgba(150,150,150,0.1)', //hover颜色
              },
            },
          },
          series: [
            //数据系列
            {
              type: 'map', //地图类型
              //地图上文字
              label: {
                normal: {
                  show: true, //是否显示标签
                  textStyle: {
                    color: '#333333',
                  },
                },
                emphasis: {
                  textStyle: {
                    color: '#fff',
                  },
                },
              },
              //地图区域的多边形 图形样式

              zoom: 1.2, //当前视角的缩放比例
              //是否开启鼠标缩放和平移漫游。默认不开启。如果只想要开启缩放或者平移,可以设置成 'scale' 或者 'move'。设置成 true 为都开启
              roam: true,
              map: 'China', 
              data: data,
            },
          ],
        },
        options: [],
      }
      //初始化
      myChart.setOption(option_tmp)
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    },

  color16() {
      //十六进制颜色随机
      const r = Math.floor(Math.random() * 256)
      const g = Math.floor(Math.random() * 256)
      const b = Math.floor(Math.random() * 256)
      const color = `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`
      return color
    },

数据格式要求:什么样的数据才能在 echarts中使用?

.geojson标准的json文件
在这里插入图片描述

如何获得

伸手可得:https://datav.aliyun.com/portal/school/atlas/area_selector
可到县一级的数据

如何把shp转成json

https://mapshaper.org/

arcgis软件处理按县的shp文件

1、打开自己的shp文件
在这里插入图片描述
查找数据
在这里插入图片描述
导出shp格式数据
在这里插入图片描述
合并乡镇
1、开启编辑
在这里插入图片描述
2、shift选择要合并的区域
在这里插入图片描述
3、进行合并
在这里插入图片描述

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

余额充值