天天看点

修改背景地图样式_百度地图实现自定义InfoWindow的样式

修改背景地图样式_百度地图实现自定义InfoWindow的样式

此修改方式已废弃,如有需要,请看新版: 戳我

百度地图提供的InfoWindow,样式问题是不是很纠结。。最近在学习vue+百度地图,遇到infowindow,发现没有提供相应的样式设置方法,四个直角+很重的外边框看着很别扭。

百度谷歌无果之后,自己从地图中一层一层的扒,写了一些css替换原有的样式,简单的实现了圆角、自定义背景等效果。demo地址:点我。

.BMap_cpyCtrl{display:none !important;}
.anchorBL a img{display:none !important;}

/*地图标题 infoWindow*/  
.BMap_bubble_title{  
    color:#fff;  
    font-size:14px;  
    font-weight: bold;  
    text-align:left; 
    background:transparent !important; 
}  

.BMap_pop .BMap_top{
    background:rgba(48,65,86,.8) !important; 
    border:0 !important;
}
.BMap_pop .BMap_center{
    width: 281px !important;
    border:0 !important;
    background:rgba(48,65,86,.8) !important; 
}
.BMap_pop .BMap_bottom{
    border:0 !important;
    background:rgba(48,65,86,.8) !important; 
}
.BMap_pop div:nth-child(3){
    background:transparent !important; 
}
.BMap_pop div:nth-child(3) div{  
    border-radius:7px;  
    background:rgba(48,65,86,.8) !important; 
    border:0 !important;
} 
.BMap_pop div:nth-child(1){  
    border-radius:7px 0 0 0;  
    background:transparent !important; 
    border:0 !important;
}  
.BMap_pop div:nth-child(1) div{
    background:rgba(48,65,86,.8) !important; 
}
.BMap_pop div:nth-child(5){  
    border-radius:0 0 0 7px;  
    background:transparent !important; 
    border:0 !important;
}  
.BMap_pop div:nth-child(5) div{  
    border-radius:7px;  
    background:rgba(48,65,86,.8) !important; 
}  
.BMap_pop div:nth-child(7){  
    background:transparent !important; 
    left: 226px;
}  
.BMap_pop div:nth-child(7) div{  
    border-radius:7px;  
    background:rgba(48,65,86,.8) !important; 
}  
/*替换关闭按钮*/  
img[src="http://api0.map.bdimg.com/images/iw_close1d3.gif"]{
    content: url('http://vino.test.bidostar.cn/iw_close1d3.png');
}
/*替换剪头*/  
img[src="http://api0.map.bdimg.com/images/iw3.png"]{
    opacity:.7;
    margin-top: -692px !important;
    filter:alpha(opacity=70);
    content: url('http://vino.test.bidostar.cn/iw3.png');
}
           

注意:不同的百度地图秘钥,可能会导致上述替换关闭按钮和替换箭头的图片获取失败,找到自己项目地图中的对应地址替换以下就ok了。

地图新手,不喜勿喷,有问题希望能够多多反馈。学习为主。