/****************添加地图控件start********************/ // 定义一个控件类,即function function LableControl() { // 设置默认停靠位置和偏移量 this.defaultAnchor = BMAP_ANCHOR_BOTTOM_RIGHT; this.defaultOffset = new BMap.Size(10, 10); } //通过JavaScript的prototype属性继承于BMap.Control LableControl.prototype = new BMap.Control(); //自定义控件必须实现initialize方法,并且将控件的DOM元素返回 //在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中 LableControl.prototype.initialize = function (map) { //创建一个DOM元素 var div = document.createElement("div"); div.style.marginLeft = "3%"; initControlLable(div); map.getContainer().appendChild(div); return div; } /** * 创建地图控件内容 * @param {Object} div */ function initControlLable(div) { var blueBall = dataUrl + 'img/map/球机蓝.png'; var blueHat = dataUrl + 'img/map/安全帽蓝.png'; var html = "
" + "
" + "" + "" + "球机:0" + "
" + "
" + "" + "" + "安全帽:0" + "
" + "
"; div.innerHTML = html; } /****************添加地图控件end**********************/ function loadLable(type, that) { var isCheck = that.checked; var marks = map.getOverlays(); if (isCheck) {//如果选中 if (type == 0) { getBulbEngine(); // 获取球机 } else if (type == 1) { getSafetyHelmet(); // 获取安全帽 } } else {//未选中 for (var i = 0; i < marks.length; i++) { var markType = marks[i].markerType; if (markType == type) { map.removeOverlay(marks[i]) // 移除覆盖物 } } } }