+
+ var page = {};
+
+ page.pushstate = page.popstate = function (path) {
+ var params = Qs.parse(path.substring(path.indexOf("?") + 1));
+ if (params.query) {
+ $(".search_form input[name=query]").val(params.query);
+ $(".describe_location").hide();
+ } else if (params.lat && params.lon) {
+ $(".search_form input[name=query]").val(params.lat + ", " + params.lon);
+ $(".describe_location").hide();
+ }
+ OSM.loadSidebarContent(path, page.load);
+ };
+
+ page.load = function () {
+ $(".search_results_entry").each(function (index) {
+ var entry = $(this),
+ csrf_param = $("meta[name=csrf-param]").attr("content"),
+ csrf_token = $("meta[name=csrf-token]").attr("content"),
+ params = {
+ zoom: map.getZoom(),
+ minlon: map.getBounds().getWest(),
+ minlat: map.getBounds().getSouth(),
+ maxlon: map.getBounds().getEast(),
+ maxlat: map.getBounds().getNorth()
+ };
+ params[csrf_param] = csrf_token;
+ $.ajax({
+ url: entry.data("href"),
+ method: "POST",
+ data: params,
+ success: function (html) {
+ entry.html(html);
+ // go to first result of first geocoder
+ if (index === 0) {
+ var firstResult = entry.find("*[data-lat][data-lon]:first").first();
+ if (firstResult.length) {
+ panToSearchResult(firstResult.data());
+ }
+ }
+ }
+ });
+ });
+
+ return map.getState();
+ };
+
+ page.unload = function () {
+ markers.clearLayers();
+ $(".search_form input[name=query]").val("");
+ $(".describe_location").fadeIn(100);
+ };
+
+ return page;
+};