代码
const map = new BMap.Map('map');
var poi = new BMap.Point(116.307852, 40.057031);
map.centerAndZoom(poi, 16);
var html = [
"<div class='infoBoxContent'><div class='title'><strong>中海雅园</strong><span class='price'>均价43000</span></div>",
"<div class='list'><ul><li><div class='left'><img src='https://lbsyun.baidu.com/jsdemo/img/wucaicheng.jpg'/></div><div class='left'><a target='_blank' href='http://map.baidu.com'>中海雅园南北通透四居室</a><p>4室2厅,205.00平米,3层</p></div><div class='rmb'>760万</div></li>",
"<li><div class='left'><img src='https://lbsyun.baidu.com/jsdemo/img/wucaicheng.jpg'/></div><div class='left'><a target='_blank' href='http://map.baidu.com'>中海雅园四居室还带保姆间</a><p>2室1厅,112.00平米,16层</p></div><div class='rmb'>300万</div></li>",
"<li><div class='left'><img src='https://lbsyun.baidu.com/jsdemo/img/wucaicheng.jpg'/></div><div class='left'><a target='_blank' href='http://map.baidu.com'>《有钥匙 随时看》花园水系</a><p>3室2厅,241.00平米,16层</p></div><div class='rmb'>400万</div></li>",
"<li><div class='left'><img src='https://lbsyun.baidu.com/jsdemo/img/wucaicheng.jpg'/></div><div class='left'><a target='_blank' href='http://map.baidu.com'>富力城D区正规楼王大三居</a><p>3室3厅,241.00平米,17层</p></div><div class='rmb'>600万</div></li>",
"<li class='last'><div class='left'><img src='https://lbsyun.baidu.com/jsdemo/img/wucaicheng.jpg'/></div><div class='left'><a target='_blank' href='http://map.baidu.com'>富力城豪,身份人士的象征</a><p>4室2厅,213.90平米,25层</p></div><div class='rmb'>700万</div></li>",
'</ul></div>',
'</div>',
];
var infoBox = new BMapLib.InfoBox(map, html.join(''), {
boxStyle: {
background: '#6cb2fa',
width: '270px',
height: '300px',
},
closeIconMargin: '1px 1px 0 0',
closeIconUrl: '//mapopen.bj.bcebos.com/github/BMapGLLib/InfoBox/examples/images/close.png',
enableAutoPan: true,
align: INFOBOX_AT_TOP,
});
var marker = new BMap.Marker(poi);
map.addOverlay(marker);
infoBox.open(marker);
marker.enableDragging();
$('close').onclick = function () {
infoBox.close();
};
$('open').onclick = function () {
infoBox.open(marker);
};
$('show').onclick = function () {
infoBox.show();
};
$('hide').onclick = function () {
infoBox.hide();
};
$('enableAutoPan').onclick = function () {
infoBox.enableAutoPan();
};
$('disableAutoPan').onclick = function () {
infoBox.disableAutoPan();
};
function $(id) {
return document.getElementById(id);
}
预览