天天看點

百度地圖JavaScript API使用infoBox修改資訊框樣式

百度地圖JavaScript API使用infoBox修改資訊框樣式
window.lastInfoBox = null;//定義上一個窗體為lastInfoBox;
function addClickHandler(content,marker){
	
	marker.addEventListener("click",function(e){
		
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		
		var infoBox = new BMapLib.InfoBox(window.map,content,{
		        boxStyle:{
		            width: "481px",
		            height: "230px",
		            marginBottom: "5px",
		            background:"url(../img/pop.png) center no-repeat "
		        },
		        closeIconMargin: "10px 10px 10px 10px",
		        closeIconUrl: "../img/cancel.png",
		        enableAutoPan: false,
		        align: INFOBOX_AT_TOP,
		    });
			if(lastInfoBox){
			//判斷上一個窗體是否存在,若存在則執行close
		        lastInfoBox.close();
		    }
		    lastInfoBox = infoBox;
		    infoBox.uid = "2";   //辨別 
		    infoBox.enableAutoPan(); //自動偏移
		    infoBox.open(point);

	});
	
}