vue使用echarts实现3D地图模型


​​​​​​​<div id="main" class="mainbox" style="width:80%;height:100%;"></div>


//引入省、市 json文件,后面要通过这个json文件请求指定getjson文件
import shengJSON from '../../../../public/static/mapJSON/sheng.json'
import shiJSON from '../../../../public/static/mapJSON/shi.json'; // 引入 JSON 文件
import china from '../../../../public/static/mapJSON/china.json'; // 引入 JSON 文件
// 34个省、市、自治区的名字拼音映射数组
var provinces = shengJSON //省
var cityMap = shiJSON // 市
// 直辖市和特别行政区没有三级地图
var special = ['北京市', '天津市', '上海市', '重庆市', '香港特别行政区', '澳门特别行政区']


 data() {
    return {
  option: {
        series: [
          {
            type: 'lines',
            coordinateSystem: 'geo', // 使用地理坐标系
            data: [],
            zlevel: 2,
            symbol: ['none', 'arrow'], //飞线起点终点点位样式
            symbolSize: 10, // 飞线起点终点点位大小
            lineStyle: {
              color: '#93EBF8',
              width: 2.5, //尾迹线条宽度
              opacity: 0.6, //尾迹线条透明度
              curveness: 0.2, //尾迹线条曲直度
              animation: true, // 启用动画
              type: 'solid' // 设置为虚线
              //solid实线, dashed //虚线
            },
            effect: {
              show: true,
              period: 4, // 动画周期
              trailLength: 0.5, // 尾迹长度
              color: '#93EBF8',
              symbol: 'arrow',
              symbolSize: [10, 5]
            }
          },
          {
            type: 'effectScatter',
            zlevel: 3,
            coordinateSystem: 'geo',
            emphasis: {
              label: {
                show: true,
                position: 'top',
                color: '#fff',
                formatter: '{b|{b}}'
              }
            },
            data: [],
            symbol: 'circle',
            symbolSize: [20, 10],
            label: {
              show: true, // 显示标签
              formatter: '{b}', // 使用名称
              position: 'top', // 标签位置
              color: '#fff' // 标签颜色
            },
            itemStyle: {
              color: 'orange',
              shadowBlur: 10,
              shadowColor: 'orange'
            },
            effectType: 'ripple',
            showEffectOn: 'render', //emphasis移入显示动画,render一开始显示动画
            rippleEffect: {
              scale: 3,
              period: 7,
              //fill,stroke
              brushType: 'stroke'
            }
          }
        ],
        geo: [   //三层的重影模拟3D形态
          {
            map: 'china',
            type: 'map',
            aspectScale: 1,
            zoom: 1.5,
            layoutCenter: ['50%', '63%'],
            layoutSize: '100%',
            show: true,
            roam: false,
            label: {
              show: false, // 各个省市县的名字
              color: '#fff'
            },
            itemStyle: {
              areaColor: 'rgba(58,149,253,1)', // 默认颜色
              borderColor: '#c0f3fb',
              borderWidth: 0.8
            },
            emphasis: {
              itemStyle: {
                show: false,
                color: '#fff',
                areaColor: 'rgba(0,254,233,0.6)'
              },
              label: {
                show: true,
                color: '#fff'
              }
            },
            regions: []
          },
          // 重影
          {
            type: 'map',
            map: 'china',

            zlevel: -1,
            aspectScale: 1,
            zoom: 1.5,
            layoutCenter: ['50%', '64%'],
            layoutSize: '100%',
            roam: false,
            silent: true,
            itemStyle: {
              borderWidth: 1,
              borderColor: 'rgba(58,149,253,0.8)',
              shadowColor: 'rgba(172, 122, 255,0.5)',
              shadowOffsetY: 5,
              shadowBlur: 15,
              areaColor: 'rgba(5,21,35,0.1)'
            }
          },
          {
            type: 'map',
            map: 'china',
            zlevel: -2,
            aspectScale: 1,
            zoom: 1.5,
            layoutCenter: ['50%', '65%'],
            layoutSize: '100%',
            roam: false,
            silent: true,
            itemStyle: {
              borderWidth: 1,
              borderColor: 'rgba(58,149,253,0.6)',
              shadowColor: 'rgba(65, 214, 255,0.6)',
              shadowOffsetY: 5,
              shadowBlur: 15,
              areaColor: 'rgba(5,21,35,0.1)'
            }
          }

        ],
        legend: {
          show: false // 这里设置图例不显示
        },
        visualMapOption: {
          show: false
        },
        title: {
          // text: 'Echarts3 离线地图',
          left: 'center',
          textStyle: {
            color: '#fff',
            fontSize: 16,
            fontWeight: 'normal',
            fontFamily: 'Microsoft YaHei'
          },
          subtextStyle: {
            color: 'rgb(104,160,200)',
            fontSize: 13,
            fontWeight: 'normal',
            fontFamily: 'Microsoft YaHei'
          }
        },
        // 鼠标悬停显示信息
        tooltip: {
          trigger: 'item',
          formatter: function (params) {
            return (
              params.seriesName + '<br />' + params.name + ':' + params.value
            )
          }
        },
        animationDuration: 1000,
        animationEasing: 'cubicOut',
        animationDurationUpdate: 1000
        // visualMap: {
        //   show: false, // 隐藏 visualMap 图标
        //   min: 800,
        //   max: 1000,
        //   text: ['High', 'Low'],
        //   calculable: true,
        //   realtime: false,
        //   inRange: {
        //     color: ['rgba(104,160,200)', 'rgba(56, 143, 162)', 'rgba(56, 143, 162)']
        //   }
        // },
      },
 regions: [
      //北部   // '北部战区': ['黑龙江省、吉林省、辽宁省和内蒙古内蒙古自治区,以及山东省],
      {
        name: '吉林省',
        val: '北部战区',
        itemStyle: { normal: { areaColor: 'rgba(9,134,214)', borderWidth: 0 } },
        label: {
          show: true,
          formatter: '北部战区', // 显示的文本
          textStyle: {
            color: 'white',
            fontSize: 35,
            fontFamily: 'KaiTi'
          }
        }
      },
      {
        name: '黑龙江省',
        val: '北部战区',
        itemStyle: { normal: { areaColor: 'rgba(9,134,214)', borderWidth: 0 } }
      },
      {
        name: '辽宁省',
        val: '北部战区',
        itemStyle: { normal: { areaColor: 'rgba(9,134,214)', borderWidth: 0 } }
      },
      {
        name: '山东省',
        val: '北部战区',
        itemStyle: { normal: { areaColor: 'rgba(9,134,214)', borderWidth: 0 } }
      },
      {
        name: '内蒙古自治区',
        val: '北部战区',
        itemStyle: { normal: { areaColor: 'rgba(9,134,214)', borderWidth: 0 } }
      },
      // '‌中部战区‌': [河北省、河南省、陕西省、山西省、湖北省、天津市和首都北京],
      //华北  中部
      {
        name: '北京市',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      {
        name: '天津市',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      {
        name: '河北省',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      {
        name: '山西省', val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } },
        label: {
          show: true,
          formatter: '中部战区', // 显示的文本
          textStyle: {
            color: 'white',
            fontSize: 35,
            fontFamily: 'KaiTi'
          }
        }
      },
      {
        name: '陕西省',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      {
        name: '河南省',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      {
        name: '湖北省',
        val: '‌中部战区‌',
        itemStyle: { normal: { areaColor: 'rgba(229,6,34)', borderWidth: 0 } }
      },
      // '华东  东部   // '东部': ['江苏省、浙江省、福建省、江西省、安徽省和上海市],
      {
        name: '上海市',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      {
        name: '江苏省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      {
        name: '浙江省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } },
        label: {
          show: true,
          formatter: '东部战区', // 显示的文本
          textStyle: {
            color: 'white',
            fontSize: 35,
            fontFamily: 'KaiTi'
          }
        }
      },
      {
        name: '安徽省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      {
        name: '福建省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      {
        name: '江西省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      {
        name: '台湾省',
        val: '东部战区',
        itemStyle: { normal: { areaColor: 'rgba(189,50,121)', borderWidth: 0 } }
      },
      // '中南   南部   // '‌南部战区': ['广东省、湖南省、海南省、云南省、贵州省和广西壮族自治区,以及香港、澳门],

      {
        name: '湖南省',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } },

        label: {
          show: true,
          formatter: '南部战区', // 显示的文本
          textStyle: {
            color: 'white',
            fontSize: 35,
            fontFamily: 'KaiTi'
          }
        }
      },
      {
        name: '广东省',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      {
        name: '广西壮族自治区',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      {
        name: '海南省',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      {
        name: '贵州省',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      {
        name: '云南省',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      {
        name: '南海诸岛',
        val: '南部战区',
        itemStyle: { normal: { areaColor: 'rgba(111,186,42,1)', borderWidth: 0 } }
      },
      // '西南  西部  rgba(111,186,42,1)沙漠色rgba(249,124,4,1)绿洲色    // '西部战区': [四川省、甘肃省、青海省、宁夏回族自治区、西藏自治区、新疆自治区和重庆市],

      {
        name: '四川省',
        val: '西部战区',
        itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } }
      },
      { name: '甘肃省', val: '西部战区', itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } } },
      {
        name: '重庆市',
        val: '西部战区',
        itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } }
      },
      {
        name: '宁夏回族自治区',
        val: '西部战区',
        itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } }
      },
      {
        name: '青海省',
        val: '西部战区',
        itemStyle: {
          normal: {
            areaColor: 'rgba(249,124,4,1)', borderWidth: 0
          }
        },
        label: {
          show: true,
          formatter: '西部战区', // 显示的文本
          textStyle: {
            color: 'white',
            fontSize: 35,
            fontFamily: 'KaiTi'
          }
        }
      },
      {
        name: '西藏自治区',
        val: '西部战区',
        itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } }
      },
      {
        name: '新疆维吾尔自治区',
        val: '西部战区',
        itemStyle: { normal: { areaColor: 'rgba(249,124,4,1)', borderWidth: 0 } }
      }

    ],
