diff --git a/static/js/map.js b/static/js/map.js index dd1714c8bdd882c19ac0cd60b5bb608b7dd89c7f..9f3489a89835b73c13085dd722a3e29ba9741f22 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -98,14 +98,15 @@ BusMap.Map = function(opts) { $.getJSON(url, params) .done(function(data) { // Store vehicle locations - that.vehicles = data.locations; + if (!that.vehicles) that.vehicles = []; + for (var v in data.locations) { + that.vehicles[v] = data.locations[v]; + that.vehicles[v].predictions = []; + } // Store predictions for (var s in that.stops) { that.stops[s].predictions = {}; } - for (var v in that.vehicles) { - that.vehicles[v].predictions = []; - } for (var p in data.predictions) { pr = data.predictions[p]; if (that.stops && pr.stop_id in that.stops) { @@ -120,7 +121,6 @@ BusMap.Map = function(opts) { that.vehicles[pr.vehicle].predictions.push(pr); } } - that.vehicles = data.locations; updateVehiclesUI(that.vehicles); updateStopsUI(that.stops); }); @@ -164,13 +164,13 @@ BusMap.Map = function(opts) { direction: 'right', clickable: true, }).bindPopup(text + footer, popupOpts).addTo(that.vehicleMarkersGroup); + that.vehicleMarkers[v].label.on('click', function() { + this._source.openPopup(); + }); } else { that.vehicleMarkers[v].setLatLng([vehicles[v].lat, vehicles[v].lon]) .setIconAngle(vehicles[v].heading); } - that.vehicleMarkers[v].label.on('click', function() { - this._source.openPopup(); - }); that.vehicleMarkers[v].bm_updated = Date.now() // Add predictions to the marker popup, if available