-
Notifications
You must be signed in to change notification settings - Fork 0
/
publicTransport.html
51 lines (40 loc) · 1.73 KB
/
publicTransport.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
<html>
<script src="http://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<body>
<script>
var requestConnectionAndVideo = function(){
$.get("http://transport.opendata.ch/v1/connections?from="+$("#fromStation").val()+"&to="+$("#toStation").val()+"&limit=1", function(data){
var renderedData = typeof data === 'object' ? data : JSON.parse(data);
mapConnectionToMovie(renderedData.connections[0]);
});
};
var mapConnectionToMovie = function(connection){
var movie = {};
movie.scenes = [];
$.each(connection.sections, function(idx, section){
if(section.journey!==undefined && section.journey!==null) {
var scene = {};
movie.scenes.push(scene);
switch (section.journey.category) {
case "NFB":
case "BUS":
scene.animation = "busTravel";
break;
default:
scene.animation = "trainTravel";
}
scene.parameters = {};
scene.parameters.directionLine = section.journey.number;
scene.parameters.directionName = section.journey.to;
}
});
var encodedMovie = encodeURIComponent(JSON.stringify(movie));
window.location.href="composer.html?model="+encodedMovie;
//alert(JSON.stringify(movie));
};
</script>
<input text="from" id="fromStation" placeholder="from"/>
<input text="to" id="toStation" placeholder="to"/>
<input type="button" value="submit" onclick="requestConnectionAndVideo()"/>
</body>
</html>