首页 > 代码库 > 百度地图动态插入标注
百度地图动态插入标注
1.点击地图上面的红旗图片后,在地图上面点击动态添加标注
<div
style="position:absolute;top:7px; right:450px; z-index:20;cursor:pointer;background:#cccccc;border:1px solid #ffffff;width:60px;height:30px;text-align:center;">
<img class="mypig" imgVal="1" src=http://www.mamicode.com/‘../images/flag.png‘ />
</div>
2.
$(‘.mypig‘).live(
"click",
function(even) {
window.clickPointer = "tuodong";
drawingManager.close();
var str = $(this).attr("imgVal");
map.addEventListener("click", function(e) {
if (str == 1) {
var point = new BMap.Point(e.point.lng, e.point.lat);
var myIcon = new BMap.Icon("../images/flag.png",
new BMap.Size(38, 47));
var marker = new BMap.Marker(point, {
icon : myIcon
}); // 创建标注
marker.disableMassClear();
map.addOverlay(marker);
}
str = 0;
});
});
百度地图动态插入标注