百度地图开发自定义信息窗口openInfoWindow样式的解决方案

简介: 百度地图开发自定义信息窗口openInfoWindow样式的解决方案


1.InfoWindow的样式,百度是没用提供直接使用的样式表的,目前都是热心网友在实际开发中自己的经验和实战总结;

2.百度提供了InfoBox富文本标签弹出框的接口,引入InfoBox.js,即可自定义样式或丰富的边框功能,但是鼠标单击下一个标注时,已经弹出的模态框是无法自动关闭;InfoWindow单击事件则是会即时展示现在单击的弹出模态框。

3.InfoBox的样式表要理解,必须理解的组成部分;

4.实现原理,就是CSS优先级和权重问题以及!important优先级;


/*地图标题 infoWindow*/
.BMap_bubble_title {
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    text-align: left;
    background: transparent !important;
}
.BMap_pop .BMap_top {
    background: rgba(0, 0, 0, .8) !important;
    border: 0 !important;
}
.BMap_pop .BMap_center {
    width: 281px !important;
    border: 0 !important;
    background: rgba(0, 0, 0, .8) !important;
}
.BMap_pop .BMap_bottom {
    border: 0 !important;
    background: rgba(0, 0, 0, .8) !important;
}
.BMap_pop div:nth-child(3) {
    background: transparent !important;
}
.BMap_pop div:nth-child(3) div {
    border-radius: 3px;
    background: rgba(0, 0, 0, .8) !important;
    border: 0 !important;
}
.BMap_pop div:nth-child(1) {
    border-radius: 3px 0 0 0;
    background: transparent !important;
    border: 0 !important;
}
.BMap_pop div:nth-child(1) div {
    background: rgba(0, 0, 0, .8) !important;
}
.BMap_pop div:nth-child(5) {
    border-radius: 0 0 0 3px;
    background: transparent !important;
    border: 0 !important;
}
.BMap_pop div:nth-child(5) div {
    border-radius: 3px;
    background: rgba(0, 0, 0, .8) !important;
}
.BMap_pop div:nth-child(7) {
    background: transparent !important;
    left: 226px;
}
.BMap_pop div:nth-child(7) div {
    border-radius: 3px;
    background: rgba(0, 0, 0, .8) !important;
}
/*替换箭头*/
img[src="http://api0.map.bdimg.com/images/iw3.png"] {
    content: url('../images/iw3.png');
}
img[src="https://api.map.baidu.com/images/iw3.png"] {
    opacity: 0.7;
    margin-top: -692px !important;
    filter: alpha(opacity=70);
    content: url('../images/iw3.png');
}


//添加信息窗口
function addInfoWindow(marker, pos) {
    var title = '<div class="popTitle" style="background:transparent !important;">' + pos.poi_name + '</div>';
    var html = [];
    html.push('<div>');
    html.push('<div class="infoItems" style="background:transparent !important;"><span>所属组织:</span><span>' + pos.poi_address + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>经度:</span><span>' + pos.poi_lon + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>纬度:</span><span>' + pos.poi_lat + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>IP地址:</span><span>' + pos.poi_ip + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>摄像机类型:</span><span>' + pos.poi_type + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>安装方式:</span><span>' + pos.poi_install + '</span></div>')
    html.push('<div class="infoItems" style="background:transparent !important;"><span>备注:</span><span>' + pos.poi_content + '</span></div>')
    html.push('</div>');
    var opts = {
        width: 250, // 信息窗口宽度
        height: 210, // 信息窗口高度
        title: '<h4>' + title + '</h4>', // 信息窗口标题
        enableMessage: true, //设置允许信息窗发送短息
    }
    var infoWindow = new BMap.InfoWindow(html.join(""), opts);
    var openInfoWinFun = function () {
        marker.openInfoWindow(infoWindow);
    };
    marker.addEventListener("click", openInfoWinFun);
    return openInfoWinFun;
}


lockdatav Done !

相关文章
|
1月前
|
Linux
|
1月前
|
开发工具 git 开发者
百度搜索:蓝易云【Git实际开发的流程】
以上是Git在实际开发中的一般流程。Git的分布式版本控制系统使得团队开发更加高效和灵活,并能有效管理项目的版本历史。
39 1
|
1月前
|
Android开发
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
|
1月前
|
容器
百度富文本上传图片后样式崩塌
百度富文本上传图片后样式崩塌
42 0
百度富文本上传图片后样式崩塌
|
1月前
|
Linux
百度搜索:蓝易云【Linux系统下获取系统、BIOS、进程、网络等相关信息的方法和工具。】
综上所述,通过使用命令行工具和图形化工具,可以在Linux系统下获取系统、BIOS、进程和网络等相关信息。根据具体的需求和使用场景,选择合适的工具和命令可以帮助你更好地了解和管理Linux系统。
72 2
|
1月前
|
Linux
百度搜索:蓝易云【Linux系统中查看硬盘信息的方法有哪些?】
这些是在Linux系统中查看硬盘信息的常见方法。根据您的需求和具体环境,您可以选择适合您的方法来查看硬盘信息。
85 0
|
1月前
|
缓存 Linux
百度搜索:蓝易云【Linux系统中查看CPU信息的方法有哪些?】
这些是在Linux系统中查看CPU信息的常见方法。根据您的需求和具体环境,您可以选择适合您的方法来查看CPU信息。
65 0
|
1月前
|
缓存 Linux
百度搜索:蓝易云【Linux系统中查看内存信息的方法有哪些?】
这些是在Linux系统中查看内存信息的常见方法。根据您的需求和具体环境,您可以选择适合您的方法来查看内存信息。
87 0
|
1月前
|
存储 Kubernetes 容器
百度搜索:蓝易云【Kubernetes使用helm部署NFS Provisioner】
现在,你已经成功使用Helm部署了NFS Provisioner,并且可以在Kubernetes中创建使用NFS存储的PersistentVolumeClaim。
159 10
|
1月前
百度搜索:蓝易云【什么是HTTP长轮询?】
现在,HTTP长轮询逐渐被WebSocket等更高效的实时通信技术所替代,但了解HTTP长轮询仍然有助于理解实时数据推送的基本原理。
95 9