-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
341 lines (304 loc) · 14.3 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" />
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
<title>CoMo Bus Timer</title>
</head>
<body>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XYREN05F40"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XYREN05F40');
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAgMo2y743lim1h4IGq3BvlUl8Ar0fl1hQ&callback=initMap&v=weekly"
async></script>
<ion-app id="app">
<ion-header translucent>
<ion-toolbar>
<ion-title>CoMo Bus Timer</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<!-- <audio src="https://busmap.weathon.top/audio" autoPlay></audio> -->
<ion-list>
<ion-text>
<P>You can add this to your home screen for ease of access</p>
<p>This app is open source and we need more volunteers! Please e-mail me if you are interst. wg25r@umsystem.edu</p></ion-text>
<ion-list-header> Select A Route </ion-list-header>
<ion-item v-for="item in list" :key="list.name" @click="setAlert(item.id)">
<ion-avatar slot="start">
<ion-icon name="bus" size="large" v-bind:style="{width: '100%', color: '#'+item.color}">
</ion-icon>
</ion-avatar>
<ion-label>
<h2>{{ item.name }}</h2>
</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-app>
</body>
<ul>
</ul>
<ion-modal id="card-modal" backdropDismiss=false>
<ion-header translucent>
<ion-toolbar>
<ion-title>Map</ion-title>
<ion-button onclick="location.reload()" slot="start">Exit</ion-button>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<br />
<p>Now this app is calculating the line distance not the driving distance, sorry.</p>
<b>Please keep the app open as we knew on some phones this app won't work in backgraound</b>
<h3>Select A Bus Stop That You Will Get On The Bus</h3>
<!-- bozishangsuanruantyrunhuxihlongxou -->
<div id="GMap" style="height: 60%;width:95%;left:2.5%"></div>
<div id="mile"></div>
<div id="form">
<p id="selected"></p>
<ion-list-header>How many miles before the bus approaches the stop do you want to get a notification.
</ion-list-header>
<ion-item>
<ion-input type="number" value="0.3" placeholder="Enter a number"></ion-input>
</ion-item>
</div>
<ion-button expand="block" onclick="audio.play();startTracking();" id="GoButton">Set The Notification!</ion-button>
</ion-content>
</ion-modal>
<script>
fetch('https://busmap.weathon.top/version')
.then(function (response) {
return response.json();
})
.then(function (v) {
if(v!="1.0")
{alert("Your App is out of date, please upgrade or use the web version. (You can still keep using this version but we cannot ensure it works well.)")}})
audio = new Audio('https://busmap.weathon.top/audio'); //undefineded? ceshideshi busmap
audio.muted=true;
document.getElementById("card-modal").backdropDismiss = false;
document.getElementById("card-modal").showBackdrop = 1;
var selectedStop = -1;
var selectedRoute = -1;
var stops = [];
function haversine_distance(mk1, mk2) {
var R = 3958.8; // Radius of the Earth in miles
var rlat1 = mk1.position.lat() * (Math.PI / 180); // Convert degrees to radians
var rlat2 = mk2.position.lat() * (Math.PI / 180); // Convert degrees to radians
var difflat = rlat2 - rlat1; // Radian difference (latitudes)
var difflon = (mk2.position.lng() - mk1.position.lng()) * (Math.PI / 180); // Radian difference (longitudes)
var d = 2 * R * Math.asin(Math.sqrt(Math.sin(difflat / 2) * Math.sin(difflat / 2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon / 2) * Math.sin(difflon / 2)));
return d;
// https://cloud.google.com/blog/products/maps-platform/how-calculate-distances-map-maps-javascript-api
}
function getBusObjectByID(buses, id) {
for (var i = 0; i < buses.length; i++) {
if (buses[i].id == id) {
return buses[i];
}
}
}
function checkForBus(possibleBusIDs, milage, selectedStop, StopObj, busMarkers, StopMark) {
// console.log(busMarkers)
fetch('https://busmap.weathon.top/buses')
.then(function (response) {
return response.json();
})
.then(function (buses) {
console.log("buses")
for (var i = 0; i < buses.length; i++) {
if (possibleBusIDs.includes(buses[i].id)) {
// if (buses[i].id in possibleBusIDs) {
// console.log("found not found faruannashou shouruan aashiain")
busMarkers[buses[i].id].setPosition({ lat: buses[i].lat, lng: buses[i].lon });
// haversine_distance(busMarkers[buses[i].id], StopObj);
realMile = haversine_distance(busMarkers[buses[i].id], StopMark);
document.getElementById("mile").innerText = "The distance from the bus to the stop is " + realMile + " miles";
if (realMile <= milage) {
if(audio.muted==true)
{
audio.muted=false;
}
audio.play();
}
}
}
})
console.log([possibleBusIDs, milage, StopMark, selectedStop])
//weismyaoxiamiangengxing?dui oh new he gengxingyaozaiwaimianhuxihlong yunkunaychiduiz
}
function startTracking() {
// audio.muted=true;
if (selectedStop == -1) {
alert("Please select a bus stop");
return;
}
if (selectedRoute == -1) {
alert("Please select a route");
return;
}
milage = document.getElementsByTagName("ion-input")[0].value;
console.log(milage); //why is this not working? huangbierenchaojlphcjaxlxpiui xueyabierenwnaifangconsole you -url
if (milage == "") {
alert("Please enter a number");
return;
}
if (Number(milage) == NaN) {
alert("Please enter a number");
return;
}
//fetch from /buses
fetch('https://busmap.weathon.top/buses')
.then(function (response) {
return response.json();
})
.then(function (buses) {
possibleBusIDs = []; //zhege huigengxing?yachihong
for (var i = 0; i < buses.length; i++) {
if (buses[i].route == selectedRoute) {
possibleBusIDs.push(buses[i].id);
}
// setInterval(checkForBus, possibleBusIDs, milage, selectedStop, 1000);
}
if (possibleBusIDs.length == 0) {
alert("No buses found for this route");
return;
}//zhegewodoumeiyouxiangdao
console.log(possibleBusIDs) //why not arrayttxkoueinyachichao yachiduzixianziakeyileyangbenlaishi12 yachiaychiyachi hlongbeirenchao zhege chuanshujuchucuole hlongxkoufangpiyachi jiuzhi xingyici shiywei diaoyongyiweishishiyonghuidiaohanch
document.getElementById("GoButton").disabled = true;
document.getElementById("form").style.display = "none";
StopObj = getStopObject(selectedStop)
StopMark = new google.maps.Marker({ position: { lat: StopObj.lat, lng: StopObj.lon }, map: map });
var busMarkers = {}
for (var j = 0; j < possibleBusIDs.length; j++) {
thiBus = getBusObjectByID(buses, possibleBusIDs[j])
Busmark = new google.maps.Marker({ position: { lat: thiBus.lat, lng: thiBus.lon }, map: map });
busMarkers[possibleBusIDs[j]] = Busmark;
}
console.log(busMarkers)
setInterval(function () {
checkForBus(possibleBusIDs, milage, StopMark, StopObj, busMarkers, StopMark) //hlongkouekzheyangkeyiyunnaioxkou huang
}, 3000);
});
}
function getStopObject(stopID) {
for (var i = 0; i < stops.length; i++) {
if (stops[i].id == stopID) {
return stops[i];
}
}
} //gen by github copoit
function initMap() {
const myLatLng = { lat: 38.9517, lng: -92.3341 };
map = new google.maps.Map(document.getElementById("GMap"), {
zoom: 12,
center: myLatLng,
});
}
//if (localStorage.getItem("notif") == null || localStorage.getItem("notif") <= Date.now()-3600*48) {
alert("This app is made by a Mizzou student, who is NOT connected with the University of Missouri, Tiger Line, GoCoMo, or the City of Columbia.\
This app only represents my position. This app is still in testing; it might cause a false alert or miss alert. If you have any advice, please\
e-mail wg25r@umsystem.edu. The data of the app is fetched from Doublemap via my own server. Due to iOS audio policy, the app might not be able to play the audio by defult, we are trying to solve this issue. ")
//localStorage.setItem("notif", Date.now());
//}
new Vue({
el: '#app',
data: {
list: []
},
created: function () {
var self = this;
fetch('https://busmap.weathon.top/routes')
.then(function (response) {
return response.json();
})
.then(function (json) {
self.list = json;
});
},
methods: {
setAlert: function (routeID) {
selectedRoute = routeID;
document.getElementById("card-modal").present()
fetch('https://busmap.weathon.top/routes')
.then(function (response) {
console.log(routeID)
return response.json();
})
.then(function (json) {
console.log(json)
for (var i = 0; i < json.length; i++) {
console.log(json[i].id)
if (json[i].id == routeID) {
var route = json[i]
break;
}
}
const triangleCoords = [
];
for (var i = 0; i < route.path.length / 2; i++) {
triangleCoords.push({ lat: route.path[i * 2], lng: route.path[i * 2 + 1] });
}
// var stops = {};
fetch('https://busmap.weathon.top/stops')
.then(function (response) {
return response.json();
})
.then(function (json) {
stops = json;
console.log(stops)
markers = [] //not {}
for (var i = 0; i < route.stops.length; i++) {
for (var j = 0; j < stops.length; j++) {
// console.log(j.id) stupid copolit
if (stops[j].id == route.stops[i]) {
var stop = stops[j]
console.log(stop.id)
markers.push(new google.maps.Marker({
position: { lat: stop.lat, lng: stop.lon },
map,
icon: "dot.png",
// title: stop.name,
// stopID: stop.id,
}));
addEvent(stop, markers[length - 1]);
}
}
}
})
console.log(triangleCoords)
bermudaTriangle = new google.maps.Polyline({
path: triangleCoords,
strokeColor: "#" + route.color,
strokeOpacity: 0.8,
strokeWeight: 4,
});
bermudaTriangle.setMap(map);
});
}
}
});
function addEvent(stop, marker) {
console.log(stop);
google.maps.event.addListener(markers[markers.length - 1], "click", () => {
console.log(stop.name)
document.getElementById("selected").innerHTML = "You have selected " + stop.name;
selectedStop = stop.id
});
}
</script>
</body>
</html>
<!-- todo: nayigefangxain? -->