Permalinks for directions

This commit is contained in:
John Firebaugh 2014-05-13 11:21:48 -07:00
parent 2b252e8337
commit f2bf38606e
14 changed files with 244 additions and 208 deletions

View file

@ -16,10 +16,12 @@
//= require index/directions
//= require router
(function() {
$(document).ready(function () {
var loaderTimeout;
OSM.loadSidebarContent = function(path, callback) {
map.setSidebarOverlaid(false);
clearTimeout(loaderTimeout);
loaderTimeout = setTimeout(function() {
@ -67,9 +69,7 @@
}
});
};
})();
$(document).ready(function () {
var params = OSM.mapParams();
var map = new L.OSM.Map("map", {
@ -222,10 +222,8 @@ $(document).ready(function () {
OSM.Index = function(map) {
var page = {};
page.pushstate = function() {
$("#content").addClass("overlay-sidebar");
map.invalidateSize({pan: false})
.panBy([-350, 0], {animate: false});
page.pushstate = page.popstate = function() {
map.setSidebarOverlaid(true);
document.title = I18n.t('layouts.project_name.title');
};
@ -236,18 +234,6 @@ $(document).ready(function () {
return map.getState();
};
page.popstate = function() {
$("#content").addClass("overlay-sidebar");
map.invalidateSize({pan: false});
document.title = I18n.t('layouts.project_name.title');
};
page.unload = function() {
map.panBy([350, 0], {animate: false});
$("#content").removeClass("overlay-sidebar");
map.invalidateSize({pan: false});
};
return page;
};
@ -281,12 +267,12 @@ $(document).ready(function () {
return page;
};
var directions = OSM.Directions(map);
var history = OSM.History(map);
OSM.router = OSM.Router(map, {
"/": OSM.Index(map),
"/search": OSM.Search(map),
"/directions": OSM.Directions(map),
"/export": OSM.Export(map),
"/note/new": OSM.NewNote(map),
"/history/friends": history,
@ -322,29 +308,4 @@ $(document).ready(function () {
if (OSM.router.route(this.pathname + this.search + this.hash))
e.preventDefault();
});
$(".search_form").on("submit", function(e) {
e.preventDefault();
if ($(".query_wrapper.routing").is(":visible")) {
// Directions
directions.requestRoute(true, true);
} else {
// Search
$("header").addClass("closed");
var query = $(this).find("input[name=query]").val();
if (query) {
OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
} else {
OSM.router.route("/" + OSM.formatHash(map));
}
}
});
$(".describe_location").on("click", function(e) {
e.preventDefault();
var precision = OSM.zoomPrecision(map.getZoom());
OSM.router.route("/search?query=" + encodeURIComponent(
map.getCenter().lat.toFixed(precision) + "," +
map.getCenter().lng.toFixed(precision)));
});
});