diff --git a/map.rb b/map.rb index 4d5791b..a6fff52 100644 --- a/map.rb +++ b/map.rb @@ -149,12 +149,12 @@ def stopInfo d2 = 'Alewife' t1 = predictedTrainTimes(trains, stop + "S") t2 = predictedTrainTimes(trains, stop + "N") - when 'blue' + when 'orange' d1 = 'Forest Hills' d2 = 'Oak Grove' t1 = predictedTrainTimes(trains, stop + "S") t2 = predictedTrainTimes(trains, stop + "N") - when 'orange' + when 'blue' d1 = 'Wonderland' d2 = 'Bowdoin' t1 = predictedTrainTimes(trains, stop + "E") diff --git a/stops.csv b/stops.csv index f6209b5..9c2d711 100644 --- a/stops.csv +++ b/stops.csv @@ -3,65 +3,65 @@ place-alfcl,Alewife Station,42.395428,-71.142483,red,RALE,, place-andrw,Andrew Station,42.330154,-71.057655,red,RAND,, place-aport,Airport Station,42.374262,-71.030395,blue,BAIR,, place-aqucl,Aquarium Station,42.359784,-71.051652,blue,BAQU,, -place-armnl,Arlington Station,42.351902,-71.070893,green,,, +place-armnl,Arlington Station,42.351902,-71.070893,,,, place-asmnl,Ashmont Station,42.284652,-71.064489,red,RASH,, place-bbsta,Back Bay Station,42.34735,-71.075727,orange,OBAC,, place-bmmnl,Beachmont Station,42.39754234,-70.99231944,blue,BBEA,, place-bomnl,Bowdoin Station,42.361365,-71.062037,blue,BBOW,, place-brdwy,Broadway Station,42.342622,-71.056967,red,RBRO,, -place-brmnl,Brigham Circle Station,42.334229,-71.104609,green,,, +place-brmnl,Brigham Circle Station,42.334229,-71.104609,,,, place-brntn,Braintree Station,42.2078543,-71.0011385,red,RBRA,, -place-bvmnl,Brookline Village Station,42.332774,-71.116296,green,,, +place-bvmnl,Brookline Village Station,42.332774,-71.116296,,,, place-ccmnl,Community College Station,42.373622,-71.069533,orange,OCOM,, place-chmnl,Charles/MGH Station,42.361166,-71.070628,red,RMGH,, place-chncl,Chinatown Station,42.352547,-71.062752,orange,OCH,, -place-clmnl,Cleveland Circle Station,42.336142,-71.149326,green,,, +place-clmnl,Cleveland Circle Station,42.336142,-71.149326,,,, place-cntsq,Central Square Station,42.365486,-71.103802,red,RCEN,, -place-coecl,Copley Station,42.349974,-71.077447,green,,, +place-coecl,Copley Station,42.349974,-71.077447,,,, place-davis,Davis Station,42.39674,-71.121815,red,RDAV,, place-dwnxg,Downtown Crossing Station,42.355518,-71.060225,red,RDTC,orange,ODT place-fldcr,Fields Corner Station,42.300093,-71.061667,red,RFIE,, place-forhl,Forest Hills Station,42.300523,-71.113686,orange,OFOR,, -place-gover,Government Center Station,42.359705,-71.059215,green,,blue, +place-gover,Government Center Station,42.359705,-71.059215,blue,BGOV,, place-grnst,Green St. Station,42.310525,-71.107414,orange,OGRE,, place-haecl,Haymarket Station,42.363021,-71.05829,orange,OHAY,, place-harsq,Harvard Square Station,42.373362,-71.118956,red,RHAR,, -place-hsmnl,Heath St. Station,42.328681,-71.110559,green,,, -place-hymnl,Hynes Convention Center Station,42.347888,-71.087903,green,,, +place-hsmnl,Heath St. Station,42.328681,-71.110559,,,, +place-hymnl,Hynes Convention Center Station,42.347888,-71.087903,,,, place-jaksn,Jackson Square Station,42.323132,-71.099592,orange,OJAC,, place-jfkred,JFK/UMass Station,42.320685,-71.052391,red,RJFK,, -place-kencl,Kenmore Station,42.348949,-71.095169,green,,, +place-kencl,Kenmore Station,42.348949,-71.095169,,,, place-knncl,Kendall/MIT Station,42.36249079,-71.08617653,red,RKEN,, -place-lake,Boston College Station,42.340081,-71.166769,green,,, -place-lech,Lechmere Station,42.370772,-71.076536,green,,, +place-lake,Boston College Station,42.340081,-71.166769,,,, +place-lech,Lechmere Station,42.370772,-71.076536,,,, place-masta,Massachusetts Ave. Station,42.341512,-71.083423,orange,OMAS,, place-matt,Mattapan Station,42.267762,-71.092241,mattapan,,, place-mlmnl,Malden Center Station,42.426632,-71.07411,orange,OMAL,, place-mvbcl,Maverick Station,42.36911856,-71.03952958,blue,BMAV,, place-nemnl,Tufts Medical Center Station,42.349662,-71.063917,orange,ONEM,, -place-north,North Station,42.365577,-71.06129,orange,ONST,green, +place-north,North Station,42.365577,-71.06129,orange,ONST,, place-nqncy,North Quincy Station,42.275275,-71.029583,red,RNQU,, place-ogmnl,Oak Grove Station,42.43668,-71.071097,orange,OOAK,, place-orhte,Orient Heights Station,42.386867,-71.004736,blue,BORH,, -place-pktrm,Park St. Station,42.35639457,-71.0624242,red,RPRK,green, +place-pktrm,Park St. Station,42.35639457,-71.0624242,red,RPRK,, place-portr,Porter Square Station,42.3884,-71.119149,red,RPOR,, -place-prmnl,Prudential Station,42.34557,-71.081696,green,,, +place-prmnl,Prudential Station,42.34557,-71.081696,,,, place-qamnl,Quincy Adams Station,42.233391,-71.007153,red,RQUA,, place-qnctr,Quincy Center Station,42.251809,-71.005409,red,RQUC,, place-rbmnl,Revere Beach Station,42.40784254,-70.99253321,blue,BREV,, place-rcmnl,Roxbury Crossing Station,42.331397,-71.095451,orange,OROX,, -place-river,Riverside Station,42.337059,-71.251742,green,,, -place-rsmnl,Reservoir Station,42.335027,-71.148952,green,,, +place-river,Riverside Station,42.337059,-71.251742,,,, +place-rsmnl,Reservoir Station,42.335027,-71.148952,,,, place-rugg,Ruggles Station,42.336377,-71.088961,orange,ORUG,, place-sbmnl,Stony Brook Station,42.317062,-71.104248,orange,OSTO,, place-sdmnl,Suffolk Downs Station,42.39050067,-70.99712259,blue,BSUF,, place-shmnl,Savin Hill Station,42.31129,-71.053331,red,RSAV,, place-smmnl,Shawmut Station,42.29312583,-71.06573796,red,RSHA,, -place-spmnl,Science Park Station,42.366664,-71.067666,green,,, +place-spmnl,Science Park Station,42.366664,-71.067666,,,, place-sstat,South Station,42.352271,-71.055242,red,RSOU,, place-state,State St. Station,42.358978,-71.057598,orange,OST,blue,BSTA place-sull,Sullivan Station,42.383975,-71.076994,orange,OSUL,, -place-symcl,Symphony Station,42.342687,-71.085056,green,,, +place-symcl,Symphony Station,42.342687,-71.085056,,,, place-welln,Wellington Station,42.40237,-71.077082,orange,OWEL,, place-wimnl,Wood Island Station,42.3796403,-71.02286539,blue,BWOO,, place-wlsta,Wollaston Station,42.2665139,-71.0203369,red,RWOL,, diff --git a/views/map2.erb b/views/map2.erb index fde0477..e6dfc54 100644 --- a/views/map2.erb +++ b/views/map2.erb @@ -18,7 +18,21 @@ <% end %> ]; - function initialize() { + var makeStopInfo = function(s, result1, result2) { + var data1 = result1[0]; + var data2 = result2 ? result2[0] : null; + var $i = $("
").append("

" + s.name); + $i.append("

" + data1.direction1); + $i.append("

" + data1.direction2); + if (data2) { + $i.append("

" + data2.direction1); + $i.append("

" + data2.direction2); + } + + return $i.html(); + }; + + var initialize = function() { var myOptions = { center: new google.maps.LatLng(42.350851, -71.089886), zoom: 13, @@ -31,6 +45,8 @@ content: "" }); + var request = null; + $.each(stops, function(i, s) { var latLng = new google.maps.LatLng(s.lat, s.lon); var marker = new google.maps.Marker({ @@ -41,8 +57,24 @@ }); google.maps.event.addListener(marker, 'click', function() { - infowindow.setContent(name + "
" + s.name + "
"); + if (s.line1 && s.stop1) { + infowindow.setContent("

" + s.name + "

Loading..."); + } else { + infowindow.setContent("

" + s.name + "

"); + } + infowindow.open(map,marker); + + if (s.line1 && s.stop1) { + request1 = $.getJSON('/stopinfo?line=' + s.line1 + '&stop=' + s.stop1); + request2 = (s.line2 && s.stop2) ? $.getJSON('/stopinfo?line=' + s.line2 + '&stop=' + s.stop2) : $.Deferred().resolve(); + $.when(request1, request2).then(function(result1, result2) { + console.log('1:', result1); + console.log('2:', result2); + infowindow.setContent(makeStopInfo(s, result1, result2)); + //infowindow.setContent(name + "
" + s.name + "
" + "
" + data.direction1 + "
" + "
" + data.direction2 + "
"); + }); + } }); });