echarts map 解决label设置width height无效并附aliyun地图json地址

  1. aliyun地图json地址 http://datav.aliyun.com/tools/atlas/#&lat=30.316551722910102&lng=106.75113472219306&zoom=3.5 (没用过里面json不确定准确性)
  2. 做地图时, 想要给label 加背景图,但是发现width height无效 后改用rich 形式有效。
  3. 后来又发现无论怎么设置verticalAlign,都没有改变里层label的位置,经测试需要在外层设置行高verticalAlign才有效,输出formatter可以发现 marker字段中实质使用的是span
  4. 附图形效果和代码
  5. graph.dataCenterMap = function (dom, data) {
      var myChart = echarts.init(document.getElementById(dom));
    
      var label1 = {
        normal: {
          position: 'top',
          // padding: [30, 0, 0, 0],
          // offset: [0, 10],
          color: '#1DE9B6',
          show: true,
          width: 3.54 * vwToPx,
          height: 5.09 * vhToPx,
          lineHeight: 5.09 * vhToPx,
          formatter: function (params) {
            console.log(params);
            var html = '';
            var info1 = params.data.info;
            var info2 = params.data.info2;
            if (info1) {
              html = info1;
            } else if (info2) {
              html = info2;
            }
            return ['{a|' + html + '}'];
          },
          fontSize: 12,
          // verticalAlign: 'bottom',
          backgroundColor: {
            image: '../../images/mapSend.png',
          },
          rich: {
            a: {
              padding: [0, 0, (5.09 * vhToPx) / 2, 0],
              align: 'center',
              color: '#fff',
            },
          },
        },
      };
    
      var labelData1 = [
        { value: [125.774678, 44.389735], info: 10, info2: 8 },
        { value: [126.57, 43.87], info: 7 },
      ];
    
      // var temData1 = [];
      labelData1.some(function (item, index) {
        var temLabel = jQuery.extend(true, {}, label1);
        if (item.info) {
          temLabel.show = true;
        }
        item.label = temLabel;
      });
      // var uploadedDataURL = "/asset/get/s/data-1482909892121-BJ3auk-Se.json";
      myChart.showLoading();
      let index = -1;
    
      echarts.registerMap('mychina', geoJson);
      myChart.hideLoading();
      var option = {
        geo: [
          {
            map: 'mychina',
            // zIndex: -1,
            aspectScale: 0.75, //长宽比
            zoom: 1.1,
            roam: false,
            regions: [
              {
                name: '南海诸岛',
                opacity: 0,
                show: false,
                itemStyle: {
                  opacity: 0,
                  // 隐藏地图
                  normal: {
                    opacity: 0, // 为 0 时不绘制该图形
                  },
                },
                emphasis: {
                  normal: {
                    opacity: 0, // 为 0 时不绘制该图形
                  },
                },
                label: {
                  show: false, // 隐藏文字
                },
              },
            ],
            itemStyle: {
              normal: {
                borderWidth: 0, //设置外层边框
                borderColor: 'RGBA(72, 173, 220, 1)',
                shadowColor: 'RGBA(23, 68, 84, 0.62)',
                areaColor: 'RGBA(23, 50, 69, 0.5)',
                shadowOffsetX: -10,
                shadowOffsetY: 35,
              },
              emphasis: {
                areaColor: 'RGBA(27, 73, 91, 1)',
                borderWidth: 0,
                show: false,
                color: 'RGBA(27, 73, 91, 1)',
                label: {
                  show: false,
                },
              },
            },
          },
        ],
    
        series: [
          // 基础地图绘制
          {
            type: 'map',
            roam: false,
            label: {
              normal: {
                show: true,
                textStyle: {
                  color: '#fff',
                },
              },
              emphasis: {
                show: false,
                textStyle: {
                  color: '#fff',
                },
              },
            },
    
            itemStyle: {
              normal: {
                borderColor: 'RGBA(72, 173, 220, 1)',
                borderWidth: 1,
                areaColor: 'RGBA(23, 50, 69, 0.5)',
              },
              emphasis: {
                borderColor: 'RGBA(72, 173, 220, 1)',
                borderWidth: 1,
                areaColor: 'RGBA(23, 50, 69, 0.5)',
              },
            },
            zoom: 1.1,
            aspectScale: 0.75, //长宽比
            map: 'mychina', //使用
            // data: data[0],
    
            data: [
              {
                name: '延边州',
                selected: true,
                emphasis: {
                  itemStyle: {
                    areaColor: 'RGBA(72, 173, 220, 0.5)',
                    borderColor: 'RGBA(72, 173, 220, 1)',
                    borderWidth: 1,
                  },
                },
                info: 10,
                info2: 7,
              },
              {
                name: '吉林市',
                selected: true,
                emphasis: {
                  itemStyle: {
                    areaColor: 'RGBA(72, 173, 220, 0.5)',
                    borderColor: 'RGBA(72, 173, 220, 1)',
                    borderWidth: 1,
                  },
                },
              },
            ],
          },
          // 点的绘制
          {
            type: 'effectScatter',
            coordinateSystem: 'geo',
            showEffectOn: 'render',
            zlevel: 1,
            rippleEffect: {
              period: 15,
              scale: 2.5,
              brushType: 'stroke',
            },
            itemStyle: {
              normal: {
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: 'rgba(72, 173, 220, 1)', // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: 'rgba(0, 241, 215, 1)', // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
              },
            },
            hoverAnimation: false,
            // label: {
            //   normal: {
            //     position: 'top',
            //     offset: [0, -10],
            //     color: '#1DE9B6',
            //     show: true,
            //     formatter: function (params) {
            //       console.log(params);
            //       var html = '';
            //       var info1 = params.data.info;
            //       var info2 = params.data.info2;
            //       if (info1) {
            //         html += '<div>发送' + info1 + '</div>';
            //       } else if (info2) {
            //         html += '<div>接收' + info2 + '</div>';
            //       }
            //       return html;
            //     },
            //   },
            // },
            itemStyle: {
              normal: {
                color: '#1DE9B6',
                /* function (value){ //随机颜色
                               return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6);
                               }*/
                shadowBlur: 10,
                shadowColor: '#333',
              },
            },
            symbolSize: 8,
            data: [
              { value: [125.774678, 44.389735], info: 10, info2: 8 },
              { value: [126.57, 43.87], info: 7 },
            ],
            // data: data[1], //points,
          },
          //地图线的动画效果
          {
            type: 'lines',
            zlevel: 2,
            effect: {
              show: true,
              period: 4, //箭头指向速度,值越小速度越快
              trailLength: 0.4, //特效尾迹长度[0,1]值越大,尾迹越长重
              symbol: 'pin', //箭头图标
              symbolSize: 8, //图标大小
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(72, 173, 220, 1)', // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: 'rgba(0, 241, 215, 1)', // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
            lineStyle: {
              normal: {
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: 'rgba(72, 173, 220, 1)', // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: 'rgba(0, 241, 215, 1)', // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
                width: 1, //线条宽度
                opacity: 0.1, //尾迹线条透明度
                curveness: 0.4, //尾迹线条曲直度
              },
            },
            // data: data[2],
            data: [
              {
                coords: [
                  [125.774678, 44.389735],
                  [126.57, 43.87], //右上
                ],
              },
              {
                coords: [
                  [116.4551, 40.2539],
                  [143.4543, 18.9222], //右下
                ],
              },
              {
                coords: [
                  [113.12244, 23.009505],
                  [60.4543, 25.9222], //左下
                ],
              },
            ],
          },
          // 对话框的绘制 发出
          {
            type: 'effectScatter',
            coordinateSystem: 'geo',
            showEffectOn: 'render',
            // zlevel: 1,
            rippleEffect: {
              period: 0,
              scale: 0,
              brushType: 'stroke',
              opacity: 0,
            },
            zlevel: 10,
            // opacity: 0,
            hoverAnimation: false,
            symbolSize: 0.000001,
            data: labelData1,
            // data: data[1], //points,
          },
        ],
      };
      myChart.setOption(option, true);
      return myChart;
    };

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值