百度地图开发自定义信息窗口openInfoWindow样式修改

2024-11-28前端开发
212


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="/imgups/allimg/2411/15225C616-0.png"] {
    content: url('../images/iw3.png');
}

img[src="/imgups/allimg/2411/15225A5V-1.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;
}
 
The End
百度地图 openInfoWindow

相关推荐

网站部署https后百度地图不显示问题
https的网站如果引用百度地图,会出现加载不了的问题,这是因为涉及到跨域问题,网站是https的,但是引用百度地图的是http的,这个要怎么操作呢? 比如我引用的地址:http://api.map.baidu.com/api?v=2.0ak=AK显示 后来看了一下,少了一个s=1字段,加一下s=1...
2025-07-28 前端开发
139

百度地图调用点聚合和弹窗事件
什么是点聚合 点聚合 (MarkerClusterer 标记聚合器)用来解决加载大量点要素到地图上产生覆盖现象的问题,并提高性能。显示效果如下图: 简单实例 HTML \ CSS style body, html {width: 100%;height: 100%;margin: 0;font-family: "微软雅黑";} #allmap {wi...
2025-01-09 前端开发
179

百度地图开发自定义信息窗口openInfoWindow样式修改
1.InfoWindow的样式,百度是没用提供直接使用的样式表的,目前都是热心网友在实际开发中自己的经验和实战总结; 2.百度提供了InfoBox富文本标签弹出框的接口,引入InfoBox.js,即可自定义样式或丰富的边框功能,但是鼠标单击下一个标注时,已经弹出的模态框...
2024-11-28 前端开发
212

百度地图API调用如何让标注内容自动呈现在最佳视野内
我有一堆标注,不规则的散落在地图的各个地方,我想把它们展示在一个最佳视野中,要怎么操作呢?我们在百度地图API的类参考里,找到这个一个类,setViewport 。可以让一系列的标注,在地图上呈现最佳视野。具体操作如下: 一、创建地图 建立一个htm文件,把基...
2024-10-10 前端开发
162