forked from pranavrc/transit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
393 lines (375 loc) · 43.2 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
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
<!DOCTYPE html>
<html>
<head>
<title>transit.js - Client-side, schedule-based Transit maps.</title>
<meta charset='utf-8'>
<link rel="stylesheet" href="index.css">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44036056-1', 'onloop.net');
ga('send', 'pageview');
</script>
<script>
$(document).ready(function () {
$('.clicktoshow').click(function () {
var text = $(this).text();
if ($(this).next().is(':hidden')) {
$(this).next().slideDown('fast');
$(this).html(text + " ^ ");
} else {
$(this).next().slideUp('fast');
$(this).html(text.slice(0, text.length - 2));
}
});
});
</script>
</head>
<body>
<a href="https://github.com/pranavrc/transit"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<h1>transit.js</h1>
<div id="exp">Make client-side, schedule-driven transit maps.</div><hr /><br />
<div id="parent">
<strong>Transit</strong> lets you build completely client-side maps of schedule-based transit systems. There's no webserver involved, the browser does all the work. Transit supports both <a href="http://openstreetmap.org/">OpenStreetMap</a> and <a href="http://maps.google.com/">Google Maps</a>. Here's how it looks like in action, on both OpenStreetMap and Google Maps:<br /><br />
<a href="images/shot02.jpg"><img src="images/shot02.jpg" style="width:398px;" alt="OpenStreetMap screenshot"></a>
<a href="images/shot01.jpg"><img src="images/shot01.jpg" style="width:398px;" alt="Google Maps screenshot"></a>
<hr />
<div id="list">
<ul>
<li><a href="#intro">What's this?</a></li>
<li><a href="#demo">Demo.</a></li>
<li><a href="#download">Download and Usage.</a></li>
<li><a href="#get_started">Getting started.</a></li>
<li><a href="#kml">Railroad to Rome - Making our transit routes.</a></li>
<li><a href="#json">The Grand Intercontinental Maglev - Scheduling our vehicles.</a></li>
<li><a href="#initialize">Initializing our Map.</a></li>
<li><a href="#deploy">Deploying our App.</a></li>
<li><a href="#app">Our Grand Intercontinental Maglev!</a></li>
<li><a href="#final">Notes.</a></li>
</ul>
</div>
<hr />
<div id="intro">
<h3>What's this?</h3>
Transit takes a set of transit routes or paths, and a set of vehicles and their schedules, and simulates their movement on the given routes, based on the schedule. The transit routes are defined in a <strong>KML</strong> (<a href="http://en.wikipedia.org/wiki/Keyhole_Markup_Language">Keyhole Markup Language</a>) file, and the vehicle schedules are written in a <strong>JSON</strong> (<a href="http://en.wikipedia.org/wiki/JSON">JavaScript Object Notation</a>) file.<br /><br />
To create the KML file, you can use a maps editor tool that can export visual geographic data as one. There are several, but the one I personally use is <a href="https://mapsengine.google.com/map/">Maps Engine Lite</a>, Google's free online Maps editor that lets you work with Google maps. For the JSON, you can use a JSON editor. If you're writing <a href="https://github.com/pranavrc/chennairail/blob/gh-pages/chennai_rail_schedule.json">a lot of</a> schedules, though, <a href="http://www.vim.org/">Vim</a> or <a href="http://www.gnu.org/software/emacs/">Emacs</a> might save your sanity.<br /><br />
Transit comes with an Event logger that logs arrivals and departures, a custom Search bar that lets you zero in on a stop quickly, and a status box for displaying current information about vehicles. All of these can be turned off if you want a basic, no-nonsense map with just the vehicles and their popups.
</div>
<hr />
<div id="demo">
<h3>Demo.</h3>
The <a href="http://onloop.net/chennairail">Chennai Suburban Rail Map</a> (<a href="http://onloop.net/chennairailmap">OpenStreetMap</a> Version) was made with Transit. It uses <a href="https://github.com/pranavrc/chennairail/blob/gh-pages/chennai_rail_map.kml">this</a> KML file and <a href="https://github.com/pranavrc/chennairail/blob/gh-pages/chennai_rail_schedule.json">this</a> JSON file. <br /><strong>Note:</strong> No trains operate between (roughly) 18:30-23:30 UTC (00:00-05:00 IST).
</div>
<hr />
<div id="download">
<h3>Download and Usage.</h3>
You can download Transit in a zipped file from <a href="https://github.com/pranavrc/transit/archive/master.zip">here</a>. Transit requires <a href="http://jquery.com/">jQuery 1.10.1</a>, and <a href="https://developers.google.com/maps/documentation/javascript/">Google Maps JavaScript API V3</a> or <a href="http://leafletjs.com">Leaflet OpenStreetMap API</a>, depending on your choice of map, so you'll have to include those too.<br /><br />
<strong>For Google Maps:</strong><br />
<div class="code">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"><script><br />
<script src="<strong>transit.js</strong>"></script> <!--You can use transit-min.js (<a href="http://en.wikipedia.org/wiki/Minification_%28programming%29">minified</a> file) here--><br />
<script src="<strong>http://maps.googleapis.com/maps/api/js?key={API_KEY}&sensor=false</strong>"><script><br />
</div>
The key={API_KEY} for your app is optional, but it helps you with analytics, so if you plan to get one, start <a href="https://developers.google.com/maps/documentation/javascript/tutorial#api_key">here</a>.<br /><br />
<strong>For OpenStreetMap:</strong><br />
<div class="code">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"><script><br />
<script src="<strong>transit-osm.js</strong>"></script> <!--You can use transit-osm-min.js (<a href="http://en.wikipedia.org/wiki/Minification_%28programming%29">minified</a> file) here--><br />
<script src="<strong>http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js</strong>"><script><br />
<link rel="stylesheet" href="<strong>http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css</strong>" /><br />
</div>
Transit does not have a CDN yet. Don't use the URL of the raw file from Github. <em>Github ain't no CDN</em>.
</div>
<hr />
<div id="get_started">
<h3>Getting started.</h3>
Do you know that all railroads lead to Rome? One of them starts from Tokyo, goes to Beijing and Moscow, and ends in Rome. Well, not really, but let's make one anyway. We're going to draw the route from Tokyo to Beijing to Moscow to Rome and schedule a train called the <em>Grand Intercontinental Maglev</em> to make a stopping run from Tokyo to Rome, covering the distance in less than 2 minutes. That's right, we're gonna use ultra-powerful magnetic fields for ultra-powerful magnetic levitation.<br /><br />
Fire up <a href="https://mapsengine.google.com/map/">Maps Engine Lite</a> and log in with your Google Account if you use one. <strong>Take a tour</strong>, if you wish.
</div>
<hr />
<div id="kml">
<h3>Railroad to Rome - Making our transit routes.</h3>
<a href="images/stops.jpg"><img src="images/stops.jpg" alt="Image of stops in the route"></a><br />
First off, we place markers at all our stops, viz., Tokyo, Beijing, Moscow and Rome. You can search for them and add the marker to the map from the search result. If you manually place the markers, set their names and descriptions (optional).<br /><br />
<a href="images/line.jpg"><img src="images/line.jpg" alt="Image of the route"></a><br />
Then, we draw the route between our stops. If there was a real railroad between your markers, you might want to trace through it. We'll draw a random railroad here, and name it the <em>Railroad to Rome</em>. Notice how I placed line-points (the white circles that demarcate the line) below all the markers?<br />Don't forget to do that - <strong>the markers just name the stops, the points are the actual stops</strong>.<br /><br />That said, it's completely fine if you don't accurately place the points on the markers' bases. Transit will automatically resolve your markers' positions to the positions of the closest points on the line.<br /><br />
<a href="images/export.jpg"><img src="images/export.jpg" alt="Image of the export option"></a><br />
Self-explanatory. Once we're done, we export our map to KML.<br /><br />
<a href="images/download.jpg"><img src="images/download.jpg" alt="Image of the Download option"></a><br />
If you create multiple layers, export the <strong>Entire map</strong>. If it's just one layer, it doesn't matter, because that layer IS the entire map. We'll save our KML file as <strong>railroad_to_rome.kml</strong>.<br /><br />
<strong>NOTE:</strong><br />
1. Multiple stops must not have the same name. If you have two stops in the route that share a name, just name them <strong><Stopname> #1</strong> and <strong><Stopname> #2</strong> (Tokyo #1 and Tokyo #2) or similar.<br />
2. A route/line must not pass through the same stop more than once. If you need this functionality, make two markers and points for a single stop, and again, name them <strong><Stopname> #1</strong> and <strong><Stopname> #2</strong>.
</div>
<hr />
<div id="json">
<h3>The Grand Intercontinental Maglev - Scheduling our vehicles.</h3>
Let's create a JSON file and name it <strong>railroad_to_rome_schedule.json</strong>. The schedule file needs to have the following format:
<span class="clicktoshow">Show</span>
<div class="code hide">
{<br />
<strong>"timezone"</strong>: "+/-HH:MM:(Optional SS, default 00)", (UTC offset in HH:MM:SS for the timezone you're gonna use)<br />
<strong>"defaultstopinterval"</strong>: "HH:MM:(Optional SS, default 00)", (<strong>Optional</strong>. If one of arrival or departure isn't specified for a stop, it's calculated using this interval. This is useful when you have to write schedules for vehicles that have a consistent stopping time of, say, 00:01:00. This doesn't apply to the first stop and the last one, because the first stop needs a mandatory departure time and the last one needs an arrival time)<br />
<strong>"vehicles"</strong>: (We write a list of vehicles and their schedules under this)<br />
[<br />
{<br />
<strong>"name"</strong>: "Vehicle #1",<br />
<strong>"info"</strong>: "Vehicle #1 Info", (<strong>Optional</strong>)<br />
<strong>"route"</strong>: "Vehicle #1 Route", (Name of the route in which it will travel, that we drew on the KML map)<br />
<strong>"stops"</strong>: (The schedule)<br />
[<br />
{<br />
<strong>"name"</strong>: "Stop #1", (Name of a stop in the route, that we defined with a marker in the map)<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"HH:MM:(Optional SS, default 00)", <strong>"day"</strong>: Integer (Calendar day starting with 00:00:00 and ending with 23:59:59, NOT the day of travel) }<br />
},<br />
{<br />
<strong>"name"</strong>: "Stop #2",<br />
<strong>"arrival"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer },<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer }<br />
},<br />
..<br />
..<br />
{<br />
<strong>"name"</strong>: "Stop #N",<br />
<strong>"arrival"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer }<br />
}<br />
]<br />
},<br />
..<br />
..<br />
{<br />
<strong>"name"</strong>: "Vehicle #N",<br />
<strong>"info"</strong>: "Vehicle #N Info",<br />
<strong>"route"</strong>: "Vehicle #N Route",<br />
<strong>"stops"</strong>:<br />
[<br />
{<br />
<strong>"name"</strong>: "Stop #1",<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"HH:MM:(Optional SS, default 00)", <strong>"day"</strong>: Integer }<br />
},<br />
{<br />
<strong>"name"</strong>: "Stop #2",<br />
<strong>"arrival"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer },<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer }<br />
},<br />
..<br />
..<br />
{<br />
<strong>"name"</strong>: "Stop #N",<br />
<strong>"arrival"</strong>: { <strong>"time"</strong>:"HH:MM:SS", <strong>"day"</strong>: Integer }<br />
}<br />
]<br />
}<br />
]<br />
}
</div><br />
So let's schedule our Grand Intercontinental Maglev.<br /><br />
<div class="code">
{<br />
<strong>"timezone"</strong>: "+5:30:00", (Since I'm on UTC+5:30:00, I'll write the schedule in it, for convenience)<br />
<strong>"defaultstopinterval"</strong>: "00:00:10", (Let's have the Maglev stop for 10 seconds at intermittent stops so that we won't have to specify both arrival and departure times for Beijing and Moscow)<br />
<strong>"vehicles"</strong>:<br />
[<br />
{<br />
<strong>"name"</strong>: "Grand Intercontinental Maglev",<br />
<strong>"info"</strong>: "Blazing Fast!",<br />
<strong>"route"</strong>: "Railroad to Rome", (This is what we named our route, remember?)<br />
<strong>"stops"</strong>:<br />
[<br />
{<br />
<strong>"name"</strong>: "Tokyo Station",<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"11:41", <strong>"day"</strong>: 1 }<br />
},<br />
{<br />
<strong>"name"</strong>: "Beijing Railway Station",<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"11:41:35", <strong>"day"</strong>: 1 } (will arrive at 11:41:25 - default stop interval)<br />
},<br />
{<br />
<strong>"name"</strong>: "Komsomolskaya",<br />
<strong>"departure"</strong>: { <strong>"time"</strong>:"11:42:10", <strong>"day"</strong>: 1 } (11:42:00 arrival)<br />
},<br />
{<br />
<strong>"name"</strong>: "Termini",<br />
<strong>"arrival"</strong>: { <strong>"time"</strong>:"11:43", <strong>"day"</strong>: 1 }<br />
}<br />
]<br />
}<br />
]<br />
}
</div>
So that's it. That's the schedule for our blazing fast Maglev.<br /><br />
<strong>NOTE:</strong><br />
1. Each train can travel only through one route. If you have two trains sharing half of the same route and then diverging onto other routes, you'll have to draw two routes separately, overlapping on the shared half.<br />
2. The first stop MUST have a departure time specified. Likewise with the last stop and an arrival time. The intermittent stops can have any one of them if you have a default stop interval.<br />
3. The <strong>day</strong> parameter indicates a calendar day, NOT the day of travel. If a vehicle starts at 23:59:59 and reaches its next stop at 00:00:00, you'd need to assign day 1 for the 23:59:59 departure and day 2 for the 00:00:00 arrival.<br />
4. If a vehicle's journey spans multiple days, Transit will show you all possible positions at which the vehicle could be, at a particular point of time. This is why each vehicle is assigned a distinct color. It makes tracking easier.
</div>
<hr />
<div id="initialize">
<h3>Initializing our Map.</h3>
We now have <strong>railroad_to_rome.kml</strong> and <strong>railroad_to_rome_schedule.json</strong>. And we have Transit in our project too, so that makes it 3 files. We're gonna need one more, the app itself.<br />
<span class="clicktoshow">Making a transit map with Google Maps</span>
<div class="hide">
First, let's get some boilerplate out of the way:<br />
<div class="code">
<!DOCTYPE html><br />
<html><br />
<head><br />
<title>Grand Intercontinental Maglev on the Railroad to Rome.</title><br />
<meta charset="utf-8" /><br />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script><br />
<script src="http://maps.googleapis.com/maps/api/js?key={API_KEY}&sensor=false"></script><br />
<script src="transit-min.js"></script><br />
</div><br />
Transit maps are like other Google maps, they're rendered inside a <strong><div></strong>. You can style them and overlay content on them like any other div. Let's make a div that occupies the whole page. Here's the code, along with some boilerplate.<br />
<div class="code">
<style type="text/css"><br />
html, body {<br />
height: 100%;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
</style><br />
</head><br />
<body><br />
<div id="ourMapDiv" style="width:100%;height:100%;"></div><br />
</div><br />
The body of the document now occupies the whole page, and our map div now occupies the whole body. Our div has been made. We just need to initialize the transit map inside it. Transit's <strong>initialize()</strong> function takes 7 arguments:
<div class="code">
transit.initialize(selector, // The <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors">selector</a> of the div. <strong>#ourMapDiv</strong> in our case.<br />
localKmlFile, // The path to your KML file.<br />
remoteKmlFile, // The same KML file, in a publicly accessible domain, for Maps API's use.<br />
jsonFile, // The path to your JSON file.<br />
showLog, // <strong>Optional</strong> boolean parameter to show or hide the Event logger. <strong>True</strong> by default.<br />
showSearch, // <strong>Optional</strong> boolean parameter to show or hide the Search bar. <strong>True</strong> by default.<br />
refreshInterval // The number of seconds between each update of the vehicles' markers.<br /> <strong>Optional</strong>. <strong>1 second</strong> by default.<br />
);
</div><br />
The remote KML file is required because the Maps API needs to access it and overlay it on your map. It needs to be in a publicly accessible webpage. Let's write the rest of our code with the initialize() call.
<div class="code">
<script><br />
transit.initialize("#ourMapDiv",<br />
"<a href="https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome/railroad_to_rome.kml">railroad_to_rome.kml</a>",<br />
"<a href="https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome/railroad_to_rome.kml">https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome/railroad_to_rome.kml</a>",<br />
"<a href="https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome/railroad_to_rome_schedule.json">railroad_to_rome_schedule.json</a>");<br />
</script><br />
</body><br />
</html>
</div><br />
We're done. <a href="https://github.com/pranavrc/transit/tree/gh-pages/railroad_to_rome">Here's</a> the whole repository of code we just created.
</div><br />
<span class="clicktoshow">Making a transit map with OpenStreetMap</span>
<div class="hide">
First, let's get some boilerplate out of the way:<br />
<div class="code">
<!DOCTYPE html><br />
<html><br />
<head><br />
<title>Grand Intercontinental Maglev on the Railroad to Rome.</title><br />
<meta charset="utf-8" /><br />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script><br />
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script><br />
<script src="transit-osm-min.js"></script><br />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" /><br />
</div><br />
Transit maps are like other OSM maps, they're rendered inside a <strong><div></strong>. You can style them and overlay content on them like any other div. Let's make a div that occupies the whole page. Here's the code, along with some boilerplate.<br />
<div class="code">
<style type="text/css"><br />
html, body {<br />
height: 100%;<br />
margin: 0;<br />
padding: 0;<br />
}<br />
</style><br />
</head><br />
<body><br />
<div id="ourMapDiv" style="width:100%;height:100%;"></div><br />
</div><br />
The body of the document now occupies the whole page, and our map div now occupies the whole body. Our div has been made. We just need to initialize the transit map inside it. Transit's <strong>initialize()</strong> function takes 7 arguments:
<div class="code">
transit.initialize(selector, // The <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors">selector</a> of the div. <strong>#ourMapDiv</strong> in our case.<br />
tileLayer, // The <a href="http://wiki.openstreetmap.org/wiki/Tiles">Tile Layer</a> that you want to render on the map.<br />
kmlFile, // The path to your KML file.<br />
jsonFile, // The path to your JSON file.<br />
showLog, // <strong>Optional</strong> boolean parameter to show or hide the Event logger. <strong>True</strong> by default.<br />
showSearch, // <strong>Optional</strong> boolean parameter to show or hide the Search bar. <strong>True</strong> by default.<br />
refreshInterval // The number of seconds between each update of the vehicles' markers.<br /> <strong>Optional</strong>. <strong>1 second</strong> by default.<br />
);
</div><br />
We'll create a tile layer (we'll use the <a href="http://wiki.openstreetmap.org/wiki/Tiles#Servers">basic OSM tileserver</a>) and write the rest of our code with the initialize() call.
<div class="code">
<script><br />
var ourTileLayer = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {<br />
attribution: "© <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, <a href='http://creativecommons.org/licenses/by-sa/2.0/'>CC-BY-SA</a>"<br />
});<br /><br />
transit.initialize("#ourMapDiv",<br />
ourTileLayer,<br />
"<a href="https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome_osm/railroad_to_rome.kml">railroad_to_rome.kml</a>",<br />
"<a href="https://raw.github.com/pranavrc/transit/gh-pages/railroad_to_rome_osm/railroad_to_rome_schedule.json">railroad_to_rome_schedule.json</a>");<br />
</script><br />
</body><br />
</html>
</div><br />
We're done. <a href="https://github.com/pranavrc/transit/tree/gh-pages/railroad_to_rome_osm">Here's</a> the whole repository of code we just created.
</div><br />
<span class="clicktoshow">Rendering on Handheld devices</span>
<div class="hide">
On mobile devices, the browser's zoom interferes with the map's zoom. This isn't a major issue, but if you want to fix this, you'd want to fit the map to the device's width. You can use <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag">Viewports</a> for this. Include a Viewport meta tag in your HTML, as follows:<br /><br />
<div class="code">
<meta name="viewport" content="width=device-width, user-scalable=false;">
</div><br />
You should note, though, that this will cramp the map, and it would be wise to remove the Event logger and maybe even the search bar if you're going to do this, so that a basic map, with just the transit system, is rendered.<br /><br />
<a href="images/mobile01.jpg"><img src="images/mobile01.jpg" style="width:150px;"></a><br />
<em>"Geez, give me some room, will ya?"</em><br /><br />
<a href="images/mobile02.jpg"><img src="images/mobile02.jpg" style="width:150px;"></a><br />
<em>"That's better. Now give me my Search bar back."</em><br /><br />
<a href="images/mobile03.jpg"><img src="images/mobile03.jpg" style="width:150px;"></a><br />
<em>"Dandy."</em><br /><br />
The <a href="https://github.com/pranavrc/transit/blob/master/transit.js#L904">transit.isMobileDevice()</a> function returns true if the client is a handheld device, or false if not. This way, you can render the basic map for mobile devices and a normal map for desktops.<br /><br />
You should also consider increasing the <strong>refreshInterval</strong> parameter for mobile devices so that the load is reduced. As most handheld devices have lesser processing power, a higher refresh interval would mean higher responsiveness.<br /><br />
See <a href="https://github.com/pranavrc/chennairailmap/blob/gh-pages/index.html#L51">here</a> to get an idea of how it's done.
</div><br />
<span class="clicktoshow">Loading different schedules on different days</span>
<div class="hide">
If your transit system uses different schedules on different days, you can use the <a href="https://github.com/pranavrc/transit/blob/master/transit.js#L688">transit.dayInTimezone()</a> function to get the day of the week (in the target timezone) and then load a corresponding schedule. The function returns a number from 0 to 6, 0 being Sunday and 6 being Saturday. See <a href="https://github.com/pranavrc/chennairailmap/blob/gh-pages/index.html#L49">here</a> for an example of how this is done.
</div>
</div>
<hr />
<div id="deploy">
<h3>Deploying our App.</h3>
Since this is pretty much a client-side app, you can serve it from your webserver or straight out of Github. <a href="http://pages.github.com/">Github Project Pages</a> let you host client-side apps that run on the browser. <a href="http://onloop.net/transit/railroad_to_rome/">Here's</a> our app (<a href="http://onloop.net/transit/railroad_to_rome_osm/">Here's</a> the OpenStreetMap version), served from a Github Project Page. If you happen to catch it between 11:41 and 11:43 IST (The UTC+5:30:00 we specified, calculated and adjusted from the client's time and timezone) any day, say Hi to our Maglev.
</div>
<hr />
<div id="app">
<h3>Our Grand Intercontinental Maglev!</h3>
Right, our train is now scheduled to depart!<br /><br />
<a href="images/demo01.jpg"><img src="images/demo01.jpg"></a><br />
Nothing yet. Oh right, it's 11:40. Not quite time.<br /><br />
<a href="images/demo02.jpg"><img src="images/demo02.jpg"></a><br />
It's 11:41 now, and sure enough, there's our good ol' Mag.<br /><br />
<a href="images/demo03.jpg"><img src="images/demo03.jpg"></a><br />
Paying Beijing a visit.<br /><br />
<a href="images/demo04.jpg"><img src="images/demo04.jpg"></a><br />
Scorching a fiery trail between two borders in a few seconds.<br /><br />
<a href="images/demo05.jpg"><img src="images/demo05.jpg"></a><br />
Hang on while I think of a Soviet Russia joke.<br /><br />
<a href="images/demo06.jpg"><img src="images/demo06.jpg"></a><br />
Streaking across the EU.<br /><br />
<a href="images/demo07.jpg"><img src="images/demo07.jpg"></a><br />
I sure hope no one was on <em>that</em> train.
</div>
<hr />
<div id="final">
<h3>Notes.</h3>
I might have missed out on a few things, but this page will stay updated, and more documentation is coming up. Meanwhile, you can <a href="mailto:me at onloop.net">mail me</a> for queries or check out <a href="https://github.com/pranavrc/transit/blob/master/transit.js">Transit's</a> and <a href="https://github.com/pranavrc/chennairail">Chennairail's</a> code, to get a better understanding of how Transit works. Bug reports, pull requests, and contributions are very much welcome.<br /><br />
And look out for our Maglev at 11:41 IST tomorrow!
</div>
</div><br />
<hr /><br />
<div id="footer">© <a href="http://onloop.net">Pranav Ravichandran</a>. Inspired by <a href="http://www.flightradar24.com/">flightradar24</a> (GPS flight tracking), <a href="http://swisstrains.ch/">swisstrains.ch</a> (Schedule-based swiss train radar) and <a href="http://busroutes.in/chennai/">busroutes</a> (Bus transit search).</div>
</body>
</html>