当前位置:   article > 正文

echarts map地图添加背景图_echarts整合省市地图 背景图

echarts整合省市地图 背景图

map地图添加了一个阴影3d的效果,添加一张背景图,给人感觉有3d的效果

具体配置如下:
html代码模块:

 <div class="echart_img" style="position: fixed; visibility: hidden;"></div>
 <div id="map"></div>
  • 1
  • 2

在mounted方法里面给地图添加背景图

 mounted() {
    let mg = require("../../../../images/jsc/map.png")
    this.domImg = document.createElement('img')
    this.domImg.style.height = this.domImg.height = this.domImg.width = this.domImg.style.width = '7000px'
    this.domImg.src = mg
    document.querySelector('.main-map .echart_img').appendChild(this.domImg)
    setTimeout(() => {
      this.initMap();
    }, 500)
  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

echarts options配置如下:

var chart = this.echarts.init(document.getElementById("map"));
      var option = {
        grid: {
          top: '-20%',
          left: '0%'
        },
        geo: [
          {
            map: 'GD',
            aspectScale: 0.75,
            zoom: 0.65, // 比例调整
            layoutCenter: ['50%', '52%'],
            layoutSize: '100%',
            silent: true,
            roam: false,
            itemStyle: {
              normal: {
                areaColor: 'rgb(37, 104, 188)',
                borderColor: 'rgb(33, 91, 167)',
                borderWidth: 1
              },
              emphasis: {
                areaColor: '#2AB8FF',
                borderWidth: 0,
                color: 'green',
                label: {
                  show: false
                }
              }
            },
          }
        ],
        series: [
          {
            type: "map",
            map: "GD",
            roam: false, //是否开启鼠标缩放和平移漫游
            animationDurationUpdate: 0,
            zoom: 0.8,
            layoutSize: "100",
            label: {
              normal: {
                show: true,
                fontSize: 14,
                color: "#fff",
              },
              emphasis: {
                color: "#fff",
              },
            },
            itemStyle: {
              normal: {
                areaColor: {
                  image: this.domImg,
                  repeat: "repeat-x"
                },
                borderColor: "#678BBB", //省份边框颜色
                borderWidth: 2, // 省份边框宽度
                shadowBlur: 0,
                shadowOffsetX: 0,
                shadowOffsetY: 0
              },
              emphasis: {
                areaColor: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0, color: 'rgba(45, 124, 200, 1)' // 渐变起始颜色
                  }, {
                    offset: 1, color: 'rgba(75, 175, 247, 1)' // 渐变结束颜色
                  }]
                },
                borderColor: "#fff", //省份边框颜色
                borderWidth: 1, // 高亮时的边框宽度
              },
            },
            select: {
              label: {
                show: true,
                color: "#fff",
              },
              itemStyle: {
                areaColor: "#123972", // 高亮时候地图显示的颜色
                borderWidth: 0, // 高亮时的边框宽度
              },
            },
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表
      chart.setOption(option);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95

具体效果如下:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/610818
推荐阅读
相关标签
  

闽ICP备14008679号