-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.js
110 lines (90 loc) · 4.33 KB
/
maps.js
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
var map;
var directionsDisplay;
// if false, only the markers are displayed without any downloaded bus information which is almost
// instant compared to downloading the bus data for each stop
var showBusTimes = true;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 15,
// centering on the University of Paderborn
center: new google.maps.LatLng(51.706768, 8.771104),
clickableIcons: false
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
$.getJSON('bus_stops.json').done(
function (data) {
$.each(data, function (key_first, value_first) {
var infoWindowContent = "";
if (showBusTimes) {
var yql = 'https://query.yahooapis.com/v1/public/yql?'
+ 'q=' + encodeURIComponent('select * from json where url=@url')
+ '&url=' + encodeURIComponent("http://padersprinter.de/internetservice/services/passageInfo/stopPassages/stop?stop=" + key_first + "&mode=arrival")
+ '&format=json&callback=?';
$.getJSON(yql, test_func);
function test_func(json) {
if (json.query.count) {
var data = json.query.results.json;
var hasContent = false;
infoWindowContent = "<h3 style=\"text-align: center\">" + value_first.name + "</h3><ul>";
if (data.actual) {
$.each(data.actual, function (key, val) {
if (typeof val.patternText != 'undefined' && typeof val.direction != 'undefined' && typeof val.actualTime != 'undefined') {
infoWindowContent += "<li>" + val.patternText + " (" + val.direction + "): " + "<b>" + val.actualTime + "</b></li>";
hasContent = true;
}
});
}
if (hasContent) {
infoWindowContent += "</ul>";
var infoWindow = new google.maps.InfoWindow({
content: infoWindowContent
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(value_first.latitude, value_first.longitude),
map: map
});
marker.addListener('click', function () {
if (!marker.open) {
infoWindow.open(map, marker);
marker.open = true;
} else {
infoWindow.close();
marker.open = false;
}
});
}
} else {
return false;
}
}
} else {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(value_first.latitude, value_first.longitude),
map: map
});
var infoWindow = new google.maps.InfoWindow({
content: "<h3>" + value_first.name + "</h3>"
});
marker.addListener('click', function () {
if (!marker.open) {
infoWindow.open(map, marker);
marker.open = true;
} else {
infoWindow.close();
marker.open = false;
}
});
}
});
}
)
}
/**
* Called by the Google Maps callback when it's done loading.
*/
function initMap() {
var directionsService = new google.maps.DirectionsService();
initialize()
}