百度地图 api for javascript 遮蔽物的心得

      关于在地图上遮挡物组合使用所产生的问题:marker label Circle组合使用。在做一展示效果时 ,使用Circle Polygon时需要给上面添加文字label后,如果说给Circle Polygon添加一系列事件,由于 label的zIndex等级比Circle Polygon要高,在我这边调试发现 在500 而circle是201,此时要触发Circle Polygon事件 会优先点到label 这样达不到预期效果。

   var label = new BMap.Label(result[m].attr.cosmfid, opts);  // 创建文本标注对象
  label.setStyle({
color : "blcak",
    backgroundColor:'transparent',//文本背景色
    borderColor:'transparent',//文本框边框色
    fontSize : "5px",
    height : "20px",
    lineHeight : "20px",
    fontFamily:"微软雅黑"
});
   this.g_map.addOverlay(label);
   var opts2 = {
position : point,    // 指定文本标注所在的地理位置
offset   : new BMap.Size(-20, 0)    //设置文本偏移量
   }
   var label2 = new BMap.Label(resultt[m]+"个", opts2);  // 创建文本标注对象
   label2.setStyle({
color : "blcak",
    backgroundColor:'transparent',//文本背景色
    borderColor:'transparent',//文本框边框色
    fontSize : "5px",
    height : "20px",
    lineHeight : "20px",
    fontFamily:"微软雅黑"
   });
   this.g_map.addOverlay(label2);
   //将label层级设置 为200低于 circle 保证文字在圆上且不会被选中
   this.g_map.getPanes().labelPane.style.zIndex=200;
   var circle = new BMap.Circle(point, 800, {
            strokeColor: "blue",
            strokeWeight: 1,
            fillColor: "blue",
            fillOpacity: 0.5
   });

  this.g_map.addOverlay(circle);

      最终解决方案是通过map的getPanes().labelPane获取到label的Zindex 将值改到200比mapPane的Zindex 值小 这样在点击等事件触发时就不会被文字多阻挡。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值