-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
215 lines (168 loc) · 4.85 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chattanooga Bus Driver Sim 2000</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px;
font-style: italic;
font-family: impact, sans-serif;
}
h1{
text-align: center;
}
#map-canvas{
position: relative;
z-index: 9999;
width: 400px;
}
#controlpanel {
position:absolute;
width: 400px;
right: 0;
top: 0;
}
#controlpanel > div {
padding: 5px;
}
#details {
white-space: pre;
}
.wrap {
position: relative;
width: 800px;
height: 352px;
margin: auto;
}
#cockpit{
background: url('cockpit.png') no-repeat scroll 0% 0% transparent;
position: absolute;
z-index: 8888;
top: 0;
left: 0;
height: 100%;
width: 100%;
opacity: .8;
}
#pano {
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBR8YLtRHYOBK381yao8KXGnzhFlm43SmE&sensor=false"></script>
<script>
var headings = {
'S' : 180,
'SSW': 202.5,
'SW' : 225,
'WSW': 247.5,
'W' : 270,
'WNW': 292.5,
'NW' : 315,
'NNW': 337.5,
'N' : 0,
'NNE': 22.5,
'NE' : 45,
'ENE': 67.5,
'E' : 90,
'ESE': 112.5,
'SE' : 135,
'SSE': 157.5
}
function initialize() {
var nullisland = new google.maps.LatLng(0,0);
map = new google.maps.Map(
document.getElementById('map-canvas'), {zoom: 14, center: nullisland});
var panoramaOptions = {
position: nullisland,
pov: {
heading: 34,
pitch: 10
}
};
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);
map.setStreetView(panorama);
var activeBusId = 0
var busData = {}
var server = new EventSource('http://api.chab.us/buses/tail')
function busOutOfService(bus) {
return bus.properties.route === 'U' || bus.properties.route === 'PI'
}
server.addEventListener('add', function (e) {
var bus = JSON.parse(e.data)
busData[bus.id] = bus
if (busOutOfService(bus)) { return }
document.getElementById('buses').innerHTML += '<option id="bus'+bus.id+'" value="'+bus.id+'">' + bus.id + ' route ' + bus.properties.route + ' to ' + bus.properties.stop +'</option>'
// set the first in-service bus we find to the active bus
if (activeBusId && activeBusId !== bus.id) { return }
activeBusId = bus.id
draw(bus)
})
server.addEventListener('remove', function (e) {
var bus = JSON.parse(e.data)
if (activeBusId === bus.id) { activeBusId = 0}
delete busData[bus.id]
document.getElementById('buses').removeChild(document.getElementById('bus'+bus.id))
})
server.addEventListener('change', function (e) {
var bus = JSON.parse(e.data)
if (busOutOfService(bus)) { return }
// update the select dropdown
document.getElementById('bus'+bus.id).textContent = bus.id + ' route ' + bus.properties.route + ' to ' + bus.properties.stop
if (activeBusId && activeBusId === bus.id) {
draw(bus)
}
})
function draw(bus) {
var pos = new google.maps.LatLng(bus.geometry.coordinates[1], bus.geometry.coordinates[0])
panorama.setPosition(pos)
panorama.setPov({
heading: headings[bus.properties.heading],
pitch: 10
})
// prevent greyness
panorama.setVisible(true)
map.panTo(pos)
document.getElementById('details').textContent = JSON.stringify(bus.properties,null,2)
}
document.getElementById('realism').addEventListener('input', function () {
document.getElementById('cockpit').style.opacity = document.getElementById('realism').value
})
document.getElementById('buses').addEventListener('change', function () {
activeBusId = document.getElementById('buses').value
draw(busData[activeBusId])
})
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<h1>Chattanooga Bus Driver Sim 2000</h1>
<div class="wrap">
<div id="pano"></div>
<div id="cockpit"></div>
</div>
<div class="wrap">
<div id="map-canvas"></div>
<div id="controlpanel">
<div>
Bus <select id="buses"></select>
</div>
<div>
Realism <input type="range" id="realism" min="0" max="1" step=".1" value=".8"/>
</div>
<div>
Details
<div id="details"></div>
</div>
</div>
</div>
<div class="wrap">Yes, you're seeing Streetview imagery based on real-time bus tracking information from CARTA.
<a href="https://github.com/jden/bus-sim">view source on github</a>. Built <option></option> the <a href="http://chab.us">chab.us api</a>
</div>
<script>
</script>
</body>
</html>