为了解决 label太多,文字会重叠看不清 所以提出这种办法
核心代码
1,创建的时候 将label设置为隐藏
2,通过百度地图监听事件 , mouseover或onmouseover 触发显示
3,通过mouseover 或onmouseover 触发隐藏
// 创建文本标注对象 var label = new BMap.Label(" "+data.data[i][4]+" ", { offset: new BMap.Size(10, -25) }); label.setStyle({ color: "#fff", border: "0", padding: "0", display: "none", background: "rgba(66,117,202,0.9)", fontSize: "12px", height: "20px", lineHeight: "20px", fontFamily: "微软雅黑" }); marker.setLabel(label); marker.addEventListener("mouseover",function(e){ var label = this.getLabel() label.setStyle({display:"block"}); }); marker.addEventListener("mouseout",function(e){ var label = this.getLabel() label.setStyle({display:"none"}); }); map.addOverlay(marker); //将标记添加到地图中