1 function initializeSearch(map) {
2 $("#search_form").submit(submitSearch);
3 $("#describe_location").click(describeLocation);
5 if ($("#query").val()) {
6 $("#search_form").submit();
9 // Focus the search field for browsers that don't support
10 // the HTML5 'autofocus' attribute
11 if (!("autofocus" in document.createElement("input"))) {
15 $("#sidebar_content").on("click", ".search_results_entry a.set_position", clickSearchResult);
17 var marker = L.marker([0, 0], {icon: getUserIcon()});
19 function submitSearch(e) {
22 var bounds = map.getBounds();
24 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
25 $("#sidebar_content").load($(this).attr("action"), {
26 query: $("#query").val(),
28 minlon: bounds.getWest(),
29 minlat: bounds.getSouth(),
30 maxlon: bounds.getEast(),
31 maxlat: bounds.getNorth()
36 $("#sidebar").one("closed", function () {
37 map.removeLayer(marker);
42 function clickSearchResult(e) {
45 var data = $(this).data(),
46 center = L.latLng(data.lat, data.lon);
48 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
49 map.fitBounds([[data.minLat, data.minLon],
50 [data.maxLat, data.maxLon]]);
52 map.setView(center, data.zoom);
59 if (data.type && data.id) {
60 map.addObject(data, { zoom: false, style: { opacity: 0.2, fill: false } });
64 function describeLocation(e) {
67 var center = map.getCenter(),
70 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
71 $("#sidebar_content").load($(this).attr("href"), {