+
+ var history = OSM.History(map),
+ note = OSM.Note(map);
+
+ OSM.route = OSM.Router(map, {
+ "/": OSM.Index(map),
+ "/search": OSM.Search(map),
+ "/export": OSM.Export(map),
+ "/history": history,
+ "/new_note": OSM.NewNote(map),
+ "/user/:display_name/edits": history,
+ "/browse/friends": history,
+ "/browse/nearby": history,
+ "/browse/note/:id": note,
+ "/browse/:type/:id(/history)": OSM.Browse(map)
+ });
+
+ $(document).on("click", "a", function(e) {
+ if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
+ if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
+ });
+
+ $(".search_form").on("submit", function(e) {
+ e.preventDefault();
+ $("header").addClass("closed");
+ var query = $(this).find("input[name=query]").val();
+ if (query) {
+ OSM.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
+ } else {
+ OSM.route("/" + OSM.formatHash(map));
+ }
+ });
+
+ $(".describe_location").on("click", function(e) {
+ e.preventDefault();
+ var precision = zoomPrecision(map.getZoom());
+ OSM.route("/search?query=" + encodeURIComponent(
+ map.getCenter().lat.toFixed(precision) + "," +
+ map.getCenter().lng.toFixed(precision)));
+ });
+});