X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9cc9a0098840363b6497337951b53aa583f4aa44..c6e8775dbab81daf9515fe94fa0ed4c51cab5f3b:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index d07c9797d..74ec05823 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') { @@ -228,7 +231,7 @@ $(document).ready(function () { page.load = function() { if (!("autofocus" in document.createElement("input"))) { - $(".search_form input[name=query]").focus(); + $("#sidebar .search_form input[name=query]").focus(); } return map.getState(); }; @@ -321,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)); + } } }); @@ -337,4 +346,21 @@ $(document).ready(function () { map.getCenter().lat.toFixed(precision) + "," + map.getCenter().lng.toFixed(precision))); }); + + $(".get_directions").on("click",function(e) { + e.preventDefault(); + $(".query_wrapper.search").hide(); + $(".query_wrapper.routing").show(); + $(".query_wrapper.routing [name=route_from]").focus(); + }); + + $(".close_directions").on("click",function(e) { + e.preventDefault(); + $(".query_wrapper.search").show(); + $(".query_wrapper.routing").hide(); + $(".query_wrapper.search [name=query]").focus(); + }); + + OSM.routing = OSM.Routing(map,'OSM.routing',$('.query_wrapper.routing')); + });