64 lines
2.6 KiB
JavaScript
64 lines
2.6 KiB
JavaScript
/****************添加地图控件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 = "<div id='content' class='btn-group-vertical' role='group' aria-label='...' >" +
|
||
"<div style='height: 38px;width: 118px;background-color: darkgray;'>" +
|
||
"<input type='checkbox' value='球机' checked='checked'style='position: relative;top: -10px;' onclick='loadLable(0,this);' />" +
|
||
"<img src=" + blueBall + " style='margin-left: 0px;' width='35px' height='35px'/>" +
|
||
"<span style='font-size:14px;color:#0950dc;position: relative;top: -13px;' id='bulbEngine'><strong>球机:0</strong></span>" +
|
||
"</div>" +
|
||
"<div style='height: 38px;width: 118px;background-color: darkgray;margin-top: 2%;'>" +
|
||
"<input type='checkbox' value='安全帽' checked='checked' style='position: relative;top: -10px;' onclick='loadLable(1,this);'/>" +
|
||
"<img src=" + blueHat + " style='margin-left:0px;' width='35px' height='35px'/>" +
|
||
"<span style='font-size:14px;color:#0950dc;position: relative;top: -13px;' id='safetyHelmet'><strong>安全帽:0</strong></span>" +
|
||
"</div>" +
|
||
"</div>";
|
||
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]) // 移除覆盖物
|
||
}
|
||
}
|
||
}
|
||
}
|