X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/24893c0936d4634e2caf0225e920a6d4c19b164c..15c156483263893d2c767030bd544d589833af93:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index d7a14c312..a3531eb30 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -5,6 +5,7 @@ //= require leaflet.key //= require leaflet.note //= require leaflet.share +//= require leaflet.polyline //= require index/search //= require index/browse //= require index/export @@ -13,6 +14,7 @@ //= require index/note //= require index/new_note //= require router +//= require routing (function() { var loaderTimeout; @@ -150,7 +152,8 @@ $(document).ready(function () { map.getLayersCode(), map._object); - $.cookie("_osm_location", cookieContent(map), { expires: expiry }); + $.removeCookie("_osm_location"); + $.cookie("_osm_location", cookieContent(map), { expires: expiry, path: "/" }); }); if ($.cookie('_osm_welcome') == 'hide') { @@ -227,6 +230,9 @@ $(document).ready(function () { }; page.load = function() { + if (!("autofocus" in document.createElement("input"))) { + $("#sidebar .search_form input[name=query]").focus(); + } return map.getState(); }; @@ -250,14 +256,24 @@ $(document).ready(function () { page.pushstate = page.popstate = function(path, id) { OSM.loadSidebarContent(path, function() { - page.load(path, id); + addObject(type, id); }); }; page.load = function(path, id) { - map.addObject({type: type, id: parseInt(id)}); + addObject(type, id, true); }; + function addObject(type, id, center) { + var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) { + if (!window.location.hash && bounds.isValid()) { + OSM.router.moveListenerOff(); + map.once('moveend', OSM.router.moveListenerOn); + if (center || !map.getBounds().contains(bounds)) map.fitBounds(bounds); + } + }); + } + page.unload = function() { map.removeObject(); }; @@ -308,12 +324,18 @@ $(document).ready(function () { $(".search_form").on("submit", function(e) { e.preventDefault(); - $("header").addClass("closed"); - var query = $(this).find("input[name=query]").val(); - if (query) { - OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map)); + if ($(".query_wrapper.routing").is(":visible")) { + // Routing + OSM.routing.requestRoute(); } else { - OSM.router.route("/" + OSM.formatHash(map)); + // 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)); + } } }); @@ -324,4 +346,22 @@ $(document).ready(function () { map.getCenter().lat.toFixed(precision) + "," + map.getCenter().lng.toFixed(precision))); }); + + OSM.routing = OSM.Routing(map,'OSM.routing',$('.query_wrapper.routing')); + + $(".get_directions").on("click",function(e) { + e.preventDefault(); + $(".search").hide(); + $(".routing").show(); + $(".query_wrapper.routing [name=route_from]").focus(); + }); + + $(".close_directions").on("click",function(e) { + e.preventDefault(); + $(".search").show(); + $(".routing").hide(); + OSM.routing.close(); + $(".query_wrapper.search [name=query]").focus(); + }); + });