Commit 18c7788e20b6a29d552c11c8ff68c425c6604ab6
1 parent
4d115176
update...
Showing
3 changed files
with
330 additions
and
242 deletions
src/main/resources/static/real_control_v2/js/utils/svg_data_convert.js
| ... | ... | @@ -6,184 +6,168 @@ var gb_svg_data_convert = (function () { |
| 6 | 6 | * |
| 7 | 7 | * enableAttr: 是否启用配置信息 |
| 8 | 8 | */ |
| 9 | - function mergeRoute(routes, enableAttr, lineCode, loopLine) { | |
| 9 | + function mergeRoute(rs, enableAttr, lineCode, loopLine) { | |
| 10 | 10 | //按上下行拆分 |
| 11 | - routes = gb_common.groupBy(routes, 'directions'); | |
| 12 | - var up = routes[0], | |
| 13 | - down = routes[1]; | |
| 11 | + rs = gb_common.groupBy(rs, 'directions'); | |
| 14 | 12 | //排序 |
| 15 | - up.sort(upSort); | |
| 16 | - down.sort(downSort); | |
| 17 | - var data = []; | |
| 18 | - | |
| 19 | - //根据配置处理一下数据 | |
| 20 | - if (enableAttr) { | |
| 21 | - var svgAttr = gb_data_basic.getSvgAttr(lineCode); | |
| 22 | - if (svgAttr) { | |
| 23 | - up = filterByAttrs(svgAttr, up); | |
| 24 | - down = filterByAttrs(svgAttr, down); | |
| 25 | - } | |
| 26 | - } | |
| 27 | - | |
| 28 | - //环线 只画上行 | |
| 29 | - if(loopLine){ | |
| 30 | - for (var j = 0; j < up.length; j++) { | |
| 31 | - var upS = nvl_get(up, j); | |
| 32 | - op = { | |
| 33 | - name: [upS.stationName], | |
| 34 | - id: [get_station_code(upS)], | |
| 35 | - type: 0, | |
| 36 | - stationMark: upS.stationMark | |
| 37 | - }; | |
| 38 | - data.push(op); | |
| 13 | + sort_station_route(rs); | |
| 14 | + //模拟图配置信息 | |
| 15 | + use_chart_config(enableAttr, lineCode, rs); | |
| 16 | + | |
| 17 | + if(loopLine) | |
| 18 | + rs[1]=[]; | |
| 19 | + //一个萝卜一个坑 | |
| 20 | + data = putTurnip(rs[0], rs[1]); | |
| 21 | + return data; | |
| 22 | + } | |
| 23 | + | |
| 24 | + var putTurnip = function (arr1, arr2) { | |
| 25 | + var data = [], a1, a2; | |
| 26 | + for(var i = 0; i < 888; i ++){ | |
| 27 | + a1=arr1[i]; | |
| 28 | + a2=arr2[i]; | |
| 29 | + if(null != a1 && null != a2 && a1.stationName!=a2.stationName) { | |
| 30 | + //arr2 包含 a1 | |
| 31 | + var ii = name_indexOf(a1, arr2); | |
| 32 | + if(ii > i){ | |
| 33 | + fill_arr(arr1, i, ii - i); | |
| 34 | + i-=1; | |
| 35 | + continue; | |
| 36 | + } | |
| 37 | + //arr1 包含 a2 | |
| 38 | + ii = name_indexOf(a2, arr1); | |
| 39 | + if(ii > i){ | |
| 40 | + fill_arr(arr2, i, ii - i); | |
| 41 | + i-=1; | |
| 42 | + continue; | |
| 43 | + } | |
| 39 | 44 | } |
| 40 | 45 | |
| 41 | - //上下行GPS容器 | |
| 42 | - $.each(data, function () { | |
| 43 | - this.gpsUps = []; | |
| 44 | - this.gpsDowns = []; | |
| 45 | - }); | |
| 46 | - | |
| 47 | - return data; | |
| 46 | + if(null==a1 && null==a2) | |
| 47 | + break; | |
| 48 | + merge(data, i, a1, a2); | |
| 48 | 49 | } |
| 49 | 50 | |
| 51 | + return data; | |
| 52 | + }; | |
| 53 | + | |
| 54 | + var fill_arr = function (array, i, size) { | |
| 55 | + for(var j=0; j < size; j++){ | |
| 56 | + array.splice(j + i, 0, null); | |
| 57 | + } | |
| 58 | + }; | |
| 50 | 59 | |
| 51 | - //同名站点合并 | |
| 52 | - for (var j = 0; j < up.length; j++) { | |
| 53 | - var upS = nvl_get(up, j), | |
| 54 | - downS = nvl_get(down, j), | |
| 55 | - op = { | |
| 56 | - name: [upS.stationName], | |
| 57 | - id: [get_station_code(upS), get_station_code(downS)], | |
| 58 | - type: 2, | |
| 59 | - stationMark: upS.stationMark//站点标记 | |
| 60 | - }; | |
| 61 | - | |
| 62 | - if (upS.stationName != downS.stationName) { | |
| 63 | - //下行站点在上行路由中是否存在 | |
| 64 | - var dIndex = station_indexof(down, upS, j); | |
| 65 | - //上行站点在下行路由中是否存在 | |
| 66 | - var uIndex = station_indexof(up, downS, j); | |
| 67 | - if (dIndex == -1 || dIndex - j > 4) { | |
| 68 | - if (uIndex == -1 && dIndex - j < 4) { | |
| 69 | - op.type = 3; | |
| 70 | - op.name = [upS.stationName, downS.stationName]; | |
| 71 | - } | |
| 72 | - else { | |
| 73 | - op.type = 0; | |
| 74 | - op.id = [get_station_code(upS), -1]; | |
| 75 | - //占位 | |
| 76 | - down.splice(j, 0, {}); | |
| 77 | - } | |
| 78 | - } else { | |
| 79 | - for (var t = j; t < dIndex - 1; t++) { | |
| 80 | - var temp = down[t]; | |
| 81 | - data.push({ | |
| 82 | - name: [temp.stationName], | |
| 83 | - type: 1, | |
| 84 | - id: [get_station_code(temp)] | |
| 85 | - }); | |
| 86 | - } | |
| 87 | - //delete | |
| 88 | - down.splice(j, dIndex - 1 - j); | |
| 89 | - j--; | |
| 90 | - continue; | |
| 91 | - } | |
| 60 | + var merge = function (array, i, a1, a2) { | |
| 61 | + array.splice(i, 1, createItem(a1, a2)); | |
| 62 | + }; | |
| 63 | + | |
| 64 | + var createItem = function (up, down) { | |
| 65 | + if(null==up && null==down) | |
| 66 | + return null; | |
| 67 | + | |
| 68 | + var names, type=2,ids,mark; | |
| 69 | + if(null==up){ | |
| 70 | + type=1; | |
| 71 | + names=[down.stationName]; | |
| 72 | + ids=[get_station_code(down)]; | |
| 73 | + mark=down.stationMark; | |
| 74 | + } | |
| 75 | + else if(null==down) { | |
| 76 | + type=0; | |
| 77 | + names=[up.stationName]; | |
| 78 | + ids=[get_station_code(up)]; | |
| 79 | + mark=up.stationMark; | |
| 80 | + } | |
| 81 | + else{ | |
| 82 | + names=[up.stationName]; | |
| 83 | + ids=[get_station_code(up), get_station_code(down)]; | |
| 84 | + mark=up.stationMark; | |
| 85 | + if(up.stationName!=down.stationName){ | |
| 86 | + type=3; | |
| 87 | + names.push(down.stationName); | |
| 92 | 88 | } |
| 93 | - data.push(op); | |
| 94 | 89 | } |
| 90 | + return { | |
| 91 | + name: names, | |
| 92 | + id: ids, | |
| 93 | + type: type, | |
| 94 | + stationMark: mark | |
| 95 | + }; | |
| 96 | + }; | |
| 95 | 97 | |
| 96 | - //将上下行挨着的异名站点合并 | |
| 97 | - var len = data.length - 1, | |
| 98 | - first, sec; | |
| 99 | - for (var s = 0; s < len; s++) { | |
| 100 | - first = data[s]; | |
| 101 | - sec = data[s + 1]; | |
| 102 | - | |
| 103 | - if (first.type == 0 && | |
| 104 | - sec.type == 1) { | |
| 105 | - data.splice(s, 2, { | |
| 106 | - name: [first['name'][0], sec['name'][0]], | |
| 107 | - type: 3, | |
| 108 | - id: [first['id'][0], sec['id'][0]] | |
| 109 | - }); | |
| 110 | - len--; | |
| 111 | - } else if (first.type == 1 && sec.type == 0) { | |
| 112 | - data.splice(s, 2, { | |
| 113 | - name: [first['name'][0], sec['name'][0]], | |
| 114 | - type: 3, | |
| 115 | - id: [first['id'][0], sec['id'][0]] | |
| 116 | - }); | |
| 117 | - len--; | |
| 118 | - } | |
| 98 | + var name_indexOf = function (a1, arr) { | |
| 99 | + for(var j=0,len=arr.length;j<len;j++){ | |
| 100 | + if(null != arr[j] && a1.stationName==arr[j].stationName) | |
| 101 | + return j; | |
| 119 | 102 | } |
| 103 | + return -1; | |
| 104 | + }; | |
| 120 | 105 | |
| 121 | - //上下行GPS容器 | |
| 122 | - $.each(data, function () { | |
| 123 | - this.gpsUps = []; | |
| 124 | - this.gpsDowns = []; | |
| 125 | - }); | |
| 126 | - return data; | |
| 106 | + var get_station_code = function (s) { | |
| 107 | + return s.stationCode + '_' + s.directions; | |
| 127 | 108 | }; |
| 128 | 109 | |
| 129 | - var filterByAttrs = function (svgAttr, routes) { | |
| 130 | - var hideStations = svgAttr.hideStations ? svgAttr.hideStations : []; | |
| 131 | - var nicknames = svgAttr.nicknames ? svgAttr.nicknames : {}; | |
| 132 | - var stationCode; | |
| 133 | - $.each(routes, function (i) { | |
| 134 | - stationCode = this.stationCode | |
| 135 | - //要隐藏的站点 | |
| 136 | - $.each(hideStations, function (j, hide) { | |
| 137 | - if (stationCode == hide) | |
| 138 | - delete routes[i]; | |
| 139 | - }); | |
| 140 | - | |
| 141 | - //要重命名的站点 | |
| 142 | - if (nicknames[this.stationName]) { | |
| 143 | - this.stationName = nicknames[this.stationName]; | |
| 110 | + var use_chart_config = function (isEnable, lineCode, rs) { | |
| 111 | + if (isEnable) { | |
| 112 | + var config = gb_data_basic.getSvgAttr(lineCode); | |
| 113 | + if (config) { | |
| 114 | + rs[0] = filterByAttr(config, rs[0]); | |
| 115 | + rs[1] = filterByAttr(config, rs[1]); | |
| 144 | 116 | } |
| 145 | - }); | |
| 146 | - | |
| 117 | + } | |
| 118 | + //路由首尾标记一下 | |
| 119 | + rs[0][0].stationMark='B'; | |
| 120 | + rs[0][rs[0].length-1].stationMark='E'; | |
| 121 | + rs[1][0].stationMark='B'; | |
| 122 | + rs[1][rs[1].length-1].stationMark='E'; | |
| 123 | + }; | |
| 124 | + | |
| 125 | + var filterByAttr = function (svgAttr, rs) { | |
| 126 | + var hsArray = svgAttr.hideStations ? svgAttr.hideStations : []; | |
| 127 | + var nsArray = svgAttr.nicknames ? svgAttr.nicknames : {}; | |
| 147 | 128 | var newRoutes = []; |
| 148 | - $.each(routes, function (i, station) { | |
| 149 | - if(station) | |
| 150 | - newRoutes.push(station); | |
| 151 | - }); | |
| 152 | 129 | |
| 130 | + for (var i = 0, s; s = rs[i++];) { | |
| 131 | + if (isHidden(s.stationCode, hsArray)) | |
| 132 | + return; | |
| 133 | + | |
| 134 | + if (nsArray[s.stationName]) | |
| 135 | + s.stationName = nsArray[s.stationName]; | |
| 136 | + | |
| 137 | + newRoutes.push(s); | |
| 138 | + } | |
| 153 | 139 | return newRoutes; |
| 154 | 140 | }; |
| 155 | 141 | |
| 156 | - var upSort = function (a, b) { | |
| 157 | - return a.stationRouteCode - b.stationRouteCode; | |
| 158 | - }; | |
| 142 | + var isHidden = function (code, array) { | |
| 143 | + for (var i = 0, temp; temp = array[i++];) { | |
| 144 | + if (code == temp) | |
| 145 | + return true; | |
| 146 | + } | |
| 159 | 147 | |
| 160 | - var downSort = function (a, b) { | |
| 161 | - return b.stationRouteCode - a.stationRouteCode; | |
| 148 | + return false; | |
| 162 | 149 | }; |
| 163 | 150 | |
| 164 | - var station_indexof = function (array, station, start) { | |
| 165 | - var res = -1; | |
| 166 | - for (var i = start, obj; obj = array[i++];) { | |
| 167 | - if (obj.stationName == station.stationName) { | |
| 168 | - res = i; | |
| 169 | - break; | |
| 170 | - } | |
| 151 | + var sort_station_route = function (routes) { | |
| 152 | + try{ | |
| 153 | + routes[0].sort(upSort); | |
| 154 | + routes[1].sort(downSort); | |
| 155 | + }catch (e){ | |
| 156 | + console.log(e); | |
| 157 | + notify_err('有站点路由数据异常!'); | |
| 171 | 158 | } |
| 172 | - return res; | |
| 173 | 159 | }; |
| 174 | 160 | |
| 175 | - var get_station_code = function (station) { | |
| 176 | - return station.stationCode + '_' + station.directions; | |
| 161 | + var upSort = function (a, b) { | |
| 162 | + return a.stationRouteCode - b.stationRouteCode; | |
| 177 | 163 | }; |
| 178 | 164 | |
| 179 | - var nvl_get = function (list, index) { | |
| 180 | - return list[index] == null ? {} : list[index]; | |
| 165 | + var downSort = function (a, b) { | |
| 166 | + return b.stationRouteCode - a.stationRouteCode; | |
| 181 | 167 | }; |
| 182 | 168 | |
| 183 | 169 | var groupByStationAndUpdown = function (data) { |
| 184 | - //gb_common.groupBy(data, 'stopNo') | |
| 185 | - var rs = {}, | |
| 186 | - key; | |
| 170 | + var rs = {}, key; | |
| 187 | 171 | $.each(data, function () { |
| 188 | 172 | key = this['stopNo'] + '_' + this['upDown']; |
| 189 | 173 | if (!rs[key]) | ... | ... |
src/main/resources/static/real_control_v2/js/utils/svg_data_convert_bf.js
0 → 100644
| 1 | +var gb_svg_data_convert = (function () { | |
| 2 | + | |
| 3 | + /** | |
| 4 | + * 合并上下行路由 | |
| 5 | + * type 0 上行 1 下行 2 同名合并 3 异名合并 | |
| 6 | + * | |
| 7 | + * enableAttr: 是否启用配置信息 | |
| 8 | + */ | |
| 9 | + function mergeRoute(routes, enableAttr, lineCode, loopLine) { | |
| 10 | + console.log('routesroutes', routes); | |
| 11 | + //按上下行拆分 | |
| 12 | + routes = gb_common.groupBy(routes, 'directions'); | |
| 13 | + var up = routes[0], | |
| 14 | + down = routes[1]; | |
| 15 | + //排序 | |
| 16 | + up.sort(upSort); | |
| 17 | + down.sort(downSort); | |
| 18 | + var data = []; | |
| 19 | + | |
| 20 | + //根据配置处理一下数据 | |
| 21 | + if (enableAttr) { | |
| 22 | + var svgAttr = gb_data_basic.getSvgAttr(lineCode); | |
| 23 | + if (svgAttr) { | |
| 24 | + up = filterByAttrs(svgAttr, up); | |
| 25 | + down = filterByAttrs(svgAttr, down); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + //环线 只画上行 | |
| 30 | + if(loopLine){ | |
| 31 | + for (var j = 0; j < up.length; j++) { | |
| 32 | + var upS = nvl_get(up, j); | |
| 33 | + op = { | |
| 34 | + name: [upS.stationName], | |
| 35 | + id: [get_station_code(upS)], | |
| 36 | + type: 0, | |
| 37 | + stationMark: upS.stationMark | |
| 38 | + }; | |
| 39 | + data.push(op); | |
| 40 | + } | |
| 41 | + | |
| 42 | + //上下行GPS容器 | |
| 43 | + $.each(data, function () { | |
| 44 | + this.gpsUps = []; | |
| 45 | + this.gpsDowns = []; | |
| 46 | + }); | |
| 47 | + | |
| 48 | + return data; | |
| 49 | + } | |
| 50 | + | |
| 51 | + | |
| 52 | + //同名站点合并 | |
| 53 | + for (var j = 0; j < up.length; j++) { | |
| 54 | + var upS = nvl_get(up, j), | |
| 55 | + downS = nvl_get(down, j), | |
| 56 | + op = { | |
| 57 | + name: [upS.stationName], | |
| 58 | + id: [get_station_code(upS), get_station_code(downS)], | |
| 59 | + type: 2, | |
| 60 | + stationMark: upS.stationMark//站点标记 | |
| 61 | + }; | |
| 62 | + | |
| 63 | + if (upS.stationName != downS.stationName) { | |
| 64 | + //下行站点在上行路由中是否存在 | |
| 65 | + var dIndex = station_indexof(down, upS, j); | |
| 66 | + //上行站点在下行路由中是否存在 | |
| 67 | + var uIndex = station_indexof(up, downS, j); | |
| 68 | + if (dIndex == -1 || dIndex - j > 4) { | |
| 69 | + if (uIndex == -1 && dIndex - j < 4) { | |
| 70 | + op.type = 3; | |
| 71 | + op.name = [upS.stationName, downS.stationName]; | |
| 72 | + } | |
| 73 | + else { | |
| 74 | + op.type = 0; | |
| 75 | + op.id = [get_station_code(upS), -1]; | |
| 76 | + //占位 | |
| 77 | + down.splice(j, 0, {}); | |
| 78 | + } | |
| 79 | + } else { | |
| 80 | + for (var t = j; t < dIndex - 1; t++) { | |
| 81 | + var temp = down[t]; | |
| 82 | + data.push({ | |
| 83 | + name: [temp.stationName], | |
| 84 | + type: 1, | |
| 85 | + id: [get_station_code(temp)] | |
| 86 | + }); | |
| 87 | + } | |
| 88 | + //delete | |
| 89 | + down.splice(j, dIndex - 1 - j); | |
| 90 | + j--; | |
| 91 | + continue; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + data.push(op); | |
| 95 | + } | |
| 96 | + | |
| 97 | + //将上下行挨着的异名站点合并 | |
| 98 | + var len = data.length - 1, | |
| 99 | + first, sec; | |
| 100 | + for (var s = 0; s < len; s++) { | |
| 101 | + first = data[s]; | |
| 102 | + sec = data[s + 1]; | |
| 103 | + | |
| 104 | + if (first.type == 0 && | |
| 105 | + sec.type == 1) { | |
| 106 | + data.splice(s, 2, { | |
| 107 | + name: [first['name'][0], sec['name'][0]], | |
| 108 | + type: 3, | |
| 109 | + id: [first['id'][0], sec['id'][0]] | |
| 110 | + }); | |
| 111 | + len--; | |
| 112 | + } else if (first.type == 1 && sec.type == 0) { | |
| 113 | + data.splice(s, 2, { | |
| 114 | + name: [first['name'][0], sec['name'][0]], | |
| 115 | + type: 3, | |
| 116 | + id: [first['id'][0], sec['id'][0]] | |
| 117 | + }); | |
| 118 | + len--; | |
| 119 | + } | |
| 120 | + } | |
| 121 | + | |
| 122 | + //上下行GPS容器 | |
| 123 | + $.each(data, function () { | |
| 124 | + this.gpsUps = []; | |
| 125 | + this.gpsDowns = []; | |
| 126 | + }); | |
| 127 | + return data; | |
| 128 | + }; | |
| 129 | + | |
| 130 | + var filterByAttrs = function (svgAttr, routes) { | |
| 131 | + var hideStations = svgAttr.hideStations ? svgAttr.hideStations : []; | |
| 132 | + var nicknames = svgAttr.nicknames ? svgAttr.nicknames : {}; | |
| 133 | + var stationCode; | |
| 134 | + $.each(routes, function (i) { | |
| 135 | + stationCode = this.stationCode | |
| 136 | + //要隐藏的站点 | |
| 137 | + $.each(hideStations, function (j, hide) { | |
| 138 | + if (stationCode == hide) | |
| 139 | + delete routes[i]; | |
| 140 | + }); | |
| 141 | + | |
| 142 | + //要重命名的站点 | |
| 143 | + if (nicknames[this.stationName]) { | |
| 144 | + this.stationName = nicknames[this.stationName]; | |
| 145 | + } | |
| 146 | + }); | |
| 147 | + | |
| 148 | + var newRoutes = []; | |
| 149 | + $.each(routes, function (i, station) { | |
| 150 | + if(station) | |
| 151 | + newRoutes.push(station); | |
| 152 | + }); | |
| 153 | + | |
| 154 | + return newRoutes; | |
| 155 | + }; | |
| 156 | + | |
| 157 | + var upSort = function (a, b) { | |
| 158 | + return a.stationRouteCode - b.stationRouteCode; | |
| 159 | + }; | |
| 160 | + | |
| 161 | + var downSort = function (a, b) { | |
| 162 | + return b.stationRouteCode - a.stationRouteCode; | |
| 163 | + }; | |
| 164 | + | |
| 165 | + var station_indexof = function (array, station, start) { | |
| 166 | + var res = -1; | |
| 167 | + for (var i = start, obj; obj = array[i++];) { | |
| 168 | + if (obj.stationName == station.stationName) { | |
| 169 | + res = i; | |
| 170 | + break; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + return res; | |
| 174 | + }; | |
| 175 | + | |
| 176 | + var get_station_code = function (station) { | |
| 177 | + return station.stationCode + '_' + station.directions; | |
| 178 | + }; | |
| 179 | + | |
| 180 | + var nvl_get = function (list, index) { | |
| 181 | + return list[index] == null ? {} : list[index]; | |
| 182 | + }; | |
| 183 | + | |
| 184 | + var groupByStationAndUpdown = function (data) { | |
| 185 | + //gb_common.groupBy(data, 'stopNo') | |
| 186 | + var rs = {}, | |
| 187 | + key; | |
| 188 | + $.each(data, function () { | |
| 189 | + key = this['stopNo'] + '_' + this['upDown']; | |
| 190 | + if (!rs[key]) | |
| 191 | + rs[key] = []; | |
| 192 | + | |
| 193 | + rs[key].push(this); | |
| 194 | + }); | |
| 195 | + | |
| 196 | + return rs; | |
| 197 | + }; | |
| 198 | + return {mergeRoute: mergeRoute, groupByStationAndUpdown: groupByStationAndUpdown}; | |
| 199 | +})(); | ... | ... |
src/main/resources/static/real_control_v2/js/utils/svg_data_convert_cx.js deleted
100644 → 0
| 1 | -var gb_svg_data_convert = (function () { | |
| 2 | - | |
| 3 | - /** | |
| 4 | - * 合并上下行路由 | |
| 5 | - * type 0 上行 1 下行 2 同名合并 3 异名合并 | |
| 6 | - * | |
| 7 | - * enableAttr: 是否启用配置信息 | |
| 8 | - */ | |
| 9 | - function mergeRoute(rs, enableAttr, lineCode, loopLine) { | |
| 10 | - //按上下行拆分 | |
| 11 | - rs = gb_common.groupBy(rs, 'directions'); | |
| 12 | - //排序 | |
| 13 | - sort_station_route(rs); | |
| 14 | - //模拟图配置信息 | |
| 15 | - use_chart_config(enableAttr, lineCode, rs); | |
| 16 | - | |
| 17 | - var data = [].concat(rs[0]); | |
| 18 | - | |
| 19 | - | |
| 20 | - return data; | |
| 21 | - } | |
| 22 | - | |
| 23 | - var use_chart_config = function (isEnable, lineCode, rs) { | |
| 24 | - if (isEnable) { | |
| 25 | - var config = gb_data_basic.getSvgAttr(lineCode); | |
| 26 | - if (config) { | |
| 27 | - rs[0] = filterByAttr(config, rs[0]); | |
| 28 | - rs[1] = filterByAttr(config, rs[1]); | |
| 29 | - } | |
| 30 | - } | |
| 31 | - }; | |
| 32 | - | |
| 33 | - var filterByAttr = function (svgAttr, rs) { | |
| 34 | - var hsArray = svgAttr.hideStations ? svgAttr.hideStations : []; | |
| 35 | - var nsArray = svgAttr.nicknames ? svgAttr.nicknames : {}; | |
| 36 | - var newRoutes = []; | |
| 37 | - | |
| 38 | - for (var i = 0, s; s = rs[i++];) { | |
| 39 | - if (isHidden(s.stationCode, hsArray)) | |
| 40 | - return; | |
| 41 | - | |
| 42 | - if (nsArray[s.stationName]) | |
| 43 | - s.stationName = nsArray[s.stationName]; | |
| 44 | - | |
| 45 | - newRoutes.push(s); | |
| 46 | - } | |
| 47 | - return newRoutes; | |
| 48 | - }; | |
| 49 | - | |
| 50 | - var isHidden = function (code, array) { | |
| 51 | - for (var i = 0, temp; temp = array[i++];) { | |
| 52 | - if (code == temp) | |
| 53 | - return true; | |
| 54 | - } | |
| 55 | - | |
| 56 | - return false; | |
| 57 | - }; | |
| 58 | - | |
| 59 | - var sort_station_route = function (routes) { | |
| 60 | - try{ | |
| 61 | - routes[0].sort(upSort); | |
| 62 | - routes[1].sort(downSort); | |
| 63 | - }catch (e){ | |
| 64 | - console.log(e); | |
| 65 | - notify_err('有站点路由数据异常!'); | |
| 66 | - } | |
| 67 | - }; | |
| 68 | - | |
| 69 | - var upSort = function (a, b) { | |
| 70 | - return a.stationRouteCode - b.stationRouteCode; | |
| 71 | - }; | |
| 72 | - | |
| 73 | - var downSort = function (a, b) { | |
| 74 | - return b.stationRouteCode - a.stationRouteCode; | |
| 75 | - }; | |
| 76 | - | |
| 77 | - | |
| 78 | - var nvl_get = function (list, index) { | |
| 79 | - return list[index] == null ? {} : list[index]; | |
| 80 | - }; | |
| 81 | - | |
| 82 | - var groupByStationAndUpdown = function (data) { | |
| 83 | - var rs = {}, key; | |
| 84 | - $.each(data, function () { | |
| 85 | - key = this['stopNo'] + '_' + this['upDown']; | |
| 86 | - if (!rs[key]) | |
| 87 | - rs[key] = []; | |
| 88 | - | |
| 89 | - rs[key].push(this); | |
| 90 | - }); | |
| 91 | - | |
| 92 | - return rs; | |
| 93 | - }; | |
| 94 | - return {mergeRoute: mergeRoute, groupByStationAndUpdown: groupByStationAndUpdown}; | |
| 95 | -})(); |