]> git.openstreetmap.org Git - rails.git/commitdiff
Add a "More results" link to Nominatim search results.
authorTom Hughes <tom@compton.nu>
Wed, 6 Jan 2010 00:30:29 +0000 (00:30 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 6 Jan 2010 00:30:29 +0000 (00:30 +0000)
app/controllers/geocoder_controller.rb
app/views/geocoder/results.html.erb
config/locales/en.yml

index 85e056a55d6f6cef28ef7f2462edcdb986751b1e..e0f8823851e6221321cba6d6f4f087c4507090f4 100644 (file)
@@ -228,14 +228,25 @@ class GeocoderController < ApplicationController
       viewbox = "&viewbox=#{minlon},#{maxlat},#{maxlon},#{minlat}"
     end
 
+    # get objects to excude
+    if params[:exclude]
+      exclude = "&exclude_place_ids=#{params[:exclude].join(',')}"
+    end
+
+    # ask nominatim
+    response = fetch_xml("http://nominatim.openstreetmap.org/search?format=xml&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{request.user_preferred_languages.join(',')}")
+
     # create result array
     @results = Array.new
 
-    # ask nominatim
-    response = fetch_xml("http://nominatim.openstreetmap.org/search?format=xml&q=#{escape_query(query)}#{viewbox}&accept-language=#{request.user_preferred_languages.join(',')}")
+    # create parameter hash for "more results" link
+    @more_params = params.reverse_merge({ :exclude => [] })
+
+    # extract the results from the response
+    results =  response.elements["searchresults"]
 
     # parse the response
-    response.elements.each("searchresults/place") do |place|
+    results.elements.each("place") do |place|
       lat = place.attributes["lat"].to_s
       lon = place.attributes["lon"].to_s
       klass = place.attributes["class"].to_s
@@ -248,6 +259,7 @@ class GeocoderController < ApplicationController
                      :min_lat => min_lat, :max_lat => max_lat,
                      :min_lon => min_lon, :max_lon => max_lon,
                      :prefix => prefix, :name => name})
+      @more_params[:exclude].push(place.attributes["place_id"].to_s)
     end
 
     render :action => "results"
index 70051c91c9b3bbeb53cf0b5e419ab0640700197d..694d0eadb2f82d8347f6490a79d0bdef23245359 100644 (file)
@@ -4,4 +4,18 @@
   <% @results.each do |result| %>
     <p class="search_results_entry"><%= result_to_html(result) %></p>
   <% end %>
+  <% if @more_params %>
+    <div id="search_more_<%= @more_params.hash %>">
+      <p class="search_results_entry"><%=
+        startSpinner = update_page do |page|
+                         page.replace_html "search_more_#{@more_params.hash}", image_tag("searching.gif", :class => "search_searching")
+                       end
+
+        link_to_remote t('geocoder.results.more_results'),
+          :update => "search_more_#{@more_params.hash}",
+          :before => startSpinner,
+          :url => @more_params
+        %></p>
+    </div>
+  <% end %>
 <% end %>
index 4fd3e9967a390a80df038a3a66026bd914692f26..adaa7e662f4486da931f17508ab4b2febef95855 100644 (file)
@@ -839,6 +839,7 @@ en:
       prefix: "{{distance}} {{direction}} of {{type}}"
     results:
       no_results: "No results found"
+      more_results: "More results"
     distance:
       zero: "less than 1km"
       one: "about 1km"