[echarts]多个geo实现缩放拖拽同步完美

geo: [
          {
            map: 'xxx',
            animationDurationUpdate: 0, // 建议添加 拖拽更丝滑
            roam: true, // 允许拖动
            layoutCenter: ['50%', '50%'],
            layoutSize: '100%',
            silent: true,
            scaleLimit: {
              min: 1,
              max: 6,
            },
          },
          {
            map: 'xxxx',
            animationDurationUpdate: 0, // 建议添加 拖拽更丝滑
            roam: true, // 允许拖动
            layoutCenter: ['50%', '50%'],
            layoutSize: '100%',
            silent: true,
            scaleLimit: {
              min: 1,
              max: 6,
            },
          },
      // 监听缩放和拖拽事件
      myChart.on('geoRoam', (params) => {
        const option = myChart.getOption()
        const geoId = params.geoId // 获取当前操作的 geoId
        // 从 geoId 中提取索引
        const currentGeoIndex = parseInt(geoId.split('\u0000series\u0000')[1].split('\u0000')[0]) // 找到变更的geo下标
        if (params.zoom != null && params.zoom != undefined) {
          for (let index = 0; index < option.geo.length; index++) {
            const element = option.geo[index]
            if (index !== currentGeoIndex) {
              element.zoom = option.geo[currentGeoIndex].zoom
              element.center = option.geo[currentGeoIndex].center
            }
          }
          myChart.dispatchAction({
            type: 'restore',
          })
        } else {
          const baseMapGeo = option.geo[currentGeoIndex]
          const zoom = option.geo[currentGeoIndex].zoom
          const center = baseMapGeo.center || ['50%', '50%']
          const dx = params.dx || 0 // 获取水平拖拽距离
          const dy = params.dy || 0 // 获取垂直拖拽距离
          const newCenter = [parseFloat(center[0]) + dx, parseFloat(center[1]) + dy]
          for (let index = 0; index < option.geo.length; index++) {
            const element = option.geo[index]
            if (index !== currentGeoIndex) {
              element.center = newCenter // 更新其他 geo 的 center
            }
          }
        }
        myChart.setOption(option)
      })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值