1 function initializeSearch(map) {
2 $("#search_form").submit(submitSearch);
4 if ($("#query").val()) {
5 $("#search_form").submit();
8 // Focus the search field for browsers that don't support
9 // the HTML5 'autofocus' attribute
10 if (!("autofocus" in document.createElement("input"))) {
14 $("#sidebar_content").on("click", ".search_results_entry a.set_position", clickSearchResult);
16 var marker = L.marker([0, 0], {icon: getUserIcon()});
18 function submitSearch(e) {
21 var bounds = map.getBounds();
23 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
24 $("#sidebar_content").load($(this).attr("action"), {
25 query: $("#query").val(),
26 minlon: bounds.getWest(),
27 minlat: bounds.getSouth(),
28 maxlon: bounds.getEast(),
29 maxlat: bounds.getNorth()
34 $("#sidebar").one("closed", function () {
35 map.removeLayer(marker);
40 function clickSearchResult(e) {
43 var data = $(this).data(),
44 center = L.latLng(data.lat, data.lon);
46 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
47 map.fitBounds([[data.minLat, data.minLon],
48 [data.maxLat, data.maxLon]]);
50 map.setView(center, data.zoom);
57 if (data.type && data.id) {
58 map.addObject(data, { zoom: false, style: { opacity: 0.2, fill: false } });