<div class="demo_main">
<fieldset class="demo_title">百度地图API显示多个标注点带提示的代码</fieldset>
<fieldset class="demo_content">
<div style="min-height: 600px; width: 100%;margin:0,auto;" id="map"></div>
<script type="text/javascript">
var map; //Map实例
function map_init() {
map = new BMap.Map("map");
//第1步:设置地图中心点,安丘
var point = new BMap.Point(119.225605,36.483843);
//第2步:初始化地图,设置中心点坐标和地图级别。
map.centerAndZoom(point, 13);
//第3步:启用滚轮放大缩小
map.enableScrollWheelZoom(true);
//第4步:向地图中添加缩放控件
var ctrlNav = new window.BMap.NavigationControl({
anchor: BMAP_ANCHOR_TOP_LEFT,
type: BMAP_NAVIGATION_CONTROL_LARGE
});
map.addControl(ctrlNav);
//第5步:向地图中添加缩略图控件
var ctrlOve = new window.BMap.OverviewMapControl({
anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
isOpen: 1
});
map.addControl(ctrlOve);
//第6步:向地图中添加比例尺控件
var ctrlSca = new window.BMap.ScaleControl({
anchor: BMAP_ANCHOR_BOTTOM_LEFT
});
map.addControl(ctrlSca);
//第7步:绘制点
var list = '${list}';
console.log(list);
for (var i = 0; i < list.size; i++) {
var lng = list[i].lng;
console.log(lng);
var lat = list[i].lat;
var maker = addMarker(new window.BMap.Point(lng, lat), i);
addInfoWindow(maker, list[i]);
}
}
// 添加标注
function addMarker(point, index) {
var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png",
new BMap.Size(46, 25), {
offset: new BMap.Size(10, 25),
imageOffset: new BMap.Size(23, 0 - index * 25)
});
var marker = new BMap.Marker(point, { icon: myIcon });
map.addOverlay(marker);
return marker;
}
// 添加信息窗口
function addInfoWindow(marker, poi) {
//pop弹窗标题
var title = '<div style="font-weight:bold;color:#CE5521;font-size:14px">' + poi.baseName + '</div>';
//pop弹窗信息
var html = [];
html.push('<table cellspacing="0" style="table-layout:fixed;width:100%;font:12px arial,simsun,sans-serif"><tbody>');
html.push('<tr>');
html.push('<td style="vertical-align:top;line-height:16px;width:38px;white-space:nowrap;word-break:keep-all">企业名称:</td>');
html.push('<td style="vertical-align:top;line-height:16px">' + poi.baseName + ' </td>');
html.push('</tr>');
html.push('<tr>');
html.push('<td style="vertical-align:top;line-height:16px;width:38px;white-space:nowrap;word-break:keep-all">联系人:</td>');
html.push('<td style="vertical-align:top;line-height:16px">' + poi.contacrName + ' </td>');
html.push('</tr>');
html.push('<tr>');
html.push('<td style="vertical-align:top;line-height:16px;width:38px;white-space:nowrap;word-break:keep-all">联系电话:</td>');
html.push('<td style="vertical-align:top;line-height:16px">' + poi.contactTel + ' </td>');
html.push('</tr>')
html.push('</tbody></table>');
var infoWindow = new BMap.InfoWindow(html.join(""), { title: title, width: 200 });
var openInfoWinFun = function () {
marker.openInfoWindow(infoWindow);
};
marker.addEventListener("click", openInfoWinFun);
return openInfoWinFun;
}
//异步调用百度js
function map_load() {
var load = document.createElement("script");
load.src = "http://api.map.baidu.com/api?v=2.0&callback=map_init";
document.body.appendChild(load);
}
window.onload = map_load;
</script>
</fieldset>
</div>
想要在页面显示所有已经有的地点标注,并且有信息,但是就是实现不了,不知道哪里错了,求助