Skip to content
Snippets Groups Projects
Commit c81f72b8 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

Better view hash decoding (latlonzoom, stops, vehicles)

parent 5a5fe1e3
No related branches found
No related tags found
1 merge request!1Implemented Embed-code generator interface
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
var BusMap = { var BusMap = {
cookiePrefix: "BM_", cookiePrefix: "BM_",
zoomShowVehicles: 15, zoomShowVehicles: 15,
vehicleZoom: 16,
stopZoom: 16,
vehicleMaxAge: 10, vehicleMaxAge: 10,
}; };
...@@ -305,15 +307,42 @@ BusMap.Map = function(opts) { ...@@ -305,15 +307,42 @@ BusMap.Map = function(opts) {
+ that.leaflet.getZoom(); + that.leaflet.getZoom();
return view; 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() { function lastViewRecover() {
var last = BusMap.getCookie('last_view'); var last = BusMap.getCookie('last_view');
if (last && last != "") { return applyViewString(last);
last = last.split(",");
that.leaflet.setView([last[0], last[1]], last[2]);
return true;
} else {
return false;
}
} }
function lastViewStore() { function lastViewStore() {
var view = getViewString(); var view = getViewString();
...@@ -336,15 +365,7 @@ BusMap.Map = function(opts) { ...@@ -336,15 +365,7 @@ BusMap.Map = function(opts) {
that.setViewFromUrlHash = function() { that.setViewFromUrlHash = function() {
var hash = window.location.hash.substring(1); var hash = window.location.hash.substring(1);
hash = hash.split(","); return applyViewString(hash);
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;
} }
that.getUrlFromView = function() { that.getUrlFromView = function() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment