-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.js
More file actions
78 lines (69 loc) · 2.28 KB
/
main.js
File metadata and controls
78 lines (69 loc) · 2.28 KB
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
(function(){
var BikeIcon = L.Icon.extend({
iconUrl: 'http://cibi.me/images/marker-bike-green-shadowed.png',
iconSize: new L.Point(25, 39),
shadowUrl: null
});
var bikeIcon = new BikeIcon(),
map = new L.Map('map', {minZoom: otp.config.minZoom, maxZoom: otp.config.maxZoom}),
tileLayer = new L.TileLayer(otp.config.tileUrl, {attribution: otp.config.tileAttrib});
if(otp.config.getTileUrl) {
tileLayer.getTileUrl = otp.config.getTileUrl;
}
map.setView(otp.config.initLatLng, otp.config.initZoom).addLayer(tileLayer);
if(otp.config.overlayTileUrl) {
var overlayTileLayer = new L.TileLayer(otp.config.overlayTileUrl);
map.addLayer(overlayTileLayer);
}
var url = 'http://host-24.deployer.opentripplanner.org/opentripplanner-api-webapp/ws/plan';
function getPlan(data) {
$.ajax(url, {
data: data,
dataType: 'jsonp',
success: function(data) {
var itin,
polyline,
marker;
if(data.plan && data.plan.itineraries && data.plan.itineraries.length) {
itin = data.plan.itineraries[0];
if (itin.legs.length === 1) {
polyline = new L.EncodedPolyline(itin.legs[0].legGeometry.points);
} else if (itin.legs.length === 3) {
polyline = new L.EncodedPolyline(itin.legs[1].legGeometry.points);
}
if (polyline && polyline._latlngs) {
marker = new L.AnimatedMarker(polyline._latlngs, {
icon: bikeIcon,
autoStart: false,
onEnd: function() {
$(this._shadow).fadeOut();
$(this._icon).fadeOut(3000, function(){
map.removeLayer(this);
});
}
});
map.addLayer(marker);
$(marker._icon).hide().fadeIn(1000, function(){
marker.start();
});
}
}
else {
console.log('wah wah waaaahhhh');
}
}
});
}
function getRecent(callback) {
// Nasty global for demo purposes
$.each(sample_data, function(i, plan){
setTimeout(function(){
if (plan && plan.data) {
plan.data.routerId = 'nyc';
callback(plan.data);
}
}, 5000 * i);
});
}
getRecent(getPlan);
})();