pointsBD: [
      {
        name: '新疆', value: [87.628579, 43.793301], itemStyle: { color: '#00EEFF' }
      },
      {
        name: '郑州', value: [113.6249, 34.7466], itemStyle: { color: '#00EEFF' }
      },
      {
        name: '永州', value: [111.608275, 26.435102], itemStyle: { color: '#00EEFF' }
      },
      {
        name: '哈尔滨市', value: [126.642464, 45.756967], itemStyle: { color: '#00EEFF' }
      },
      {
        name: '南京市', value: [118.796989, 32.060255], itemStyle: { color: '#00EEFF' }
      },
      // {
      //   name: '云南', value: [102.709372, 25.046434], itemStyle: { color: '#00EEFF' }
      // },
      // {
      //   name: '北京', value: [116.407387, 39.904179], itemStyle: { color: '#00EEFF' }
      // },
      {
        name: '武汉', value: [114.2986, 30.5823], itemStyle: { color: '#00EEFF' }
      },

    ],
    linesDataBD: [
      //战区1级
      {
        coords: [[87.628579, 43.793301], [111.608275, 26.435102]],//新疆到永州
        lineStyle: {
          color: '#93EBF8',
          width: 2.5, //尾迹线条宽度
          opacity: 0.6, //尾迹线条透明度
          curveness: 0.2, //尾迹线条曲直度
          type: 'solid' // 虚线

        }
      },
      {
        coords: [[126.642464, 45.756967], [118.796989, 32.060255]], // 哈尔滨市到南京市的飞线
        lineStyle: {
          color: '#93EBF8',
          width: 2.5,
          opacity: 0.6,
          curveness: 0.2,
          type: 'solid' //

        }
      },
    ],
    }
}



