Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix links in station popups, make station links in the vehicle timeta…

…ble open the station popup.
  • Loading branch information...
commit 13b63852d589643c1095ef7eb0dac6e4ded449c3 1 parent 96e35e9
@kurtraschke authored
Showing with 32 additions and 25 deletions.
  1. +25 −20 static/js/station.js
  2. +7 −5 static/js/vehicle_helpers.js
View
45 static/js/station.js
@@ -1,7 +1,7 @@
define(['jquery', 'async!http://maps.googleapis.com/maps/api/js' +
'?v=3.7&sensor=false&libraries=geometry!callback',
- 'map_layers_add', 'simulation_manager', 'timer', 'vehiclesPool'],
-function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool) {
+ 'map_layers_add', 'simulation_manager', 'timer', 'vehiclesPool', 'stationsPool'],
+function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool, stationsPool) {
function vehiclesForStation(vehicles, stopID) {
@@ -57,8 +57,7 @@ function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool) {
$.each(vehicle_info[1], function(idx, vehicle) {
var seconds = vehicle.status.when - timer.getTime();
tbody.append($('<tr></tr>').append(
- $('<td></td>').append($('<a href=""></a>').append(
- vehicle.name).click(clickVehicle(vehicle))),
+ $('<td></td>').append($('<a href=""></a>').append(vehicle.name).click(clickVehicle(vehicle))),
$('<td></td>').append(vehicle.direction),
$('<td></td>').append(vehicle.status.track),
$('<td></td>').append('Departing in ' + seconds + ' seconds'))
@@ -68,22 +67,21 @@ function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool) {
$.each(vehicle_info[0], function(idx, vehicle) {
var seconds = vehicle.status.when - timer.getTime();
tbody.append($('<tr></tr>').append(
- $('<td></td>').append($('<a href=""></a>').append(
- vehicle.name).click(clickVehicle(vehicle))),
+ $('<td></td>').append($('<a href=""></a>').append(vehicle.name).click(clickVehicle(vehicle))),
$('<td></td>').append(vehicle.direction),
$('<td></td>').append(vehicle.status.track),
$('<td></td>').append('Arriving in ' + seconds + ' seconds'))
);
});
-
-
}
- var out = $('<div></div>').append(div).html();
- return out;
+ var out = $('<div></div>').append(div);
+ return out.get(0);
}
+ var setupPopup;
+
simulation_manager.subscribe('map_init', function() {
var station_ib;
@@ -102,18 +100,20 @@ function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool) {
}
);
-
- google.maps.event.addListener(map_layers['stations'], 'click', function(event) {
- //if (station_ib.get('station_id') === event.row.id.value) { return; }
- station_ib.set('station_id', event.row.id.value);
- station_ib.set('station_name', event.row.name.value);
-
+ setupPopup = function(station_id, station_name, latlng) {
station_ib.close();
+ station_ib.set('station_id', station_id);
+ station_ib.set('station_name', station_name);
- station_ib.setContent(updateStationPopup(event.row.id.value,
- event.row.name.value));
- station_ib.setPosition(event.latLng);
+ station_ib.setContent(updateStationPopup(station_id, station_name));
+ station_ib.setPosition(latlng);
station_ib.open(map);
+ };
+
+
+ google.maps.event.addListener(map_layers['stations'], 'click', function(event) {
+ //if (station_ib.get('station_id') === event.row.id.value) { return; }
+ setupPopup(event.row.id.value, event.row.name.value, event.latLng);
});
setInterval(function() {
@@ -124,7 +124,12 @@ function(_jquery, _gmaps, map_layers, simulation_manager, timer, vehiclesPool) {
}, 1000);
});
- return;
+
+
+ return {'openPopup': function(station_id) {
+ setupPopup(station_id, stationsPool.get(station_id),
+ stationsPool.location_get(station_id));
+ }};
});
View
12 static/js/vehicle_helpers.js
@@ -1,8 +1,10 @@
define(['jquery',
'async!http://maps.googleapis.com/maps/api/js' +
'?v=3.7&sensor=false&libraries=geometry!callback',
- 'vehicle', 'vehicleFollower', 'linesPool', 'stationsPool', 'vehiclesPool'],
-function(_jquery, _gmaps, Vehicle, vehicleFollower, linesPool, stationsPool, vehiclesPool) {
+ 'vehicle', 'vehicleFollower', 'linesPool', 'stationsPool', 'vehiclesPool',
+ 'station', 'simulation_manager'],
+function(_jquery, _gmaps, Vehicle, vehicleFollower, linesPool, stationsPool, vehiclesPool,
+ station, simulation_manager) {
// Vehicle helpers
// Roles:
@@ -31,7 +33,8 @@ function(_jquery, _gmaps, Vehicle, vehicleFollower, linesPool, stationsPool, veh
$(this).val(value_new);
});
- $('#vehicle_timetable tbody tr a').live('click', function() {
+ $('#vehicle_timetable tbody tr a').live('click', function(event) {
+ event.preventDefault();
var station_location = stationsPool.location_get(
$(this).attr('data-station-id'));
if (parseInt(station_location.lng(), 10) === 0) { return; }
@@ -40,8 +43,7 @@ function(_jquery, _gmaps, Vehicle, vehicleFollower, linesPool, stationsPool, veh
if (map.getZoom() < simulation_manager.getParam('zoom_station')) {
map.setZoom(simulation_manager.getParam('zoom_station'));
}
-
- return false;
+ station.openPopup($(this).attr('data-station-id'));
});
/*Vehicle was here*/
Please sign in to comment.
Something went wrong with that request. Please try again.