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_content").load($(this).attr("action"), {
25 query: $("#query").val(),
27 minlon: bounds.getWest(),
28 minlat: bounds.getSouth(),
29 maxlon: bounds.getEast(),
30 maxlat: bounds.getNorth()
33 $("#sidebar").one("closed", function () {
34 map.removeLayer(marker);
39 function clickSearchResult(e) {
42 var data = $(this).data(),
43 center = L.latLng(data.lat, data.lon);
45 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
46 map.fitBounds([[data.minLat, data.minLon],
47 [data.maxLat, data.maxLon]]);
49 map.setView(center, data.zoom);
56 if (data.type && data.id) {
57 map.addObject(data, { zoom: false, style: { opacity: 0.2, fill: false } });
61 function describeLocation(e) {
64 var center = map.getCenter(),
67 $("#sidebar_content").load($(this).attr("href"), {