From 381a7d2d05d25d3fdc6a1f3e80e41c4f0c7c5d22 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Sat, 9 Apr 2016 20:01:39 -0400
Subject: [PATCH] js logic bugfix

---
 static/js/map.js | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/static/js/map.js b/static/js/map.js
index dd1714c..9f3489a 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
-- 
GitLab