wrap.html
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<link href="/pages/control/line/css/lineControl.css" rel="stylesheet" type="text/css" />
<div id="tab_map" class="portlet light portlet-fullscreen" style="transition: all .5s ease;padding: 0;" oncontextmenu=self.event.returnValue=false>
</div>
<script>
!function(){
//加载地图页面
$('#tab_map').load('/pages/mapmonitor/real/real.html', function(){
$('#mapContainer').height('100%').css('margin-top', 0);
$('#openWindow').remove();
$('.leftUtils').css('width', '189px');
startRefreshGpsTimer();
});
moment.locale('zh-cn');
var storage = window.localStorage;
var lineCodes = '';
var allGps = {};
//初始化lineCodes
$.each(JSON.parse(storage.getItem('lineControlItems')), function(i, obj){
lineCodes += (obj.lineCode + ',');
});
lineCodes = lineCodes.substr(0, lineCodes.length - 1);
//为地图提供gps数据
var gpsTimer;
var realGpsT = 1000 * 10;
function startRefreshGpsTimer(){
var f = arguments.callee;
refreshGpsProxy();
gpsTimer = setTimeout(f, realGpsT);
}
function refreshGpsProxy(){
refreshGps(function(add, up){
$('#tab_map #mapContainer').trigger('gps_refresh', [add, up]);
});
}
function refreshGps(cb){
$.ajax({
url: '/gps/real/line',
data: {lineCodes: lineCodes},
timeout: 5000,//5秒超时
success: getGpsSuccess,
error: getGpsError
});
function getGpsSuccess(gpsList){
if(!gpsList || gpsList.length == 0)
return;
var prve = allGps
,addArray = []
,upArray = []
,oldGps;
for(var i = 0, gps; gps=gpsList[i++];){
oldGps = prve[gps.deviceId];
if(!oldGps){
addArray.push(gps);
}
else if(gps.timestamp > oldGps.timestamp){
//更新
upArray.push(gps);
}
allGps[gps.deviceId] = gps;
}
cb && cb(addArray, upArray);
}
function getGpsError(jqXHR, textStatus){
if(textStatus === 'error'){
console.log(jqXHR, textStatus);
layer.alert('获取GPS数据时出现异常,请尝试刷新页面!', {icon: 2});
}
else if(textStatus === 'timeout')
layer.alert('连接服务器超时', {icon: 2});
//停止gps刷新
clearTimeout(gpsTimer);
}
}
}();
</script>