-
Notifications
You must be signed in to change notification settings - Fork 3
/
makeRoute.html
397 lines (369 loc) · 22.1 KB
/
makeRoute.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<!-- Made by Penguin -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>makeRoute.html</title>
<link rel="stylesheet" href="./assets/styles/styles.css">
</head>
<body class="pg-app" id="pg-app">
<div class="mask collapse" id="mask"></div>
<nav class="nav-head">
<div class="container show" id="pg-app-head">
<div class="nav-description" id="CurrentRoute"><span>广州地铁指南</span></div>
</div>
</nav>
<div class="pg-app-wrap" id="pg-app-wrap">
<div class="main-content routeinfo">
<div id="routeinfWrap">
<div class="inner">
<div class="p_content">
<div class="innerData" id="routeInformation">
<div class="leftpane" id="left-pane">
</div>
<div class="rightpane" id="right-pane">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- BOTTOM NAV -->
<nav class="nav-bottom" id="pg-app-bottom">
<ul>
<li pg-target="home" onclick="window.location.href='index.html?type=index'"><span>home</span><span
class="description">Home</span>
</li>
<li pg-target="info" onclick="window.location.href='index.html?type=stationinfo'"><span>info</span><span
class="description">Info</span>
</li>
<li pg-target="map" onclick="window.location.href='routeMap.html'"><span class="active">map</span><span
class="description">Routemap</span></li>
<li pg-target="settings" onclick="window.location.href='index.html?type=account'"><span>settings</span><span
class="description">Settings</span>
</li>
</ul>
</nav>
</body>
<script src="./assets/data/map.js"></script>
<script src="./assets/data/interchanges.js"></script>
<script src="./assets/data/fullstationlog.js"></script>
<script src="./assets/data/convertStoN.js"></script>
<script src="./assets/strings/string.js"></script>
<script src="./assets/scripts/require.lib.js"></script>
<script>
let Graph = (function (undefined) {
let extractKeys = function (obj) {
let keys = [], key;
for (key in obj) {
Object.prototype.hasOwnProperty.call(obj, key) && keys.push(key);
}
return keys;
};
let sorter = function (a, b) {
return parseFloat(a) - parseFloat(b);
};
let findPaths = function (map, start, end, infinity) {
infinity = infinity || Infinity;
let costs = {},
open = {'0': [start]},
predecessors = {},
keys;
let addToOpen = function (cost, vertex) {
let key = "" + cost;
if (!open[key]) open[key] = [];
open[key].push(vertex);
};
costs[start] = 0;
while (open) {
if (!(keys = extractKeys(open)).length) break;
keys.sort(sorter);
let key = keys[0],
bucket = open[key],
node = bucket.shift(),
currentCost = parseFloat(key),
adjacentNodes = map[node] || {};
if (!bucket.length) delete open[key];
for (let vertex in adjacentNodes) {
if (Object.prototype.hasOwnProperty.call(adjacentNodes, vertex)) {
let cost = adjacentNodes[vertex][0],
totalCost = cost + currentCost,
vertexCost = costs[vertex];
if ((vertexCost === undefined) || (vertexCost > totalCost)) {
costs[vertex] = totalCost;
addToOpen(totalCost, vertex);
predecessors[vertex] = node;
}
}
}
}
if (costs[end] === undefined) {
return null;
} else {
return predecessors;
}
};
let extractShortest = function (predecessors, end) {
let nodes = [],
u = end;
while (u !== undefined) {
nodes.push(u);
u = predecessors[u];
}
nodes.reverse();
return nodes;
};
let findShortestPath = function (map, nodes) {
let start = nodes.shift(),
end,
predecessors,
path = [],
shortest;
while (nodes.length) {
end = nodes.shift();
predecessors = findPaths(map, start, end);
if (predecessors) {
shortest = extractShortest(predecessors, end);
if (nodes.length) {
path.push.apply(path, shortest.slice(0, -1));
} else {
return path.concat(shortest);
}
} else {
return null;
}
start = end;
}
};
let toArray = function (list, offset) {
try {
return Array.prototype.slice.call(list, offset);
} catch (e) {
let a = [];
for (let i = offset || 0, l = list.length; i < l; ++i) {
a.push(list[i]);
}
return a;
}
};
let Graph = function (map) {
this.map = map;
};
Graph.prototype.findShortestPath = function (start, end) {
if (Object.prototype.toString.call(start) === '[object Array]') {
return findShortestPath(this.map, start);
} else if (arguments.length === 2) {
return findShortestPath(this.map, [start, end]);
} else {
return findShortestPath(this.map, toArray(arguments));
}
};
Graph.findShortestPath = function (map, start, end) {
if (Object.prototype.toString.call(start) === '[object Array]') {
return findShortestPath(map, start);
} else if (arguments.length === 3) {
return findShortestPath(map, [start, end]);
} else {
return findShortestPath(map, toArray(arguments, 1));
}
};
return Graph;
})();
getRoute = (start, end) => {
let calc = (start, end, map) => {
let s = [], e = [], res = [], restime = [];
if (typeof start === "object")
s = start;
else s = [start];
if (typeof end === "object")
e = end;
else e = [end];
s.forEach(a => {
e.forEach(b => {
let t = 0, r = new Graph(n_map).findShortestPath(a, b);
for (let i = 0; i < r.length - 1; i++)
t += n_map[r[i]][r[i + 1]][0];
restime.push(t);
res.push(r);
});
});
let g = res[restime.indexOf(Math.min.apply(null, restime))];
let time = 0, length = 0, booleanAPM = false, booleanTramHZ = false, priceLength = 0, price = 0;
for (let i = 0; i < g.length - 1; i++) {
g[i] = Int(g[i]);
time += map[g[i]][g[i + 1]][0];
length += map[g[i]][g[i + 1]][1];
priceLength += map[g[i]][g[i + 1]][1];
if (g[i] >= 266 && g[i] <= 274) {
if (!booleanAPM)
price += 2;
priceLength -= map[g[i]][g[i + 1]][1];
} else if (g[i] >= 275 && g[i] <= 286) {
if (!booleanTramHZ)
price += 2;
priceLength -= map[g[i]][g[i + 1]][1];
}
}
return [g, time, length, calcPrice(priceLength) + price];
};
let calcPrice = (distance) => {
return distance <= 4000 ? 2 : distance <= 12000 ? 2 + 4 * Math.round((distance - 4000) / 4000) : distance <= 24000 ? 5 + Math.round((distance - 12000) / 6000) : 7 + Math.round((distance - 24000) / 8000);
};
let result = calc(start, end, n_map);
let processSameRoute = () => {
let res = [result[0][0]], partTime = [0], partDistance = [0], routeDiretion = [], sepStation = [[]];
let num = [0], k = 0, d = 0, g = 0, h = 1, p = 0;
routeDiretion.push((result[0][0] > result[0][1] ? result[0][0] - 1 !== result[0][1] : result[0][0] + 1 !== result[0][1]) ? 0 : 1);
for (let i = 0; i < result[0].length - 1; i++) {
if (result[0][i] > result[0][i + 1] ? result[0][i] - 1 !== result[0][i + 1] : result[0][i] + 1 !== result[0][i + 1]) {
k++;
d++;
g++;
h++;
p++;
num.push(0);
partTime.push(0);
partDistance.push(0);
routeDiretion.push(((result[0][i + 1] + 1 === result[0][i + 2]) ? 0 : 1));
res.push([result[0][i], result[0][i + 1]]);
sepStation.push([]);
} else {
num[k] = num[k] + 1;
partTime[k] += n_map[result[0][i]][result[0][i + 1]][0];
partDistance[k] += n_map[result[0][i]][result[0][i + 1]][1];
sepStation[p].push(result[0][i + 1]);
}
}
for (let i = 1; i < res.length; i++)
for (let j = 0; j < n_interchanges.length; j++)
if (n_interchanges[j].indexOf(res[i]) !== -1) {
res[i] = [res[i][0], res[i][1]];
}
res.push(result[0][result[0].length - 1]);
return [res, num, partTime, partDistance, routeDiretion, sepStation];
};
return [result, processSameRoute()];
};
getBelong = (id) => {
let res = id >= 0 && id <= 15 ? "1" : id >= 16 && id <= 39 ? "2" : id >= 40 && id <= 55 ? "3" : id >= 56 && id <= 70 ? "3N" : id >= 71 && id <= 94 ? "4" : id >= 95 && id <= 118 ? "5" : id >= 119 && id <= 150 ? "6" : id >= 151 && id <= 159 ? "7" : (id >= 160 && id <= 174) || (id >= 286 && id <= 298) ? "8" : id >= 175 && id <= 185 ? "9" : id >= 186 && id <= 196 ? "13" : id >= 197 && id <= 209 ? "14" : id >= 210 && id <= 219 ? "KCL" : id >= 210 && id <= 240 ? "21" : id >= 241 && id <= 265 ? "GF" : id >= 266 && id <= 274 ? "APM" : id >= 275 && id <= 285 ? "THZ1" : "8";
let name = ["1", "2", "3", "3N", "4", "5", "6", "7", "8", "9", "13", "14", "KCL", "21", "GF", "APM", "THZ1"],
gn = ["Line1-GZ", "Line2-GZ", "Line3-GZ", "Line3-GZ", "Line4-GZ", "Line5-GZ", "Line6-GZ", "Line7-GZ", "Line8-GZ", "Line9-GZ", "Line13-GZ", "Line14-GZ", "Line14-GZ", "Line21-GZ", "Line-GF", "LineAPM-GZ", "THZ1-GZ"],
line = [1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 13, 14, 14, 21, "GF", "APM", "THZ1"];
return [res, gn[name.indexOf(res)], line[name.indexOf(res)], name.indexOf(res)];
};
processResult = (start, end) => {
routedirection = [[["廣州東站方向", "西塱方向"], ["广州东站方向", "西塱方向"], ["広州東駅方面", "西塱方面"], ["광저우 동역까지", "서쪽"], ["To Guangzhou E. Railway Station", "To Xilang"]], [["嘉禾望崗方向", "廣州南站方向"], ["嘉禾望岗方向", "广州南站方向"], ["嘉禾望崗方面", "広州南駅方面"], ["지아 왕강 지역", "루 저우 남 지역"], ["To Jiahe Wanggang", "To Guangzhou S. Railway Station"]], [["天河客運站方向", "機場北方向", "機場北/天河客運站方向", "體育西路方向", "番禺廣場方向", "體育西路/番禺廣場方向"], ["天河客运站方向", "机场北方向", "机场北/天河客运站方向", "体育西路方向", "番禺广场方向", "体育西路/番禺广场方向"], ["天河客運站方面", "空港北方面", "空港北方面/天河客運站方面", "体育西路方面", "番禺広場方面", "体育西路/番禺広場方面"], ["톈허 여객 터미널", "공항 북쪽", "공항 북쪽 / 톈허 여객 터미널", "톈 위서로", "판위 스퀘어", "톈 위서로 / 판위 스퀘어"], ["To Tinahe Coach Terminal", "To Airport N.", "To Airport N./Tianhe Coach Terminal", "To Tiyu Xilu", "To Panyu Square", "To Tiyu Xilu/Panyu Square"]], [["黃村方向", "南沙客運港方向"], ["黄村方向", "南沙客运港方向"], ["黃村方面", "南沙客運港方面"], ["후앙 쿤 지역", "난샤 여객 항구 지역"], ["To Huangcun", "To Nansha Passenger Port"]], [["文沖方向", "滘口方向", "三溪方向"], ["文冲方向", "滘口方向", "三溪方向"], ["文沖方面", "滘口方面", "三溪方面"], ["원 종 측면", "이코 우 측면", "산시 역 측면"], ["To Wenchong", "To Jiaokou", "To Sanxi"]], [["香雪方向", "潯峰崗方向"], ["香雪方向", "浔峰岗方向"], ["香雪方面", "潯峰崗方面"], ["향설 ", "심봉초"], ["To Xiangxue", "To Xunfenggang"]], [["大學城南方向", "廣州南站方向"], ["大学城南方向", "广州南站方向"], ["大學城南方面", "広州南駅方面"], ["대학교 도시의 남쪽 측면", "광저우 남역"], ["To Higher Education Mega Center S.", "To Guangzhou S. Railway Station"]], [["文化公園方向", "萬勝圍方向"], ["文化公园方向", "万胜围方向"], ["文化公園方面", "萬勝圍方面"], ["문화 공원", "완성 웨이"], ["To Cultural Park", "To Wanshengwei"]], [["高增方向", "飛鵝嶺方向"], ["高增方向", "飞鹅岭方向"], ["高增方面", "飛鵝嶺方面"], ["고성장 지역", "페이 게링 지역"], ["To Gaozeng", "To Fei'eling"]], [["新沙方向", "魚珠方向"], ["新沙方向", "鱼珠方向"], ["新沙方面", "魚珠方面"], ["신샤 지역", "물고기 구슬 지역"], ["To Xinsha", "To Yuzhu"]], [["東風方向", "鎮龍方向", "嘉禾望崗方向", "新和方向"], ["东风方向", "镇龙方向", "嘉禾望岗方向", "新和方向"], ["東風方面", "鎮龍方面", "嘉禾望崗方面", "新和方面"], ["동풍 방향", "정룽 방향", "지애 왕강 방향", "신와 방향"], ["To Dongfeng", "To Zhenlong", "To Jiahe Wanggang", "To Xinhe"]], [["增城廣場方向", "員村方向"], ["增城广场方向", "员村方向"], ["增城広場方面", "員村方面"], ["정청 광장으로가는 길", "위안 쿤으로가는 길"], ["To Zengcheng Square", "To Yuancun"]], [["瀝滘方向", "新城東方向"], ["沥滘方向", "新城东方向"], ["瀝滘方面", "新城東方面"], ["릴리의 방향으로", "도시의 동쪽으로"], ["To Lijiao", "To Xincheng Dong"]], [["林和西方向", "廣州塔方向"], ["林和西方向", "广州塔方向"], ["林和西方面", "広州タワー方面"], ["린 허시 지역", "광저우 타워 지역"], ["To Linhexi", "To Canton Tower"]], [["廣州塔方向", "萬勝圍方向"], ["广州塔方向", "万胜围方向"], ["広州タワー方面", "萬勝圍方面"], ["광저우 타워 지역", "완성 웨이"], ["To Canton Tower", "To Wanshengwei"]]];
let processNumber = (num) => {
return num < 10 ? ("0" + num).toString() : num.toString();
};
let route = getRoute(start, end);
let time = route[0][1], length = route[0][2], price = route[0][3], inter = route[1][0], num = route[1][1],
partTime = route[1][2], partDistance = route[1][3], routeDirection = route[1][4], sepStation = route[1][5];
start = route[0][0][0];
end = route[0][0][route[0][0].length - 1];
$("#CurrentRoute")[0].innerText = n_res_2[start][cL].split(cL === 2 ? "-" : "undefined")[0] + " -> " + n_res_2[end][cL].split(cL === 2 ? "-" : "undefined")[0] + " " + string.aboutTime[cL] + time + " " + string.Minute[cL];
let id = [1, -15, -39, -39, -70, -94, -118, -150, -159, -174, -185, -196, -196, -219, -240, -265, -274];
let lp = $("#left-pane")[0];
let rp = $("#right-pane")[0];
lp.innerHTML = rp.innerHTML = "";
for (let i = 0; i < inter.length - 1; i++) {
let belong = i === 0 ? getBelong(inter[i]) : [getBelong(inter[i][0]), getBelong(inter[i][1])];
lp.appendChild(cE({type: "div", attr: [["class", "tripOrigin"]]}));
let line = cE({type: "div", attr: [["class", "border-" + (i === 0 ? belong[1] : belong[1][1])]]});
if (i !== 0) line.classList.add("longer");
lp.appendChild(line);
let station = cE({
type: "h4",
innerText: i === 0 ? n_res_2[inter[i]][cL].split(cL === 2 ? "-" : "undefined")[0] : n_res_2[inter[i][0]][cL].split(cL === 2 ? "-" : "undefined")[0]
});
if (i !== 0) {
let a = inter[i][0];
let b = inter[i][1];
if (a >= 286 && a <= 298)
a -= 126;
if (b >= 286 && b <= 298)
b -= 126;
a = Int(processNumber((a + id[belong[0][3]])));
b = Int(processNumber((b + id[belong[1][3]])));
let num = [Int(processNumber((inter[i][0] + id[belong[0][3]]))), Int(processNumber((inter[i][1] + id[belong[1][3]])))];
if (Int(num[0]) === 14 && belong[0][0] === "KCL") num[0] = "8";
if (Int(num[0]) === 17 && belong[0][0] === "3N") num[0] = "11";
if (Int(num[1]) === 14 && belong[1][0] === "KCL") num[1] = "8";
if (Int(num[1]) === 17 && belong[1][0] === "3N") num[1] = "11";
station.innerHTML += processPill(belong[0][2], a, belong[0][1]) + processPill(belong[1][0], b, belong[1][1]);
rp.appendChild(station);
let des = cE({
type: "p",
innerText: string.interchangeCost[cL] + " " + n_map[inter[i][0]][inter[i][1]][0] + string.Minute[cL]
});
rp.appendChild(des);
} else {
let num = Int(processNumber(inter[i] + id[belong[3]]));
if (Int(num) === 14 && belong[0] === "KCL") num = "8";
if (Int(num) === 17 && belong[0] === "3N") num = "11";
station.innerHTML += processPill(belong[2], num, belong[1]);
rp.appendChild(station);
}
let rd = routedirection[globallist.indexOf(i === 0 ? belong[1] : belong[1][1])][cL][routeDirection[i]];
if (belong[0] === "3N") rd = routedirection[globallist.indexOf(i === 0 ? belong[1] : belong[1][1])][cL][routeDirection[i] === 0 ? 1 : 3];
else if (belong[0] === "3") rd = routedirection[globallist.indexOf(i === 0 ? belong[1] : belong[1][1])][cL][routeDirection[i] === 0 ? 0 : 4];
else if (belong[0] === "14") rd = routedirection[globallist.indexOf(i === 0 ? belong[1] : belong[1][1])][cL][routeDirection[i] === 0 ? 0 : 2];
else if (belong[0] === "KCL") rd = routedirection[globallist.indexOf(i === 0 ? belong[1] : belong[1][1])][cL][routeDirection[i] === 0 ? 3 : 1];
let html = "<p><span class='border-" + (i === 0 ? belong[1] : belong[1][1]) + "'>" + (i === 0 ? belong[0] : belong[1][0]) + "</span>" + rd + "</p><p><span class='expandIcon'></span>" + num[i] + [" 個站,", " 个站,", " 駅、", " 역 ", " station(s), "][cL] + partTime[i] + [" 分鐘, 共 ", " 分钟, 共 ", " 分、 ", " 분 ", " min, "][cL] + (partDistance[i] / 1000) + " km</p><div id='showmore_" + i + "' style='display: none'>";
for (let t = 0; t < sepStation[i].length; t++)
html += "<p>" + n_res_2[sepStation[i][t]][cL].split(cL === 2 ? "-" : "undefined")[0] + "</p>";
let numbox = cE({
type: "div",
innerHTML: html + "<p>" + string.operatedNy[cL] + "</p></div>",
attr: [["class", "border-" + (i === 0 ? belong[1] : belong[1][1]) + " numbox"]]
});
numbox.onclick = function () {
let toggle = $("#showmore_" + i)[0];
if (numbox.getAttribute("aria-expanded") !== "true") {
toggle.style.display = "unset";
numbox.setAttribute("aria-expanded", "true");
let line = $("#left-pane")[0].children[1 + 2 * i];
if (line.classList.contains("longer"))
line.setAttribute("style", "height:" + (150 + 32.5 * ($("#showmore_" + i)[0].children.length) + "px"));
else
line.setAttribute("style", "height:" + (135 + 31 * ($("#showmore_" + i)[0].children.length) + "px"));
} else {
toggle.style.display = "none";
numbox.setAttribute("aria-expanded", "false");
$("#left-pane")[0].children[1 + 2 * i].setAttribute("style", "");
}
};
rp.appendChild(numbox);
}
let a = inter[inter.length - 1];
if (a >= 286 && a <= 298)
a -= 126;
let belong = getBelong(inter[inter.length - 1]);
a = Int(processNumber((a + id[belong[3]])));
lp.appendChild(cE({type: "div", attr: [["class", "tripOrigin"]]}));
rp.appendChild(cE({
type: "h4",
innerHTML: n_res_2[end][cL].split(cL === 2 ? "-" : "undefined")[0] + processPill(belong[2], a, belong[1])
}));
let infWrap = $("#routeInformation")[0];
infWrap.appendChild(cE({
type: "h5",
attr: [["id", "RouteData"]],
innerText: "CN¥" + price + " , " + (length / 1000).toPrecision(2) + " km , " + time + " " + string.Minute[cL]
}));
infWrap.appendChild(cE({
type: "h5",
attr: [["id", "arrivedTime"]],
innerText: string.aboutArrived[cL] + ": " + new Date((new Date().getTime()) + 11).toLocaleTimeString()
}));
};
window.onload = function () {
loadRequire();
processResult(csn[GetPara("start")], csn[GetPara("end")]);
}
</script>
</html>