echarts地图实现3d效果,自定义背景图,打点图标及鼠标经过内容样式

1.引入echarts和json数据

const echarts = require('echarts');

import mapJson from 'echarts/map/json/china.json';

2.实现地图3d效果


      var imgData = '' //地图背景图
      var domImg = new Image();
      domImg.src = imgData;
      this.mapRef = echarts.init(this.$refs.mapRef);
      echarts.registerMap('china', mapJson);
      let options = {
        geo: [
          {
            // 主图
            map: 'china',
            zlevel: 0,
            zoom: 1.2, //当前视角的缩放比例
            roam: false, //是否开启平游或缩放
            center: undefined,
            top: '15%',//***********重点**********距离顶部的位置,每层向下一个百分比
            left: '10%',
            show: true,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            itemStyle: {
              normal: {
                borderColor: "rgb(17,246,242)",
                borderWidth: 1,
                areaColor: {
                  type: "pattern",
                  image: domImg, //配置图片
                  repeat: "repeat", //可选值repeat、no-repeat、repeat-x、repeat-y
                },
              },
              emphasis: {
                areaColor: "inherit"
              },
            },
          },
          //第一层投影
          {
            map: 'china',
            zlevel: -1,
            zoom: 1.2, //当前视角的缩放比例
            roam: false, //是否开启平游或缩放
            center: undefined,
            top: '15.1%',//***********重点**********距离顶部的位置,每层向下一个百分比
            left: '10%',
            show: true,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            itemStyle: {
              normal: {
                borderJoin: "round",
                borderColor: "rgb(17,246,242)",
                borderWidth: 5,
                areaColor: "rgba(22,67,91, 1)",
                shadowColor: "rgba(22,67,91, .7)",
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 28,
              },
              emphasis: {
                areaColor: "inherit"
              },
            },
            regions: [
              {
                name: "南海诸岛",
                itemStyle: {
                  // 隐藏地图
                  normal: {
                    opacity: 0, // 为 0 时不绘制该图形
                  }
                },
                label: {
                  show: false // 隐藏文字
                }
              },
            ],
          },
          {
            map: 'china',
            zlevel: -2,
            zoom: 1.2, //当前视角的缩放比例
            roam: false, //是否开启平游或缩放
            center: undefined,
            top: '16.5%',//***********重点**********距离顶部的位置,每层向下一个百分比
            left: '10%',
            show: true,
            label: {
              normal: {
                show: false,
              },
              emphasis: {
                show: false,
              },
            },
            itemStyle: {
              normal: {
                borderJoin: "round",
                borderColor: "rgba(53,75,86,1)",
                borderWidth: 5,
                areaColor: "rgba(24,60,85, 1)",
                shadowColor: "rgba(24,60,85, .7)",
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 25,
              },
              emphasis: {
                areaColor: "inherit"
              },
            },
            regions: [
              {
                name: "南海诸岛",
                itemStyle: {
                  // 隐藏地图
                  normal: {
                    opacity: 0, // 为 0 时不绘制该图形
                  }
                },
                label: {
                  show: false // 隐藏文字
                }
              },
            ],
          },
        ],
        series: [{
          type: "scatter",
          coordinateSystem: "geo",
          symbol: 'image://' + require('图片url'), //自定义打点图标
          symbolSize: [18, 21],
          data: this.convertData(this.cityData), //处理数据格式
          hoverAnimation: true,
          label: {
            normal: {
              formatter: "{b}",
              position: "bottom",
              show: true,
              color: "#fff",
              fontSize: 12,
            },
          },
          zlevel: 1,
        }],
        tooltip: {
          trigger: 'item', // 触发类型,'item' 表示数据项图形触发,'axis' 表示坐标轴触发
          backgroundColor: "transparent",
          formatter: function (params) {
            let str = `html代码` //自定义鼠标经过的提示
            // params 是包含当前数据信息的对象
            return str;
          }
        },
      }
      this.mapRef.setOption(options);
      window.addEventListener('resize', () => {
        this.mapRef.resize()
      })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值