-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.html
220 lines (193 loc) · 8.62 KB
/
playground.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
<!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>
<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>
<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;
}
</style>
<script>
function showMap() {
//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: 18,
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'});
//現在地が取れる時
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);
}
});
let shapeGroup = [[32.954426,130.218366],
[32.958972,130.202581],
[32.995287,130.108315],
[33.041737,130.044807],
[33.095585,129.97879],
[33.141351,129.948997],
[33.154726,129.944592],
[33.194944,129.948124],
[33.2409,129.967549],
[33.254302,129.991168],
[33.34,130.32584],
[33.24735,130.36864],
[33.24497,130.36946],
[33.23484,130.37085],
[33.22955,130.37042],
[33.22939,130.37036],
[33.22923,130.3703],
[32.955407,130.220234],
[32.954426,130.218366]];
L.polyline(shapeGroup, {color: 'red', weight: 5}).addTo(mymap);
//バス停を入力
//stops.txt読込
var data = makeArrayForHyochu(csvToArray("busData/stops.txt"));
var cn = 1;
//var busstopIcon = L.divIcon({html: '<div><i class="fas fa-bus"></i></div>', className: 'bsIcon', iconSize: [20,20]});
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,'');
//バス停マーカー
//bmarkers[cn] = L.marker([latBs,lngBs],{icon: busstopIcon, title: stopid + ',' + hyochu}).addTo(mymap).bindPopup("<p>"+ hyochu + '</p>');
bmarkers[cn] = L.circle([latBs,lngBs],{radius:20, color: 'dodgerblue', 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="bsTimeTime">' + ('0' + scheduledDepartureTime.getHours()).slice(-2) + ':' + ('0' + scheduledDepartureTime.getMinutes()).slice(-2) + '</span>' + '<span class="bsTimeDesc">' + schedule + '<br>' + headsign2 + '<br>' + tripId2[1] + '</span>' + '</p>');
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="history.back()">戻る</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>