You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
6.8 KiB
JavaScript

//校园里百度地图
var TT_API_KEY = "bsyeCEEdtDb5Z7dBSAFEPYVS7AETsO9z";
var TT_SECRET_KEY = "aSqjktpzBZrR9aC65uQSXKumsMQgkEGq";
var MAP_DIV = "container";
var MapIcon = [];
var BDMap = null;
var MarkList = {};
var MapFence = {};
var MapTarget = {};
var MapRadar = {};
var MapDevice = {};
var MapObject = {};
var MapType = "";
var MapCallBack = "";
function initialize() {
BDMap = new BMapGL.Map(MAP_DIV);
BDMap.centerAndZoom(new BMapGL.Point(p.MapCenter[0], p.MapCenter[1]), 12);
BDMap.enableScrollWheelZoom(true);
MapIcon = {
arrow_b: new BMapGL.Icon(webHome + "/common/images/arrow/arrow_b.png", new BMapGL.Size(21, 21))
, arrow_y: new BMapGL.Icon(webHome + "/common/images/arrow/arrow_y.png", new BMapGL.Size(21, 21))
, arrow_b2: new BMapGL.Icon(webHome + "/common/images/arrow/arrow_b2.png", new BMapGL.Size(21, 21))
, arrow_g: new BMapGL.Icon(webHome + "/common/images/arrow/arrow_g.png", new BMapGL.Size(21, 21))
, point01: new BMapGL.Icon(webHome + "/common/images/point/point01.png", new BMapGL.Size(30, 30))
, point02: new BMapGL.Icon(webHome + "/common/images/point/point02.png", new BMapGL.Size(30, 30))
, point03: new BMapGL.Icon(webHome + "/common/images/point/point03.png", new BMapGL.Size(30, 30))
, people01: new BMapGL.Icon(webHome + "/common/images/point/p01.png", new BMapGL.Size(30, 30))
, ship01: new BMapGL.Icon(webHome + "/common/images/point/ship_b.png", new BMapGL.Size(30, 30))
, ship02: new BMapGL.Icon(webHome + "/common/images/arrow/arrow01.png", new BMapGL.Size(30, 30))
};
if (MapCallBack != "") {
eval(MapCallBack + "()");
}
//
// addOverlay("one", new BMapGL.Point(112.96, 29.20), function () {
// alert("one");
// });
// addCircle("four", new BMapGL.Point(112.96, 29.20), 15000, function () {
// alert("four");
// });
// addCircle("five", new BMapGL.Point(112.91, 29.361), 8000);
// addTarget("three", new BMapGL.Point(112.91, 29.361), "2", function () {
// openTT("three");
// });
// addObject("o_021", new BMapGL.Point(112.960, 29.220), MapIcon.arrow_b, 80, function () {
// //alert("o_021");
//
// });
// addObject("o_0231", new BMapGL.Point(112.960, 29.210), MapIcon[2], 0, function () {
// alert("o_0231");
// });
// addObject("o_0231", new BMapGL.Point(112.950, 29.210), MapIcon[0], 0, function () {
// alert("o_0231");
// });
}
function changeMapType() {
$("#b_gtype").removeClass("icon-globe icon-th");
if (MapType == "") {
MapType = "1";
BDMap.setMapType(BMAP_EARTH_MAP);
$("#b_gtype").html(" 电子地图");
$("#b_gtype").addClass("icon-th");
} else {
MapType = "";
BDMap.setMapType(BMAP_NORMAL_MAP);
$("#b_gtype").html(" 卫星地图");
$("#b_gtype").addClass("icon-globe");
}
}
function BDMap_loadScript(_callback) {
MapCallBack = _callback != null ? _callback : "initialize";
let script = document.createElement("script");
script.src = "https://api.map.baidu.com/api?type=webgl&v=1.0&ak=" + TT_API_KEY + "&callback=initialize";
document.body.appendChild(script);
}
function toMapCenter(_zoom) {
if (p.MapCenter != null && p.MapCenter.length == 2) {
BDMap.panTo(new BMapGL.Point(p.MapCenter[0], p.MapCenter[1]));
}
setTimeout(function () {
BDMap.setZoom(_zoom != null && _zoom != "" ? _zoom : 13);
}, 1000);
}
//标注
function addOverlay(_id, _point, _fun) {
let _oneMark = new BMapGL.Marker(_point);
MarkList["l_" + _id] = _oneMark;
BDMap.addOverlay(_oneMark);
if (_fun != null) {
_oneMark.addEventListener("click", function () {
alert("点击一个点");
});
}
}
//塔台标注
function addDevice(_id, _point, _img, _html, _angle, _fun) {
let _labelbg = new BMapGL.Marker(_point, {
icon: _img
})
BDMap.addOverlay(_labelbg);
if (_angle != null) {
_labelbg.setRotation(_angle);
}
let opts = {
position: _point, // 指定文本标注所在的地理位置
offset: new BMapGL.Size(-20, -20) // 设置文本偏移量
};
// 创建文本标注对象
let _label = new BMapGL.Label(_html, opts);
_label.setStyle({
color: 'white',
borderRadius: '50%',
borderColor: 'blue',
backgroundColor: '0',
padding: '0px 15px',
fontSize: '16px',
width: '40px',
height: '40px',
lineHeight: '40px',
fontFamily: '微软雅黑'
});
BDMap.addOverlay(_label);
if (_fun != null) {
_labelbg.addEventListener("click", function () {
_fun();
});
}
MarkList["d_" + _id] = _label;
MapDevice[_id] = _label;
}
function addTarget(_id, _point, _img, _angle, _clickfun, _moveFun) {
// 创建文本标注对象
let _obj = new BMapGL.Marker(_point, {
icon: _img
});
BDMap.addOverlay(_obj);
if (_angle != null) {
_obj.setRotation(_angle);
}
if (_clickfun != null) {
_obj.addEventListener("click", function () {
_clickfun();
});
}
if (_moveFun != null) {
_obj.addEventListener("mouseover", function () {
_moveFun();
});
}
MarkList["t_" + _id] = _obj;
MapTarget[_id] = _obj;
}
//添加雷达范围
function addCircle(_id, _point, _bj, _fun) {
let _circle = new BMapGL.Circle(_point, _bj, {
strokeColor: '#6495ED',
strokeWeight: 1,
strokeOpacity: 0.2
});
//BDMap.addOverlay(_circle);
MarkList["c_" + _id] = _circle;
MapRadar[_id] = _circle;
if (_fun != null) {
_circle.addEventListener("click", function () {
_fun();
});
}
}
//雷达范围
function showRadar() {
$.each(MapRadar, function (key, value) {
BDMap.removeOverlay(value);
});
if ($("#t_radar").is(':checked')) {
$.each(MapRadar, function (key, value) {
BDMap.addOverlay(value);
});
}
}
function showFance() {
$.each(MapFence, function (key, value) {
BDMap.removeOverlay(value);
});
if ($("#t_fance").is(':checked')) {
$.each(MapFence, function (key, value) {
BDMap.addOverlay(value);
});
}
}
function showTarget(_id) {
_id = (_id != null && _id != "") ? _id : "t_target";
$.each(MapTarget, function (key, value) {
if (value != null) {
BDMap.removeOverlay(value);
}
});
if ($("#" + _id).is(':checked')) {
$.each(MapTarget, function (key, value) {
if (value != null) {
BDMap.addOverlay(value);
}
});
}
}
//设置多边形可编辑
function setPolygonEditFlg(_flg, _polygon) {
if (_flg) {
_polygon.enableEditing();
} else {
_polygon.disableEditing();
}
}