高德地图点位聚合

高德地图 版本2.0

// map地图实例  markerList点位数组 包含lnglat(数组形式),extData(点位相关信息)属性
this.map.plugin(['AMap.MarkerClusterer'], () => { // 异步加载插件
        this.cluster = new this.AMap.MarkerClusterer(this.map, this.markerList,
          {
            renderMarker: this.renderMarker, // 自定义非聚合点样式
            renderClusterMarker: this.renderClusterMarker, // 聚合点位样式
          });
      });


renderMarker(context) {
      const zoom = this.map.getZoom();
      const { extData } = context.data[0];
		// 图标获取
      const { icon } = colorList[extData.info - 1];
      context.marker.setIcon(icon);
      context.marker.setOffset(new this.AMap.Pixel(-5, -5));
      context.marker.on('click', () => {
        this.setLabels(extData);
      });
      if (zoom >= 17) {
        context.marker.setLabel({
          content:
                                            `<div style="height: 20px;
                          background: #fff;
                          padding: 0px 10px;
                          border-radius: 7px;
                          color: #337ded;
                          line-height: 20px;
                          box-shadow: 0 5px 8px #9f9f9fad;">${
  extData.name
}</div><i class='tri'></i>`, // 设置文本标注内容
          direction: 'top', // 设置文本标注方位
        });
      } else {
        context.marker.setLabel({
          content: '<div></div>',
          direction: 'top', // 设置文本标注方位
        });
      }
    },
    renderClusterMarker(context) {
      const content = `<span style="display:inline-block;width: 30px;height:30px;background:#55bd64;
      border-radius:15px;
       border:1px solid #bff0ca;color:#fff;
       line-height:30px;text-align:center;font-size:12px">${context.count}</span>`;
      context.marker.setContent(content);
    },
  },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值