echarts map地图设置外边框或者阴影

4,421 阅读1分钟

换个思路实现起来也很简单,比如设计图是这个样子:

你觉得边框不好实现,但是你会不会实现下面两种样子

细边框:

粗边框:

如果你说你都会,那么问题就解决了,如果想实现阴影就把底层map的边框改成阴影,两个重叠一下就是你想要的效果(center,aspectScale和zoom需要一样),附上关键代码:

geo: {
              map: 'china',
              center: [112.194115019531, 23.582111640625],
              zoom: 12,
              aspectScale: 1, //长宽比
              label: {
                normal: {
                  show: true,
                  textStyle: {
                    fontSize: 16,
                    color: '#ccc'
                    }
                  },
                emphasis: {
                  show: false,
                  textStyle: {
                    color: '#ccc'
                  }
                }
                },
              roam: false,
              itemStyle: {
                normal: {
                  borderColor: "#fff",
                  borderWidth: 5,
                  areaColor: '#272235',
                  fontWeightL: 700,
                /*  shadowBlur:20,
                  shadowColor: '#fff',*/

                },
                emphasis: {
                  areaColor: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                      offset: 0, color: '#3f15d6' // 0% 处的颜色
                    }, {
                      offset: 1, color: '#d243cd' // 100% 处的颜色
                    }],
                    globalCoord: false // 缺省为 false
                  }
                }
              }
            },


            series: [
              {
                type: 'map',
                map: 'china',
                center: [112.194115019531, 23.582111640625],
                zoom: 12,
                geoIndex: 1,
                aspectScale: 1, //长宽比
                showLegendSymbol: false, // 存在legend时显示

                label: {
                  normal: {
                    show: true,
                    textStyle: {
                      fontSize: 16,
                      color: '#ccc'
                    }
                  },
                  emphasis: {
                    show: false,
                    textStyle: {
                      color: '#ccc'
                    }
                  }
                },
                roam: false,
                itemStyle: {
                  normal: {
                    areaColor: '#272235',
                    borderColor: '#fff',
                    fontWeightL: 700,
                    borderWidth: 1
                  },
                  emphasis: {
                    areaColor: {
                      type: 'linear',
                      x: 0,
                      y: 0,
                      x2: 0,
                      y2: 1,
                      colorStops: [{
                        offset: 0, color: '#3f15d6' // 0% 处的颜色
                      }, {
                        offset: 1, color: '#d243cd' // 100% 处的颜色
                      }],
                      globalCoord: false // 缺省为 false
                    }
                  }
                },
                data: []
              }
              ]

本篇如能对您有所帮助,实在是感到荣幸。如有不合理之处也请大家多多指点