//默认公司位置置--113.550545,34.798932
|
var locations = [{longitude:"113.550545",latitude:"34.798932",name:"某演示粮库"}];
|
var tsn = locationArray;
|
//定义标记点数组
|
var markers = Array();
|
//定义点数组
|
var points = Array();
|
//定义下标数组
|
var indexs = Array();
|
//创建标记文本标注数组
|
var labels = Array();
|
var map = new BMapGL.Map("container");
|
var timer;
|
var layer;
|
|
$(function() {
|
layui.use([ 'layer', 'laydate', 'form' ], function() {
|
layer = layui.layer;
|
});
|
|
//旋转动画
|
rotate();
|
|
//初次定位到库区位置
|
setTimeout('firstSetCenter(locations)', 6000);
|
|
//再定位到设备位置
|
setTimeout('setCenterAndLocation(tsn)', 13000);
|
|
//定时请求位置信息并实时定位
|
timing();
|
});
|
|
//定位库区位置
|
function firstSetCenter(data) {
|
//适应地图大小,设置地图中心点坐标及地图级别
|
var defaultPoint = data[0];
|
map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 18);
|
|
//标记位置
|
markPosition(data);
|
//位置信息显示
|
showInfo(data);
|
}
|
|
//定位设备位置
|
function setCenterAndLocation(data) {
|
if(data.length==0){
|
layer.alert("暂无设备位置信息!");
|
return;
|
}
|
//适应地图大小,设置地图中心点坐标及地图级别
|
var defaultPoint = data[0];
|
map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 14);
|
markPosition(data);
|
showInfo(data);
|
}
|
|
//定时每5分钟定时请求位置
|
function timing() {
|
timer = setInterval(function() {
|
changeMarkerPosition();
|
}, 300000);
|
}
|
|
//请求后台获取最新位置信息
|
function getCurrentLocation() {
|
$.ajax({
|
type : "POST",
|
url : "../../basic/oa/quaryLocation",
|
contentType : "application/json;charset=UTF-8",
|
success : function(data) {
|
tsn = null;
|
tsn = data;
|
},
|
error : function(error) {
|
console.log("获取位置失败!");
|
}
|
});
|
}
|
|
//获取最新位置后进行定位
|
function changeMarkerPosition () {
|
|
//到后台请求最新的位置信息
|
getCurrentLocation();
|
|
//清除所有的覆盖物标识
|
map.clearOverlays();
|
|
if(tsn.length==0){
|
layer.alert("暂无设备位置信息,定位到粮库位置!");
|
firstSetCenter(locations);
|
return;
|
}
|
//适应地图大小,设置地图中心点坐标及地图级别
|
var defaultPoint = tsn[0];
|
map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 14);
|
markPosition(tsn);
|
showInfo(tsn);
|
}
|
|
//根据坐标标记位置
|
function markPosition(data) {
|
var sContent;
|
for (var i = 0; i < data.length; i++) {
|
// 根据数据设定点
|
points[i] = new BMapGL.Point(data[i].longitude, data[i].latitude);
|
// 自定义标注图片
|
var myIcon = new BMapGL.Icon( '../../static/images/icon_gcoding.png', new BMapGL.Size(25, 35));
|
// 创建标注
|
markers[i] = new BMapGL.Marker(points[i], {icon : myIcon});
|
// 将标注添加到地图中
|
map.addOverlay(markers[i]);
|
indexs[i] = i
|
}
|
}
|
|
function showInfo(data) {
|
// 对标记数组添加事件
|
markers.map(function(value, index) {
|
// 设定点以定位文本标注位置
|
var point = new BMapGL.Point(data[index].longitude,
|
data[index].latitude);
|
|
var opts = {
|
position : point, // 指定文本标注所在的地理位置
|
offset : new BMapGL.Size(10, -20)
|
//设置文本偏移量
|
};
|
|
// 创建文本标注对象为文字
|
labels[index] = new BMapGL.Label(data[index].name +"\r\n"+ dateFormatStr(data[index].updateTime), opts);
|
// 设置label样式
|
labels[index].setStyle({
|
color : "black",
|
// border:"none",
|
"border" : "5px solid #e2e2e4",
|
"border-radius" : "10px",
|
"background" : "white",
|
fontSize : "18px",
|
// height : "50px",
|
lineHeight : "25px",
|
fontFamily : "微软雅黑"
|
});
|
// 将文本标注添加到地图上
|
map.addOverlay(labels[index]);
|
});
|
}
|
|
function rotate() {
|
//开启鼠标滚轮缩放
|
map.enableScrollWheelZoom(true);
|
|
//开启地球模式
|
map.setMapType(BMAP_EARTH_MAP);
|
|
// 初始化地图,设置动画起始点坐标和地图级别
|
map.centerAndZoom(new BMapGL.Point(214.406, 40.000), 5);
|
|
//旋转动画开始
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(204.406, 40.000));
|
}, 2000);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(194.406, 40.000)); //旋转动画
|
}, 2250);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(184.406, 40.000)); //旋转动画
|
}, 2500);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(174.406, 40.000)); //旋转动画
|
}, 2775);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(164.406, 40.000)); //旋转动画
|
}, 3000);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(154.406, 40.000)); //旋转动画
|
}, 3250);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(144.406, 40.000)); //旋转动画
|
}, 3500);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(134.406, 40.000)); //旋转动画
|
}, 3750);
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(124.406, 40.000)); //旋转动画
|
}, 4000);
|
//旋转动画结束
|
setTimeout(function() {
|
map.panTo(new BMapGL.Point(114.403, 40.000));
|
}, 4250);
|
}
|
|
//格式化时间
|
function dateFormatStr(time) {
|
if(time){
|
var d = new Date(time);
|
return dateFtt("yyyy-MM-dd hh:mm:ss",d);
|
}
|
return "";
|
}
|