function bmap(_div ) { return bmap(_div , null , null,false , false,false); } /** * 创建百度地图 * @param _div 地图所处div * @param _centerPoint 地图当前中心点 * @param _mapZoom 当前缩放层级 0-19 * @param _is_hybrid_map 是否卫星图 * @param _overView 是否包含鹰眼图 * @returns 百度地图 Bmap */ function bmap(_div ,_centerPoint , _mapZoom , _is_hybrid_map , _overView , _navigation ) { var map = _is_hybrid_map ? new BMap.Map(_div, {mapType: BMAP_HYBRID_MAP}) : new BMap.Map(_div); // 创建Map实例 if(_centerPoint && _mapZoom) { map.centerAndZoom(_centerPoint, _mapZoom); // 初始化地图,设置中心点坐标和地图级别 } else { var point = new BMap.Point(116.404, 39.915);//, 11 map.centerAndZoom(point, 11); } map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放 if(_navigation) { var top_left_navigation = new BMap.NavigationControl(/*{type:BMAP_NAVIGATION_CONTROL_ZOOM}*/); //左上角,添加默认缩放平移控件 map.addControl(top_left_navigation); // } if(_overView) { var overView = new BMap.OverviewMapControl(); var overViewOpen = new BMap.OverviewMapControl({isOpen:true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT}); map.addControl(overView); //添加默认缩略地图控件 map.addControl(overViewOpen); //右下角,打开 } return map ; } function ComplexCustomOverlay(point ){ this._point = point; } ComplexCustomOverlay.prototype = new BMap.Overlay(); ComplexCustomOverlay.prototype.initialize = function(map){ this._map = map; var div = this._div = document.createElement("div"); div.style.position = "absolute"; var arrow = this._arrow = document.createElement("div"); arrow.style.position = "absolute"; arrow.style.overflow = "hidden"; div.appendChild(arrow); arrow.className="css_animation"; map.getPanes().labelPane.appendChild(div); return div; } ComplexCustomOverlay.prototype.draw = function(){ var map = this._map; var pixel = map.pointToOverlayPixel(this._point); this._div.style.left = pixel.x - 25 + "px"; this._div.style.top = pixel.y - 25 + "px"; } ComplexCustomOverlay.prototype.setPosition = function(point) { this._point = point ; } /** * 添加一个闪烁点 * @param lon * @param lat * @returns */ function addComplexOverlay(map , point , iconUrl , id , info) { if(!id) { id = -1; } var c = new ComplexCustomOverlay(point); c.id = id ; cs.push(c); map.addOverlay(c); var m = new BMap.Marker(point ); // 创建标注 m.id = id; ms.push(m); if(info) { var label = new BMap.Label(info ); // 创建文本标注对象 //label.setStyle({ color : "white", fontSize : "14px" }); m.setLabel(label); } if(iconUrl) { var size = new BMap.Size(36,36); var icon = new BMap.Icon( iconUrl , size , {imageOffset: new BMap.Size(0, 0)} ); m.setIcon(icon); } map.addOverlay(m); // 将标注添加到地图中 } var ms = [] ; var cs = [] ; /** * 添加一个闪烁点 * @param lon * @param lat * @returns */ function mergeComplexOverlay(map , point , iconUrl , id , info) { var m , c ; if(!id) { id = -1; } for(var i = 0 ; i < ms.length ; i++) { if(ms[i].id = id){ m = ms[i]; c = cs[i]; break ; } } if(m && c) { //已存在,修改经纬度 //var point = new BMap.Point(lon , lat); m.setPosition(point); c.setPosition(point); c. draw(); } else { //不存在重新绘制 addComplexOverlay(map ,point , iconUrl , id , info); } } function removeComplexOverlay(id) { var m , c ; if(!id) { id = -1; } for(var i = 0 ; i < ms.length ; i++) { if(ms[i].id = id){ m = ms[i]; c = cs[i]; ms.splice(i,1); cs.splice(i,1); break; } } if(m) map.removeOverlay(m); if(c) map.removeOverlay(c); m = null; c = null; } var cls = []; /** * 地图画一个圆圈 * @param center_point 中心点 point * @param radius 半径 单位为米 * @returns */ function addCircle( center_point , radius ,id) { if(!id) { id = -1; } removeCircle(id); var c = new BMap.Circle(center_point , radius); c.id = id; map.addOverlay(c); cls.push(c); } function removeCircle(id) { if(!id) { id = -1; } var c ; for(var i = 0 ; i < cls.length ; i++) { if(cls[i].id = id){ c = cls[i]; cls.splice(i,1); break; } } if(c) { map.removeOverlay(c); } } function formatDistance(distance) { var str = '' ; if(distance > 1000) { str = (distance / 1000).toFixed(1) + '千米'; } else { str = distance.toFixed(1) + '米'; } return str ; } function createInfoMarker(point , iconUrl , info) { var m = new BMap.Marker(point ); // 创建标注 if(info) { var label = new BMap.Label(info ,{ offset: new BMap.Size(20, -20) }); // 创建文本标注对象 label.setStyle({ color : "#000", fontSize : "14px" }); m.setLabel(label); } if(iconUrl) { console.log('iconUrl ' + iconUrl); var size = new BMap.Size(36,36); var icon = new BMap.Icon( iconUrl , size , {imageOffset: new BMap.Size(0, 0)} ); m.setIcon(icon); } return m ; } /** * 拼接设备信息 * @param equi */ function createEquiInfo(equi) { var iconUrl = equi.icon && equi.icon != '' && equi.icon.length > 2 ? equi.icon : ctx + '/comm/img/equi/1' + equi.icon ; var str = '
| 设备名称: | '+ '' + equi.equi_name + ' | '+ '
| 布设位置: | '+ '' + (equi.location ? equi.location : '') + ' | '+ '
| 经纬度: | '+ '' + equi.lon + "," + equi.lat + ' | '+ '
| 设备状态: | '+ '正在防护 | '+ '
| 设备图片: | '+ ' | '+
'
| 设备介绍: | '+ '' + equi.equi_description + ' | '+ '
| 技术指标: | '+ ''+ ' |