百度地图开发自定义信息窗口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 !

相关文章
|
3月前
|
定位技术 开发者
百度地图开发 —— 获取百度地图开发的 AK
百度地图开发 —— 获取百度地图开发的 AK
199 3
|
3月前
|
JavaScript 定位技术
vue-baidu-map 绘制行政区划的轮廓,添加行政区划名称(含给覆盖物添加点击事件)——vue 百度地图开发
vue-baidu-map 绘制行政区划的轮廓,添加行政区划名称(含给覆盖物添加点击事件)——vue 百度地图开发
169 1
|
3月前
|
JavaScript 定位技术
vue 百度地图开发【教程】3. 自定义百度地图主题
vue 百度地图开发【教程】3. 自定义百度地图主题
104 0
|
3月前
|
JavaScript 定位技术
vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)
vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)
243 0
|
5月前
|
Android开发
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
|
5月前
|
存储 Kubernetes 容器
百度搜索:蓝易云【Kubernetes使用helm部署NFS Provisioner】
现在,你已经成功使用Helm部署了NFS Provisioner,并且可以在Kubernetes中创建使用NFS存储的PersistentVolumeClaim。
193 10
|
5月前
百度搜索:蓝易云【什么是HTTP长轮询?】
现在,HTTP长轮询逐渐被WebSocket等更高效的实时通信技术所替代,但了解HTTP长轮询仍然有助于理解实时数据推送的基本原理。
118 9
|
5月前
|
移动开发 Shell Linux
百度搜索:蓝易云【Shell错误:/bin/bash^M: bad interpreter: No such file or directory】
将 `your_script.sh`替换为你的脚本文件名。运行此命令后,脚本文件的换行符将被转换为Linux格式,然后就可以在Linux系统上正常执行脚本了。
67 8
|
5月前
百度搜索:蓝易云【ipmitool配置BMC的ip】
以上操作将配置BMC的IP地址为新的值。请注意,操作BMC需要谨慎,确保你对服务器有足够的权限,并且仔细检查新的IP地址、子网掩码和默认网关,以免导致服务器网络失联。
82 7
|
5月前
|
Kubernetes 应用服务中间件 nginx
百度搜索:蓝易云【使用Kubernetes部署Nginx应用教程】
现在,你已经成功在Kubernetes集群上部署了Nginx应用。通过访问Service的外部IP地址,你可以访问Nginx服务。
78 4
下一篇
无影云桌面