-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinnerRoute.html
361 lines (295 loc) · 13.3 KB
/
innerRoute.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"></script>
<link rel="stylesheet" href="css/L.Icon.Pulse.css" />
<script type="text/javascript" src="js/L.Icon.Pulse.js"></script>
<link rel="stylesheet" href="css/leaflet.extra-markers.min.css">
<script src="js/leaflet.extra-markers.min.js"></script>
<script type="text/javascript" src="js/Leaflet.Icon.Glyph.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/base.js"></script>
<script type="text/javascript" src="js/polyline.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
width: 100vw;
}
#realBs {
position: absolute;
z-index: 10000;
top: 15px;
right: 15px;
}
#realBs2 {
position: absolute;
z-index: 10000;
top: 80px;
right: 15px;
}
#info {
position: absolute;
z-index: 10000;
bottom: 0px;
width: 100%;
max-height: 50%;
overflow: scroll;
font-size: small;
background-color: rgba(0,0,0,0.67);
line-height: 120%;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: yellow;
}
.bsIconSub {
width: 15px;
height: 15px;
color: rgb(80, 109, 202);
font-size: larger;
font-weight: bolder;
text-align: center;
display: inline-block;
text-decoration: none;
line-height: auto;
vertical-align: middle;
}
</style>
<script>
function showMap() {
flagDemo();
//OpenStreetMapをロード
var mymap = L.map('map');
var layerGroupGn = L.layerGroup().addTo(mymap);
mymap.on('click', function(ev){
//クリア
document.getElementById('info').innerHTML = '';
//layerGroupGn.clearLayers();
});
L.control.scale({metric: true, imperial: false}).addTo(mymap);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, '
}).addTo(mymap);
let loc = localStorage.getItem('currentPosition').split(',');
var lat = loc[0];
var lng = loc[1];
mymap.setView([lat, lng], 15);
//現在地
var myLoc;
var pulsingIcon = L.icon.pulse({iconSize:[15,15],color:'#1199fb'});
if (localStorage.getItem('demoflag') == 'false') {
//現在地が取れる時
mymap.locate({watch: true});
mymap.on('locationfound', function(ev){
if (!myLoc) {
myLoc = L.marker(ev.latlng,{icon:pulsingIcon, zIndexOffset: 10000}).bindPopup('<p>現在地 (' + lat + ',' + lng + ')</p>').openPopup().addTo(mymap);
} else {
myLoc.setLatLng(ev.latlng);
//console.log(ev.latlng);
}
});
} else {
//現在地が取れない時
myLoc = L.marker([lat,lng],{icon:pulsingIcon, zIndexOffset: 10000}).bindPopup('<p>デモ現在地<br>(JR佐賀駅)' + lat + ',' + lng + ')</p>').openPopup().addTo(mymap);
}
//////////////////////////
//サブ旅程描画
//localStorageのrouteDataからデータをもらう
//getでrnが取れるので、routeData[rn]が該当
let routeData = JSON.parse(localStorage.getItem('routeData'));
//クレンジング
let param = window.location.search;
let param1 = param.split('&');
let param2 = param1[0].split('=');
let routeNum = Number(param2[1]);
if (isNaN(routeNum) || routeData.length < 1 || routeNum < 0 || routeNum >= routeData.length) {
alert('旅程の指定に失敗しました。前の画面に戻ってください。');
window.location = 'no.html';
}
//console.log(routeData[routeNum]);
//経路描画
let polylines = JSON.parse(localStorage.getItem('polyline'));
L.polyline(polylines, {color: 'dodgerblue', weight: 5}).addTo(mymap);
//バス停を入力
//stops.txt読込
var data = makeArrayForHyochu(csvToArray("busData/stops.txt"));
var cn = 1;
/////マーカー一覧
//乗るバス停
var busstopIconSub = L.divIcon({html: '<div><i class="fas fa-bus"></i></div>', className: 'bsIcon', iconSize: [20,20]});
//スタート
var busstopIconStart = L.icon.glyph({prefix: 'fa',glyph: 'dot-circle'});
//ゴール
var busstopIconGoal = L.icon.glyph({prefix: 'fa',glyph: 'flag-checkered'});
//バス停
//var busstopIcon = L.divIcon({html: '<div><i class="fas fa-bus"></i></div>', className: 'bsIcon', iconSize: [20,20]});
//var busstopIcon = L.icon.glyph({prefix: 'fa',glyph: 'bus'});
////////////////////////////////
//サブ旅程に合わせてマーカー描画
let lastSeg = (routeData[routeNum][6].length) - 1;
//スタート(出発地点)
let clatLng = localStorage.getItem('currentPosition').split(',');
L.marker(clatLng,{icon: busstopIconStart, title: '出発地点', zIndexOffset: 10010}).bindPopup('出発地点').addTo(mymap);
//中間地点
let icn = 1;
routeData[routeNum][6].forEach(function(el) {
var busstopIconSegment = L.icon.glyph({glyph: icn});
//p1区切り(出発)
let p1Label;
if (el[4] == 'Origin') {
p1Label = '出発地点';
} else {
p1Label = el[4];
}
let p1Lat = el[12];
let p1Lng = el[13];
//p1start
let p1StartTime;
if (el[5] == null || isNaN(el[5])) {
p1StartTime = routeData[routeNum][0];
} else {
p1StartTime = el[5];
}
let p1StartDate = new Date(p1StartTime);
//p1end
let p1EndTime = el[6];
let p1EndDate = new Date(p1EndTime);
//p2区切り(到着)
let p2Label;
if (el[7] == 'Destination') {
p2Label = '到着地点';
} else {
p2Label = el[7];
}
let p2Lat = el[15];
let p2Lng = el[16];
//p2start
let p2StartTime = el[8];
let p2StartDate = new Date(p2StartTime);
//p2end
let p2EndTime;
if (el[9] == null || isNaN(el[9])) {
p2EndTime = routeData[routeNum][2];
} else {
p2EndTime = el[9];
}
let p2EndDate = new Date(p2EndTime);
//let desc = el[4] + '(' + ('0' + p1StartDate.getHours()).slice(-2) + ':' + ('0' + p1StartDate.getMinutes()).slice(-2) + '出発 ' + ('0' + p1EndDate.getHours()).slice(-2) + ':' + ('0' + p1EndDate.getMinutes()).slice(-2) + '到着)<br>' + el[7] + '(' + ('0' + p2StartDate.getHours()).slice(-2) + ':' + ('0' + p2StartDate.getMinutes()).slice(-2) + '出発 ' + ('0' + p2EndDate.getHours()).slice(-2) + ':' + ('0' + p2EndDate.getMinutes()).slice(-2) + '到着)' ;
let via;
if (el[0] == 'BUS') {
via = el[11] + '<a href="' + el[3] + '" target="_blank">' + el[2] + '</a>';
} else {
via = '徒歩';
}
//かかる時間
var interval;
if (el[10] >= 60) {
interval = '(' + Math.ceil((el[10] / 60)) + '分' + ('0' + (el[10] % 60)).slice(-2) + '秒)';
} else {
interval = '(' + (el[10] % 60) + '秒)';
}
let desc = '<h3>' + p1Label + '(' + ('0' + p1EndDate.getHours()).slice(-2) + ':' + ('0' + p1EndDate.getMinutes()).slice(-2) + '発)</h3><p align="center">' + via + interval + '</p><h3>' + p2Label + '(' + ('0' + p2StartDate.getHours()).slice(-2) + ':' + ('0' + p2StartDate.getMinutes()).slice(-2) + '着)</h3>';
L.marker([p1Lat,p1Lng],{icon: busstopIconSegment, title: el[4], zIndexOffset: 10010}).bindPopup(desc).openPopup().addTo(mymap);
L.marker([p2Lat,p2Lng],{icon: busstopIconSegment, title: el[7], zIndexOffset: 10010}).bindPopup(desc).openPopup().addTo(mymap);
icn++;
});
//ゴール(到着地点)
let gLat = routeData[routeNum][6][lastSeg][15];
let gLng = routeData[routeNum][6][lastSeg][16];
let gDate = new Date(routeData[routeNum][2]);
L.marker([gLat,gLng],{icon: busstopIconGoal, title: routeData[routeNum][1], zIndexOffset: 10010}).bindPopup('<h3>' + routeData[routeNum][1] + '(' + ('0' + gDate.getHours()).slice(-2) + ':' + ('0' + gDate.getMinutes()).slice(-2) + '着)</h3>').addTo(mymap);
////////////////////////////////
//普通のバス停(時刻表つき)
var bmarkers = new Array();
while (cn < data.length) {
var latBs = data[cn][2].replace(/\"/g,'');
var lngBs = data[cn][3].replace(/\"/g,'');
var hyochu = data[cn][1].replace(/\"/g,'');
var stopid = data[cn][0].replace(/\"/g,'');
//バス停マーカー
//普通のバス停はCircle
bmarkers[cn] = L.circle([latBs,lngBs],{radius:10, color: '#ff0000', fill: true, title: stopid + ',' + hyochu}).addTo(mymap).bindPopup("<p>"+ hyochu + '</p>');
bmarkers[cn].on('click', function(ev){
document.getElementById('info').innerHTML = 'バス停データを読み込めませんでした...';
//バス停情報取得
var bstopinfoelements = this.options.title.split(',');
var bsinfo = readXML('https://summer.hori-s.net/otp/routers/default/index/stops/1:' + bstopinfoelements[0] + '/stoptimes?numberOfDepartures=10');
//バス停の停車時間
var rosenName;
var rosenTime;
var headsign2;
var schedule;
var baseDate;
var tripId;
var tripId2;
var tripData = new Array();
var scheduledArrival;
var scheduledDeparture;
var val1;
var val2;
var scheduledArrivalTime;
var scheduledDepartureTime;
var testArray = new Array();
bsinfo.forEach(function(el){
rosenName = el["pattern"]["desc"];
rosenTime = el["times"];
rosenTime.forEach(function(t) {
headsign2 = t["headsign"];
schedule = t["realtimeState"];
var schedule2;
var scheduleComment = '';
if (schedule == 'SCHEDULED' || Math.ceil(t["departureDelay"] / 60) < 1) {
schedule2 = '<span style="color: lightgreen;">定刻</span>';
} else {
schedule2 = '<span class="flash">更新</span>';
scheduleComment = Math.ceil(t["departureDelay"] / 60) + '分遅れ';
}
baseDate = t["serviceDay"];
scheduledArrival = t["scheduledArrival"]; //baseDate + scheduledArrival = 到着時刻
scheduledDeparture = t["scheduledDeparture"];
val1 = (baseDate + scheduledArrival) * 1000;
val2 = (baseDate + scheduledDeparture) * 1000;
scheduledArrivalTime = new Date(val1);
scheduledDepartureTime = new Date(val2);
tripId = t["tripId"];
tripId2 = tripId.split(':');
let vehicleAgency;
if (tripId2[1].match(/^1_/) != null) {
vehicleAgency = '<a href="http://www.bus.saga.saga.jp" target="_blank">佐賀市交通局</a>';
} else if (tripId2[1].match(/^4_/) != null) {
vehicleAgency = '<a href="http://www.yutoku.jp/jidousya/bus/" target="_blank">祐徳バス株式会社</a>';
} else {
vehicleAgency = '<a href="http://showa-bus.jp" target="_blank">昭和自動車株式会社</a>';
}
testArray.push('<p class="bsTimeTable">' + '<span class="bsTimeTable bsTimeTime"><span class="smallerSign">' + (scheduledArrivalTime.getMonth() + 1) + '月' + scheduledArrivalTime.getDate() + '日</span>' + ('0' + scheduledDepartureTime.getHours()).slice(-2) + ':' + ('0' + scheduledDepartureTime.getMinutes()).slice(-2) + '<span class="bsTimeTable bsTimeSchedule">' + schedule2 + '<br>' + scheduleComment + '</span></span><span class="bsTimeTable bsTimeDesc"><span class="bsTimeSign">' + headsign2 + '</span>' + vehicleAgency + '<br>' + tripId2[1] + '</span></p>');
});
});
//クリックしたバス停を通過するバス系統表示
document.getElementById('info').innerHTML = '<h4>' + bstopinfoelements[1] + '</h4>' + uniq(testArray).sort().join('');
});
cn++;
}
}
</script>
</head>
<body onload="showMap();">
<div id="demo"></div>
<div id="realBs"><button class="btnCircle" type="button" onclick="goNoPage()">戻る</button></div>
<div id="realBs2"><button class="btnCircle" type="button" onclick="location.reload()"><i class="fas fa-sync-alt" aria-hidden="true"></i></button></div>
<div id="map"></div>
<div id="info"></div>
</body>
</html>