+
+ OSM.router.load();
+
+ $(document).on("click", "a", function(e) {
+ if (e.isDefaultPrevented() || e.isPropagationStopped())
+ return;
+
+ // Open links in a new tab as normal.
+ if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
+ return;
+
+ // Ignore cross-protocol and cross-origin links.
+ if (location.protocol !== this.protocol || location.host !== this.host)
+ return;
+
+ 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")) {
+ // Routing
+ OSM.routing.requestRoute();
+ } 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 = zoomPrecision(map.getZoom());
+ OSM.router.route("/search?query=" + encodeURIComponent(
+ 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'));
+