Commit 1b11adc8cff662002e0f897e7118d1cd1ed164f0

Authored by 王通
1 parent 60e654b2

1.班次"无发有到"色块显示异常修正

src/main/resources/static/pages/control/line/js/data.js
1   -/**
2   - * 数据处理模块
3   -*/
4   -var _data = (function(){
5   - var storage = window.localStorage;
6   -
7   - var gpsTimer;
8   -
9   - //实时GPS数据
10   - var allGps = {};
11   - //10秒刷新一次实时GPS
12   - var realGpsT = 1000 * 8;
13   -
14   - var dateStr = moment().format('YYYY-MM-DD');
15   - //实际排班
16   - var schedules = {};
17   -
18   - //站点路由缓存
19   - var stationRoute = {};
20   -
21   - //线路 ——> 路牌 ——> 班次 3层映射
22   - var lineLpMap = {};
23   - //线路标准信息
24   - var lineInformations = {};
25   - //车辆和班次数组映射
26   - //var clSchMap = {};
27   -
28   - //车辆自编号和设备号对照
29   - var carDeviceIdMapp = {};
30   -
31   - var fcsjSort = function(a, b){
32   - return (a.fcno - b.fcno) + (a.fcsjT - b.fcsjT);
33   - }
34   -
35   - var dataObject = {
36   - //根据线路和上下行获取计划排班
37   - findSchByLine: function(xlbm, upDown){
38   - var array = [];
39   - var sch;
40   - for(var id in schedules){
41   - sch = schedules[id];
42   - if(sch.xlBm == xlbm
43   - && sch.xlDir == upDown){
44   - array.push(sch);
45   - }
46   - }
47   - //排序
48   - array.sort(fcsjSort);
49   -
50   - return array;
51   - },
52   - //根据车辆获取班次数组
53   - findByCl: function(nbbm){
54   - var array = [];
55   - for(var id in schedules){
56   - sch = schedules[id];
57   - if(sch.clZbh == nbbm)
58   - array.push(sch);
59   - }
60   -
61   - //排序
62   - array.sort(fcsjSort);
63   - return array;
64   - },
65   - //清理线路下班次
66   - clearByLineCode: function(lineCode){
67   - for(var id in schedules){
68   - if(schedules[id].xlBm == lineCode){
69   - schedules[id] = null;
70   - delete schedules[id];
71   - }
72   - }
73   -
74   - lineLpMap[lineCode] = {};
75   - },
76   - //添加一个班次
77   - pushSchedule: function(sch){
78   - //附加信息
79   - attachInfo(sch);
80   - schedules[sch.id] = sch;
81   -
82   - var xl=sch.xlBm,lp=sch.lpName;
83   - if(!lineLpMap[xl][lp])
84   - lineLpMap[xl][lp] = [];
85   -
86   - lineLpMap[xl][lp].push(sch);
87   - },
88   - //更新班次信息
89   - updateSchedule: function(sch){
90   - //附加信息
91   - attachInfo(sch);
92   - schedules[sch.id] = sch;
93   -
94   - var lpArray = lineLpMap[sch.xlBm][sch.lpName];
95   - $.each(lpArray, function(i){
96   - if(this.id == sch.id){
97   - lpArray.splice(i, 1, sch);
98   - return false;
99   - }
100   - });
101   - },
102   - getLines: function(){
103   - return JSON.parse(storage.getItem('lineControlItems'));
104   - },
105   - getDeviceIdByCar: function(car){
106   - return carDeviceIdMapp[car];
107   - },
108   - //获取线路标准信息
109   - getLineInformation: function(lineCode){
110   - return lineInformations[lineCode];
111   - },
112   - getLineIds: function(){
113   - return JSON.parse(storage.getItem('lineIds'));
114   - },
115   - //获取线路路牌对照数据
116   - getLineLpMap: function(){
117   - return lineLpMap;
118   - },
119   - //根据线路编码获取应发未发班次数量
120   - getYfwfNumByLine: function(lineCode){
121   - var lpMap = lineLpMap[lineCode]
122   - ,arr = [], t = new Date().valueOf(), num = 0;
123   - for(var lp in lpMap){
124   - arr = lpMap[lp];
125   - for(var i = 0, sch; sch=arr[i++];){
126   - if(sch.fcsjT > t)
127   - break;
128   -
129   - if(sch.fcsjActual == null && sch.fcsjActualTime == null && sch.status != -1)
130   - num ++;
131   - }
132   - }
133   - return num;
134   - },
135   - //根据线路编码获取站点路由
136   - getStationRouteByLine: function(lineCode){
137   - return stationRoute[lineCode];
138   - },
139   - //为GPS点附加班次信息
140   - attachSchedulInfo: function(gpsArray){
141   - $.each(gpsArray, function(){
142   - gps = this;
143   - if(gps.schId)
144   - gps.sch = schedules[gps.schId];
145   -
146   - });
147   - }
148   - //查询站点路由
149   - ,queryStationRoute : function(lineId,container, cb, width){
150   - $get('/stationroute/all', {'line.lineCode_eq': lineId, 'destroy_eq': 0}, function(routes){
151   - var svgData = analyData(routes);
152   - cb && cb(lineId, svgData, container, width);
153   - });
154   - },
155   - //实时GPS定时刷新
156   - startRefreshGpsTimer: function(){
157   - var f = arguments.callee;
158   - refreshGpsProxy();
159   - gpsTimer = setTimeout(f, realGpsT);
160   - },
161   - //查询实际排班计划
162   - queryRealSchedule: function(lineArrayStr, cb){
163   - $.get('/realSchedule/lines', {lines: lineArrayStr} ,function(rs){
164   - var list, sm, em, lineName;
165   - for(var lineCode in rs){
166   - list = rs[lineCode];
167   - lineLpMap[lineCode] = {};
168   - $.each(list, function(){
169   - attachInfo(this);
170   - //缓存排班计划
171   - schedules[this.id] = this;
172   - //构造 线路 ——> 路牌 ——> 班次 3层映射
173   - if(!lineLpMap[lineCode][this.lpName])
174   - lineLpMap[lineCode][this.lpName] = [];
175   - lineLpMap[lineCode][this.lpName].push(this);
176   - });
177   -
178   - //按发车时间排序
179   - list.sort(fcsjSort);
180   - }
181   - cb && cb(rs);
182   - });
183   - },
184   - //根据排班ID获取排班
185   - getSchedulById: function(id){
186   - return schedules[id];
187   - },
188   - //根据车辆内部编码获取排班数组
189   - getSchedulByVeh: function(nbbm){
190   - var array = [];
191   - var sch;
192   - for(var id in schedules){
193   - sch = schedules[id];
194   - if(sch.clZbh == nbbm)
195   - array.push(sch);
196   - }
197   -
198   - //排序
199   - array.sort(fcsjSort);
200   - return array;
201   - },
202   - //根据设备号获取GPS
203   - getGpsByDeviceId: function(deviceId){
204   - return allGps[deviceId];
205   - },
206   - //获取所有GPS
207   - findAllGps: function(){
208   - return allGps;
209   - }
210   - };
211   -
212   - //初始化carDeviceIdMapp
213   - $.get('/realSchedule/carDeviceMapp', function(rs){
214   - carDeviceIdMapp = rs;
215   - });
216   -
217   - //初始化lineCodes
218   - $.each(dataObject.getLines(), function(i, obj){
219   - lineCodes += (obj.lineCode + ',');
220   - lineMap[obj.lineCode] = obj;
221   - });
222   - lineCodes = lineCodes.substr(0, lineCodes.length - 1);
223   -
224   - //地图tab页显示时 注入gps数据
225   - $('a[href=#tab_map]').on('shown.bs.tab', function(){
226   - $('#tab_map #mapContainer').trigger('gps_refresh', [allGps]);
227   - });
228   -
229   - //获取线路标准信息
230   - $.get('/lineInformation/line/multi', {lineCodes: lineCodes}
231   - ,function(rs){
232   - $.each(rs, function(){
233   - lineInformations[this.line.lineCode] = this;
234   - delete this['line'];
235   - });
236   - });
237   -
238   - function attachInfo(sch){
239   - //实际发车误差值
240   - if(sch.fcsjActualTime){
241   - var diff = parseInt((sch.fcsjActualTime - sch.dfsjT) / 1000 / 60);
242   - if(diff > 0)
243   - sch.fcsj_diff = '( +' + diff + ' )';
244   - else if(diff < 0)
245   - sch.fcsj_diff = '( ' + diff + ' )';
246   - else
247   - sch.fcsj_diff = '';
248   - }
249   - }
250   -
251   - function refreshGpsProxy(){
252   - refreshGps(function(all){
253   - //触发元素刷新事件
254   - $('#tab_home,#tab_map #mapContainer').trigger('gps_refresh', [all]);
255   - });
256   - }
257   - var upSort = function(a, b){
258   - return a.stationRouteCode - b.stationRouteCode;
259   - }
260   -
261   - var downSort = function(a, b){
262   - return b.stationRouteCode - a.stationRouteCode;
263   - }
264   -
265   - var station_indexof = function(array, station , start){
266   - var res = -1
267   -
268   - for(var i = start, obj; obj = array[i++];){
269   -
270   - if(obj.stationName == station.stationName){
271   - res = i;
272   - break;
273   - }
274   - }
275   -
276   - return res;
277   - }
278   -
279   -
280   - /**
281   - * 刷新GPS车辆信息
282   - */
283   - function refreshGps(cb){
284   - $.ajax({
285   - url: '/gps/real/line',
286   - data: {lineCodes: lineCodes},
287   - timeout: 5000,//5秒超时
288   - success: getGpsSuccess,
289   - error: getGpsError
290   - });
291   -
292   - function getGpsSuccess(gpsList){
293   - if(!gpsList || gpsList.length == 0)
294   - return;
295   -
296   - //var prve = allGps
297   - //,addArray = []
298   - //,upArray = []
299   - // ,oldGps;
300   - for(var i = 0, gps; gps=gpsList[i++];){
301   - /*oldGps = prve[gps.deviceId];
302   - if(!oldGps){
303   - addArray.push(gps);
304   - }
305   - else if(gps.timestamp > oldGps.timestamp){
306   - //更新
307   - upArray.push(gps);
308   - }*/
309   - //addArray.push(gps);
310   -/* if(prve[gps.deviceId] &&
311   - gps.timestamp == prve[gps.deviceId].timestamp)
312   - continue;*/
313   - //异常状态检查
314   - abnormalCheck(gps);
315   - //关联班次信息
316   - if(gps.schId)
317   - gps.sch = schedules[gps.schId];
318   -
319   - allGps[gps.deviceId] = gps;
320   - }
321   - //cb && cb(addArray, upArray);
322   - cb && cb(allGps);
323   - }
324   -
325   - function abnormalCheck(gps){
326   - if(!stationRoute[gps.lineId])
327   - return;
328   - var routes = stationRoute[gps.lineId][gps.upDown]
329   - ,rs;
330   - if(routes){
331   - $.each(routes , function(){
332   - if(this.stationCode == gps.stopNo){
333   - rs = 1;
334   - return false;
335   - }
336   - });
337   - }
338   -
339   - if(!rs){
340   - gps.abnormal = true;
341   - gps.abnormalText = '走向异常?';
342   - }
343   - }
344   -
345   - function getGpsError(jqXHR, textStatus){
346   - if(textStatus === 'error')
347   - layer.alert('获取GPS数据时出现异常,请尝试刷新页面!', {icon: 2});
348   - else if(textStatus === 'timeout')
349   - layer.alert('连接服务器超时', {icon: 2});
350   -
351   - //停止gps刷新
352   - clearTimeout(gpsTimer);
353   - }
354   - }
355   -
356   - /**
357   - * 解析数据成svg想要的格式
358   - */
359   - function analyData(routes){
360   - //按上下行拆分
361   - var up=[],down=[];
362   - for(var i = 0, route; route = routes[i++];){
363   - if(route.directions==0)
364   - up.push(route);
365   - else if(route.directions==1)
366   - down.push(route);
367   - }
368   - //排序
369   - up.sort(upSort);
370   - down.sort(downSort);
371   - //缓存路由
372   - if(routes.length > 0){
373   - stationRoute[routes[0].lineCode] = [up.slice(0), down.slice(0).sort(upSort)];
374   - }
375   -
376   - //合并
377   - var data = [];
378   - for(var j = 0; j < up.length; j ++){
379   - var upS = up[j] == null?{}:up[j]
380   - ,downS = down[j] == null?{}:down[j]
381   - ,op = {name: [upS.stationName], id: [upS.stationCode, downS.stationCode], type: 2, stationMark: upS.stationMark};
382   -
383   - //编码相同
384   - if(upS.stationName != downS.stationName){
385   - var dIndex = station_indexof(down, upS, j);
386   - if(dIndex == -1){
387   - op.type = 0;
388   - op.id = [upS.stationCod, -1];
389   - //占位
390   - down.splice(j, 0, {});
391   - }else{
392   - for(var t = j; t < dIndex - 1; t++){
393   - var temp = down[t];
394   - data.push({name: [temp.stationName], type:1, id: [temp.stationCode]});
395   - }
396   - //delete
397   - down.splice(j, dIndex - 1 - j);
398   - j --;
399   - continue;
400   - }
401   - }
402   - data.push(op);
403   - }
404   -
405   - //将上下行挨着的独立站点合并
406   - var len = data.length - 1, first, sec;
407   - for(var s = 0; s < len; s ++){
408   - first = data[s];
409   - sec = data[s + 1];
410   -
411   - if(first.type == 0
412   - && sec.type == 1){
413   - data.splice(s, 2, {name: [first['name'][0],sec['name'][0]], type:3, id: [first['id'][0],sec['id'][0]]});
414   - len --;
415   - }
416   - else if(first.type == 1 && sec.type == 0){
417   - data.splice(s, 2, {name: [first['name'][0],sec['name'][0]], type:3, id: [first['id'][0],sec['id'][0]]});
418   - len --;
419   - }
420   - }
421   - return data;
422   - }
423   -
424   - countDown('data.js');
425   - //queryStationRoute();
426   - return dataObject;
  1 +/**
  2 + * 数据处理模块
  3 +*/
  4 +var _data = (function(){
  5 + var storage = window.localStorage;
  6 +
  7 + var gpsTimer;
  8 +
  9 + //实时GPS数据
  10 + var allGps = {};
  11 + //10秒刷新一次实时GPS
  12 + var realGpsT = 1000 * 8;
  13 +
  14 + var dateStr = moment().format('YYYY-MM-DD');
  15 + //实际排班
  16 + var schedules = {};
  17 +
  18 + //站点路由缓存
  19 + var stationRoute = {};
  20 +
  21 + //线路 ——> 路牌 ——> 班次 3层映射
  22 + var lineLpMap = {};
  23 + //线路标准信息
  24 + var lineInformations = {};
  25 + //车辆和班次数组映射
  26 + //var clSchMap = {};
  27 +
  28 + //车辆自编号和设备号对照
  29 + var carDeviceIdMapp = {};
  30 +
  31 + var fcsjSort = function(a, b){
  32 + return (a.fcno - b.fcno) + (a.fcsjT - b.fcsjT);
  33 + }
  34 +
  35 + var dataObject = {
  36 + //根据线路和上下行获取计划排班
  37 + findSchByLine: function(xlbm, upDown){
  38 + var array = [];
  39 + var sch;
  40 + for(var id in schedules){
  41 + sch = schedules[id];
  42 + if(sch.xlBm == xlbm
  43 + && sch.xlDir == upDown){
  44 + array.push(sch);
  45 + }
  46 + }
  47 + //排序
  48 + array.sort(fcsjSort);
  49 +
  50 + return array;
  51 + },
  52 + //根据车辆获取班次数组
  53 + findByCl: function(nbbm){
  54 + var array = [];
  55 + for(var id in schedules){
  56 + sch = schedules[id];
  57 + if(sch.clZbh == nbbm)
  58 + array.push(sch);
  59 + }
  60 +
  61 + //排序
  62 + array.sort(fcsjSort);
  63 + return array;
  64 + },
  65 + //清理线路下班次
  66 + clearByLineCode: function(lineCode){
  67 + for(var id in schedules){
  68 + if(schedules[id].xlBm == lineCode){
  69 + schedules[id] = null;
  70 + delete schedules[id];
  71 + }
  72 + }
  73 +
  74 + lineLpMap[lineCode] = {};
  75 + },
  76 + //添加一个班次
  77 + pushSchedule: function(sch){
  78 + //附加信息
  79 + attachInfo(sch);
  80 + schedules[sch.id] = sch;
  81 +
  82 + var xl=sch.xlBm,lp=sch.lpName;
  83 + if(!lineLpMap[xl][lp])
  84 + lineLpMap[xl][lp] = [];
  85 +
  86 + lineLpMap[xl][lp].push(sch);
  87 + },
  88 + //更新班次信息
  89 + updateSchedule: function(sch){
  90 + //附加信息
  91 + attachInfo(sch);
  92 + schedules[sch.id] = sch;
  93 +
  94 + var lpArray = lineLpMap[sch.xlBm][sch.lpName];
  95 + $.each(lpArray, function(i){
  96 + if(this.id == sch.id){
  97 + lpArray.splice(i, 1, sch);
  98 + return false;
  99 + }
  100 + });
  101 + },
  102 + getLines: function(){
  103 + return JSON.parse(storage.getItem('lineControlItems'));
  104 + },
  105 + getDeviceIdByCar: function(car){
  106 + return carDeviceIdMapp[car];
  107 + },
  108 + //获取线路标准信息
  109 + getLineInformation: function(lineCode){
  110 + return lineInformations[lineCode];
  111 + },
  112 + getLineIds: function(){
  113 + return JSON.parse(storage.getItem('lineIds'));
  114 + },
  115 + //获取线路路牌对照数据
  116 + getLineLpMap: function(){
  117 + return lineLpMap;
  118 + },
  119 + //根据线路编码获取应发未发班次数量
  120 + getYfwfNumByLine: function(lineCode){
  121 + var lpMap = lineLpMap[lineCode]
  122 + ,arr = [], t = new Date().valueOf(), num = 0;
  123 + for(var lp in lpMap){
  124 + arr = lpMap[lp];
  125 + for(var i = 0, sch; sch=arr[i++];){
  126 + if(sch.fcsjT > t)
  127 + break;
  128 +
  129 + if(sch.fcsjActual == null && sch.fcsjActualTime == null && sch.status != -1)
  130 + num ++;
  131 + }
  132 + }
  133 + return num;
  134 + },
  135 + //根据线路编码获取站点路由
  136 + getStationRouteByLine: function(lineCode){
  137 + return stationRoute[lineCode];
  138 + },
  139 + //为GPS点附加班次信息
  140 + attachSchedulInfo: function(gpsArray){
  141 + $.each(gpsArray, function(){
  142 + gps = this;
  143 + if(gps.schId)
  144 + gps.sch = schedules[gps.schId];
  145 +
  146 + });
  147 + }
  148 + //查询站点路由
  149 + ,queryStationRoute : function(lineId,container, cb, width){
  150 + $get('/stationroute/all', {'line.lineCode_eq': lineId, 'destroy_eq': 0}, function(routes){
  151 + var svgData = analyData(routes);
  152 + cb && cb(lineId, svgData, container, width);
  153 + });
  154 + },
  155 + //实时GPS定时刷新
  156 + startRefreshGpsTimer: function(){
  157 + var f = arguments.callee;
  158 + refreshGpsProxy();
  159 + gpsTimer = setTimeout(f, realGpsT);
  160 + },
  161 + //查询实际排班计划
  162 + queryRealSchedule: function(lineArrayStr, cb){
  163 + $.get('/realSchedule/lines', {lines: lineArrayStr} ,function(rs){
  164 + var list, sm, em, lineName;
  165 + for(var lineCode in rs){
  166 + list = rs[lineCode];
  167 + lineLpMap[lineCode] = {};
  168 + $.each(list, function(){
  169 + attachInfo(this);
  170 + //缓存排班计划
  171 + schedules[this.id] = this;
  172 + //构造 线路 ——> 路牌 ——> 班次 3层映射
  173 + if(!lineLpMap[lineCode][this.lpName])
  174 + lineLpMap[lineCode][this.lpName] = [];
  175 + lineLpMap[lineCode][this.lpName].push(this);
  176 + });
  177 +
  178 + //按发车时间排序
  179 + list.sort(fcsjSort);
  180 + }
  181 + cb && cb(rs);
  182 + });
  183 + },
  184 + //根据排班ID获取排班
  185 + getSchedulById: function(id){
  186 + return schedules[id];
  187 + },
  188 + //根据车辆内部编码获取排班数组
  189 + getSchedulByVeh: function(nbbm){
  190 + var array = [];
  191 + var sch;
  192 + for(var id in schedules){
  193 + sch = schedules[id];
  194 + if(sch.clZbh == nbbm)
  195 + array.push(sch);
  196 + }
  197 +
  198 + //排序
  199 + array.sort(fcsjSort);
  200 + return array;
  201 + },
  202 + //根据设备号获取GPS
  203 + getGpsByDeviceId: function(deviceId){
  204 + return allGps[deviceId];
  205 + },
  206 + //获取所有GPS
  207 + findAllGps: function(){
  208 + return allGps;
  209 + }
  210 + };
  211 +
  212 + //初始化carDeviceIdMapp
  213 + $.get('/realSchedule/carDeviceMapp', function(rs){
  214 + carDeviceIdMapp = rs;
  215 + });
  216 +
  217 + //初始化lineCodes
  218 + $.each(dataObject.getLines(), function(i, obj){
  219 + lineCodes += (obj.lineCode + ',');
  220 + lineMap[obj.lineCode] = obj;
  221 + });
  222 + lineCodes = lineCodes.substr(0, lineCodes.length - 1);
  223 +
  224 + //地图tab页显示时 注入gps数据
  225 + $('a[href=#tab_map]').on('shown.bs.tab', function(){
  226 + $('#tab_map #mapContainer').trigger('gps_refresh', [allGps]);
  227 + });
  228 +
  229 + //获取线路标准信息
  230 + $.get('/lineInformation/line/multi', {lineCodes: lineCodes}
  231 + ,function(rs){
  232 + $.each(rs, function(){
  233 + lineInformations[this.line.lineCode] = this;
  234 + delete this['line'];
  235 + });
  236 + });
  237 +
  238 + function attachInfo(sch){
  239 + //实际发车误差值
  240 + if(sch.fcsjActualTime){
  241 + var diff = parseInt((sch.fcsjActualTime - sch.dfsjT) / 1000 / 60);
  242 + if(diff > 0)
  243 + sch.fcsj_diff = '( +' + diff + ' )';
  244 + else if(diff < 0)
  245 + sch.fcsj_diff = '( ' + diff + ' )';
  246 + else
  247 + sch.fcsj_diff = '';
  248 + }
  249 +
  250 + if (sch.fcsjActual == null && sch.zdsjActual && sch.status != -1) {
  251 + sch.status = 4;
  252 + }
  253 + }
  254 +
  255 + function refreshGpsProxy(){
  256 + refreshGps(function(all){
  257 + //触发元素刷新事件
  258 + $('#tab_home,#tab_map #mapContainer').trigger('gps_refresh', [all]);
  259 + });
  260 + }
  261 + var upSort = function(a, b){
  262 + return a.stationRouteCode - b.stationRouteCode;
  263 + }
  264 +
  265 + var downSort = function(a, b){
  266 + return b.stationRouteCode - a.stationRouteCode;
  267 + }
  268 +
  269 + var station_indexof = function(array, station , start){
  270 + var res = -1
  271 +
  272 + for(var i = start, obj; obj = array[i++];){
  273 +
  274 + if(obj.stationName == station.stationName){
  275 + res = i;
  276 + break;
  277 + }
  278 + }
  279 +
  280 + return res;
  281 + }
  282 +
  283 +
  284 + /**
  285 + * 刷新GPS车辆信息
  286 + */
  287 + function refreshGps(cb){
  288 + $.ajax({
  289 + url: '/gps/real/line',
  290 + data: {lineCodes: lineCodes},
  291 + timeout: 5000,//5秒超时
  292 + success: getGpsSuccess,
  293 + error: getGpsError
  294 + });
  295 +
  296 + function getGpsSuccess(gpsList){
  297 + if(!gpsList || gpsList.length == 0)
  298 + return;
  299 +
  300 + //var prve = allGps
  301 + //,addArray = []
  302 + //,upArray = []
  303 + // ,oldGps;
  304 + for(var i = 0, gps; gps=gpsList[i++];){
  305 + /*oldGps = prve[gps.deviceId];
  306 + if(!oldGps){
  307 + addArray.push(gps);
  308 + }
  309 + else if(gps.timestamp > oldGps.timestamp){
  310 + //更新
  311 + upArray.push(gps);
  312 + }*/
  313 + //addArray.push(gps);
  314 +/* if(prve[gps.deviceId] &&
  315 + gps.timestamp == prve[gps.deviceId].timestamp)
  316 + continue;*/
  317 + //异常状态检查
  318 + abnormalCheck(gps);
  319 + //关联班次信息
  320 + if(gps.schId)
  321 + gps.sch = schedules[gps.schId];
  322 +
  323 + allGps[gps.deviceId] = gps;
  324 + }
  325 + //cb && cb(addArray, upArray);
  326 + cb && cb(allGps);
  327 + }
  328 +
  329 + function abnormalCheck(gps){
  330 + if(!stationRoute[gps.lineId])
  331 + return;
  332 + var routes = stationRoute[gps.lineId][gps.upDown]
  333 + ,rs;
  334 + if(routes){
  335 + $.each(routes , function(){
  336 + if(this.stationCode == gps.stopNo){
  337 + rs = 1;
  338 + return false;
  339 + }
  340 + });
  341 + }
  342 +
  343 + if(!rs){
  344 + gps.abnormal = true;
  345 + gps.abnormalText = '走向异常?';
  346 + }
  347 + }
  348 +
  349 + function getGpsError(jqXHR, textStatus){
  350 + if(textStatus === 'error')
  351 + layer.alert('获取GPS数据时出现异常,请尝试刷新页面!', {icon: 2});
  352 + else if(textStatus === 'timeout')
  353 + layer.alert('连接服务器超时', {icon: 2});
  354 +
  355 + //停止gps刷新
  356 + clearTimeout(gpsTimer);
  357 + }
  358 + }
  359 +
  360 + /**
  361 + * 解析数据成svg想要的格式
  362 + */
  363 + function analyData(routes){
  364 + //按上下行拆分
  365 + var up=[],down=[];
  366 + for(var i = 0, route; route = routes[i++];){
  367 + if(route.directions==0)
  368 + up.push(route);
  369 + else if(route.directions==1)
  370 + down.push(route);
  371 + }
  372 + //排序
  373 + up.sort(upSort);
  374 + down.sort(downSort);
  375 + //缓存路由
  376 + if(routes.length > 0){
  377 + stationRoute[routes[0].lineCode] = [up.slice(0), down.slice(0).sort(upSort)];
  378 + }
  379 +
  380 + //合并
  381 + var data = [];
  382 + for(var j = 0; j < up.length; j ++){
  383 + var upS = up[j] == null?{}:up[j]
  384 + ,downS = down[j] == null?{}:down[j]
  385 + ,op = {name: [upS.stationName], id: [upS.stationCode, downS.stationCode], type: 2, stationMark: upS.stationMark};
  386 +
  387 + //编码相同
  388 + if(upS.stationName != downS.stationName){
  389 + var dIndex = station_indexof(down, upS, j);
  390 + if(dIndex == -1){
  391 + op.type = 0;
  392 + op.id = [upS.stationCod, -1];
  393 + //占位
  394 + down.splice(j, 0, {});
  395 + }else{
  396 + for(var t = j; t < dIndex - 1; t++){
  397 + var temp = down[t];
  398 + data.push({name: [temp.stationName], type:1, id: [temp.stationCode]});
  399 + }
  400 + //delete
  401 + down.splice(j, dIndex - 1 - j);
  402 + j --;
  403 + continue;
  404 + }
  405 + }
  406 + data.push(op);
  407 + }
  408 +
  409 + //将上下行挨着的独立站点合并
  410 + var len = data.length - 1, first, sec;
  411 + for(var s = 0; s < len; s ++){
  412 + first = data[s];
  413 + sec = data[s + 1];
  414 +
  415 + if(first.type == 0
  416 + && sec.type == 1){
  417 + data.splice(s, 2, {name: [first['name'][0],sec['name'][0]], type:3, id: [first['id'][0],sec['id'][0]]});
  418 + len --;
  419 + }
  420 + else if(first.type == 1 && sec.type == 0){
  421 + data.splice(s, 2, {name: [first['name'][0],sec['name'][0]], type:3, id: [first['id'][0],sec['id'][0]]});
  422 + len --;
  423 + }
  424 + }
  425 + return data;
  426 + }
  427 +
  428 + countDown('data.js');
  429 + //queryStationRoute();
  430 + return dataObject;
427 431 })();
428 432 \ No newline at end of file
... ...