1 OSM.Search = function(map) {
2 $(".search_form input[name=query]")
3 .on("input", function(e) {
4 if ($(e.target).val() == "") {
5 $(".describe_location").fadeIn(100);
7 $(".describe_location").fadeOut(100);
12 .on("click", ".search_more a", clickSearchMore)
13 .on("click", ".search_results_entry a.set_position", clickSearchResult);
15 function clickSearchMore(e) {
19 var div = $(this).parents(".search_more");
22 div.find(".loader").show();
24 $.get($(this).attr("href"), function(data) {
25 div.replaceWith(data);
29 function clickSearchResult(e) {
30 var data = $(this).data(),
31 center = L.latLng(data.lat, data.lon);
33 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
34 map.fitBounds([[data.minLat, data.minLon], [data.maxLat, data.maxLon]]);
36 map.setView(center, data.zoom);
39 // Let clicks to object browser links propagate.
40 if (data.type && data.id) return;
42 marker.setLatLng(center).addTo(map);
48 var marker = L.marker([0, 0], {icon: getUserIcon()});
52 page.pushstate = page.popstate = function(path) {
53 var params = querystring.parse(path.substring(path.indexOf('?') + 1));
54 $(".search_form input[name=query]").val(params.query);
55 OSM.loadSidebarContent(path, page.load);
58 page.load = function() {
59 $(".search_results_entry").each(function() {
62 url: entry.data("href"),
66 minlon: map.getBounds().getWest(),
67 minlat: map.getBounds().getSouth(),
68 maxlon: map.getBounds().getEast(),
69 maxlat: map.getBounds().getNorth()
71 success: function(html) {
77 return map.getState();
80 page.unload = function() {
81 map.removeLayer(marker);
83 $(".search_form input[name=query]").val("");
84 $(".describe_location").fadeIn(100);