X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/dae3dcf87edcfc0648cd0b93b069b0eee67d3ab7..a20e28809f5ca1e3f3579faeaf118fff3ecc4994:/app/assets/javascripts/index/search.js diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index 9481e271e..52af38c54 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -95,15 +95,18 @@ OSM.Search = function(map) { $(this).closest("li").removeClass("selected"); } - function clickSearchResult(e) { - var data = $(this).data(), - center = L.latLng(data.lat, data.lon); - + function panToSearchResult(data) { if (data.minLon && data.minLat && data.maxLon && data.maxLat) { map.fitBounds([[data.minLat, data.minLon], [data.maxLat, data.maxLon]]); } else { - map.setView(center, data.zoom); + map.setView([data.lat, data.lon], data.zoom); } + } + + function clickSearchResult(e) { + var data = $(this).data(); + + panToSearchResult(data); // Let clicks to object browser links propagate. if (data.type && data.id) return; @@ -124,7 +127,7 @@ OSM.Search = function(map) { }; page.load = function() { - $(".search_results_entry").each(function() { + $(".search_results_entry").each(function(index) { var entry = $(this); $.ajax({ url: entry.data("href"), @@ -138,6 +141,13 @@ OSM.Search = function(map) { }, 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()); + } + } } }); });