diff --git a/static/js/map.js b/static/js/map.js index e48570b10c58e08a6ea3de4197f291a5d7aac9d8..dd1714c8bdd882c19ac0cd60b5bb608b7dd89c7f 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -2,6 +2,8 @@ var BusMap = { cookiePrefix: "BM_", zoomShowVehicles: 15, + vehicleZoom: 16, + stopZoom: 16, vehicleMaxAge: 10, }; @@ -305,15 +307,42 @@ BusMap.Map = function(opts) { + that.leaflet.getZoom(); return view; } + function applyViewString(view) { + if (!view || view == "") return false; + if (view.charAt(0) == "s") return _avsStop(view); + if (view.charAt(0) == "v") return _avsVehicle(view); + window.location.replace("#" + view); + return _avsLatLonZoom(view); + function _avsStop(view) { + if (!that.stopMarkers) { + return setTimeout(function() { _avsStop(view) }, 500); + } + var marker = that.stopMarkers[view.substring(1)]; + var ll = marker.getLatLng(); + that.leaflet.setView(ll, that.stopZoom); + marker.openPopup(); + } + function _avsVehicle(view) { + if (!that.vehicleMarkers) { + return setTimeout(function() { _avsVehicle(view) }, 500); + } + var marker = that.vehicleMarkers[view.substring(1)]; + var ll = marker.getLatLng(); + that.leaflet.setView(ll, that.vehicleZoom); + marker.openPopup(); + } + function _avsLatLonZoom(view) { + view = view.split(","); + if (view.length == 3) { + that.leaflet.setView([view[0], view[1]], view[2]); + } else if (view.length == 2) { + that.leaflet.setView([view[0], view[1]]); + } else return false; + } + } function lastViewRecover() { var last = BusMap.getCookie('last_view'); - if (last && last != "") { - last = last.split(","); - that.leaflet.setView([last[0], last[1]], last[2]); - return true; - } else { - return false; - } + return applyViewString(last); } function lastViewStore() { var view = getViewString(); @@ -336,15 +365,7 @@ BusMap.Map = function(opts) { that.setViewFromUrlHash = function() { var hash = window.location.hash.substring(1); - hash = hash.split(","); - if (hash.length == 2) { - that.leaflet.setView([hash[0],hash[1]]); - return true; - } else if (hash.length == 3) { - that.leaflet.setView([hash[0],hash[1]], hash[2]); - return true; - } - return false; + return applyViewString(hash); } that.getUrlFromView = function() {