From c776989db5be80157ca831bec64a57f77e0f77a0 Mon Sep 17 00:00:00 2001 From: Anton Sarukhanov <code@ant.sr> Date: Tue, 17 May 2016 21:39:29 -0400 Subject: [PATCH] Half-ass solution to #8. --- static/js/map.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/static/js/map.js b/static/js/map.js index 483e2a8..836785e 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(); -- GitLab