原文:https://blog.csdn.net/jiangshi0/article/details/84618569

 

 

1.百度地图标注点上,去掉的背景色

百度地图API开发之. 添加文字标签 Lable:去掉的背景色

/*标签*/
function createLable(map, point, content) {
    var opts = {
        position: point,
        offset: new BMap.Size(-5, 10)
    }
    var label = new BMap.Label(content, opts);
    label.setStyle({
        color: "#000",
        border: "0px",
        backgroundColor: "0.000000000001", //通过这个方法,去掉背景色
        fontSize: "12px",
        height: "20px",
        lineHeight: "20px"
    });
    map.addOverlay(label);
    return label;
}

 

2.百度地图标注点上添加数字

var points = [
    { "lng": 116, "lat": 40, "data": "5" },
    { "lng": 117, "lat": 31, "data": "9" },
    { "lng": 116, "lat": 34, "data": "7" }
];

function addMarker(points) {  // 创建图标对象     

    // 创建标注对象并添加到地图     
    for (var i = 0, pointsLen = points.length; i < pointsLen; i++) {
        var point = new BMap.Point(points[i].lng, points[i].lat);
        var marker = new BMap.Marker(point);
        var label = new BMap.Label(points[i].data, {
            offset: new BMap.Size(5, 4)
        });
        label.setStyle({
            background: \'none\', color: \'#fff\', border: \'none\'//只要对label样式进行设置就可达到在标注图标上显示数字的效果
        });
        marker.setLabel(label);//显示地理名称 a 
        map.addOverlay(marker);
        //给标注点添加点击事件。使用立即执行函数和闭包  
        (function () {
            var thePoint = points[i];
            marker.addEventListener("click", function () {
                showInfo(this, thePoint);
            });
        })();

    }

}

 

版权声明:本文为chenghu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/chenghu/p/14842443.html