diff --git a/static/js/map.js b/static/js/map.js index 483e2a8c8155213894151128d18cd9310d460e24..836785e7519d5c89366b02111583abc7a54fbfee 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -3,7 +3,7 @@ var BusMap = { zoomShowVehicles: 15, stopZoom: 16, vehicleMaxAge: 10, - locateOptions = { timeout: 3000, }, + locateOptions: { timeout: 3000, }, }; /* @@ -426,7 +426,8 @@ BusMap.Map = function(opts) { // Scaling: update what is displayed based on zoom level function zoomShowHide() { var zoom = that.leaflet.getZoom(); - if (that.vehicleMarkersGroup) { + var got_vehicles = Object.keys(map.vehicleMarkers).length > 0; + if (got_vehicles && that.vehicleMarkersGroup) { if (zoom >= BusMap.zoomShowVehicles && !(that.leaflet.hasLayer(that.vehicleMarkersGroup))) { that.leaflet.addLayer(that.vehicleMarkersGroup); @@ -485,9 +486,15 @@ BusMap.Map = function(opts) { // Go to zoom level and map center where vehicles are visible. function goToVehicles() { - // TODO: this var zoom = BusMap.zoomShowVehicles; - console.log("going to zoom " + zoom); + var veh_keys = Object.keys(that.vehicleMarkers); + if (veh_keys.length > 0) { + var ll = that.vehicleMarkers[veh_keys[0]].getLatLng(); + } else { + var ll = that.leaflet.getCenter(); + } + console.log("setView("+ll+","+zoom+")"); + that.leaflet.setView(ll, zoom); } init();