echarts 地图轮廓边框

echarts 地图轮廓边框

最近搞了个需求要求地图轮廓搞个边框,找了下官网没有找到对应的配置,在 issue 中看到有人图层叠加的方式实现,在此记录一下。其思想就是底图的边框搞粗一点,两个图层叠加后,达到边框效果。

js 复制代码
echartInst?.setOption({
    geo: [
      {
        // 跟随图层动画必须关闭,否则会出现图层分离的现象
        animationDurationUpdate: 0,
        // 禁用底图,底图坐标跟随顶层图层
        roam: false,
        map: 'test',
        layoutCenter: ['50%', '50%'],
        layoutSize: '100%',
        emphasis: {
          disabled: true
        },
        itemStyle: {
          areaColor: '#73E6FF',
          borderColor: '#73E6FF',
          borderWidth: 6,
          shadowColor: '#012FE0',
          shadowOffsetX: 2,
          shadowOffsetY: 10
        }
      },
      {
        type: 'map',
        map: 'test',
        roam: true,
        emphasis: {
          disabled: false,
          label: {
            color: '#fff'
          },
          itemStyle: {
            areaColor: '#389BC5',
            borderColor: '#1E78C1',
            borderWidth: 1
          }
        },
        itemStyle: {
          areaColor: '#0F3877',
          borderColor: '#1E78C1',
          borderWidth: 1
        },
        label: {
          color: '#fff'
        }
      }
    ]
  })

bottomLayer 要把 roma 禁用掉,不然要做图层跟随逻辑的判断,这里我为了方便就禁掉了,让 bottomLayer 跟随 topLayer 图层变化(这里导致点击外轮廓时无反应) 。通过监听georoam事件,让 bottomLayer 的center,zoom 跟随着 topLayer 变化就完事了。这里需要注意的时 bottomLayer 的动画要关闭(animationDurationUpdate置为0,默认好像有0.5s),不然会看到明显的图层分离

js 复制代码
  echartInst.on('georoam', function () {
    const options = echartInst.getOption()
    const [bottomLayer,topLayer] = (options.geo as Array<any>)
    const { center, zoom } = topLayer
    bottomLayer.center = center
    bottomLayer.zoom = zoom
    echartInst.setOption(options)
  })
相关推荐
FogLetter1 分钟前
初识图片懒加载:让网页像"懒人"一样聪明加载
前端·javascript
微客鸟窝2 分钟前
一文搞懂NVM管理Node.js:从安装到实战全攻略
前端
归于尽3 分钟前
Cookie、Session、JWT 的前世今生
前端
程序员辉哥4 分钟前
学会在Cursor中使用Rules生成代码后可以躺平了吗?
前端·后端
请你吃div9 分钟前
JavaScript 实用函数大全(超实用)
前端·javascript·面试
一个水瓶座程序猿.10 分钟前
Vue3 中使用 Vueuse
前端·javascript·vue.js
夏梦春蝉11 分钟前
ES6从入门到精通:Symbol与迭代器
前端·javascript·es6
一个水瓶座程序猿.14 分钟前
ES6数组的`flat()`和`flatMap()`函数用法
前端·ecmascript·es6
袁煦丞30 分钟前
AI直接出答案!Perplexica开源搜索引擎:cpolar内网穿透实验室第534个成功挑战
前端·程序员·远程工作
Hilaku32 分钟前
用“人话”讲明白10个最常用的正则表达式
前端·javascript·正则表达式