init(){
 this.myMapChart = echarts.init(document.getElementById('main'))
  echarts.registerMap('china', china)//注册地图的数据,china,
        this.option.series[0].data = this.linesDataZX // 飞线数据
        this.option.series[1].data = this.pointsZX // 点位数据
        this.option.geo[0].regions =this.regions    //这个是战区颜色分布

      this.myMapChart.setOption(this.option)
      this.myMapChart.on('click', this.clickMap)//加点击事件,可下钻
      


}
 /* 地区区域点击事件 */
    async  clickMap(params) {
      let origin=window.location.origin
      let centerCoord=''
      if (params.name in provinces) {
        let res=await this.$axios.get(`${origin}/static/mapJSON/province/${provinces[params.name]}.json`);
     
       if(res.data.features[0].properties.childrenNum==0){
         let shengAll = this.getChildMap(china)
         this.renderMap(shengAll,params.name)
         return
       }
        this.$echarts.registerMap(params.name, res.data)
        let shiAll = this.getChildMap( res.data)
        this.renderMap( shiAll,params.name)
      } else if (params.seriesName in provinces) {
 
        console.log("市:" + params.name)
        if (special.indexOf(params.seriesName) >= 0) { //直辖市和特别行政区没有下级了,返回大图
          this.renderMap('china',params.name,)
        } else {
          let res1=await this.$axios.get(`${origin}/static/mapJSON/city/${cityMap[params.name]}.json`);
  
          this.$echarts.registerMap(params.name, res1.data)
          let xianAll = this.getChildMap(res1.data)
          this.renderMap( xianAll,params.name,)
          return
 
        }
      } else {
        let shengAll = this.getChildMap(china)
        this.renderMap(shengAll,params.name)
      }
    },
 
    getChildMap(data) {
      let childMapAll = []
      for (var i = 0; i < data.features.length; i++) {
        childMapAll.push({
          name: data.features[i].properties.name,
          value: 0
        })
      }
      return childMapAll
    },
renderMap(geoJson, name) {
      this.option.geo.forEach((v) => {
        v.map = name
        v.layoutSize = name == 'china' ? '100%' : '70%'
      })
  this.myMapChart.setOption(this.option)
    },

 上一篇我也写过charts地图,但是那个不是3d模型形态的,这个是优化版,主要是option里面的,其他的没什么变化

这个是效果图,旁边的不要管,

这个是用到的地图数据csdn - 安全中心https://link.csdn.net/?from_id=141921612&target=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fwwk.lanzout.com%2FiwZ531p52e7a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值