]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/geocoder_controller.rb
Add history changesets layer module
[rails.git] / app / controllers / geocoder_controller.rb
index 5f3b4dbb65875dab909f1dc5c482d20bcb5f1d35..81c179a677576d345515171feefa3f6101e5ecb3 100644 (file)
@@ -6,17 +6,22 @@ class GeocoderController < ApplicationController
   before_action :authorize_web
   before_action :set_locale
   before_action :require_oauth, :only => [:search]
+
   authorize_resource :class => false
 
+  before_action :normalize_params, :only => [:search]
+
   def search
-    @params = normalize_params
     @sources = []
 
-    if @params[:lat] && @params[:lon]
-      @sources.push(:name => "latlon", :url => root_path)
-      @sources.push(:name => "osm_nominatim_reverse", :url => nominatim_reverse_url(:format => "html"))
-    elsif @params[:query]
-      @sources.push(:name => "osm_nominatim", :url => nominatim_url(:format => "html"))
+    if params[:lat] && params[:lon]
+      @sources.push(:name => "latlon", :url => root_path,
+                    :fetch_url => url_for(params.permit(:lat, :lon, :latlon_digits, :zoom).merge(:action => "search_latlon")))
+      @sources.push(:name => "osm_nominatim_reverse", :url => nominatim_reverse_url(:format => "html"),
+                    :fetch_url => url_for(params.permit(:lat, :lon, :zoom).merge(:action => "search_osm_nominatim_reverse")))
+    elsif params[:query]
+      @sources.push(:name => "osm_nominatim", :url => nominatim_url(:format => "html"),
+                    :fetch_url => url_for(params.permit(:query, :minlat, :minlon, :maxlat, :maxlon).merge(:action => "search_osm_nominatim")))
     end
 
     if @sources.empty?
@@ -34,13 +39,13 @@ class GeocoderController < ApplicationController
       # We've got two nondescript numbers for a query, which can mean both "lat, lon" or "lon, lat".
       @results = []
 
-      if lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180
+      if lat.between?(-90, 90) && lon.between?(-180, 180)
         @results.push(:lat => params[:lat], :lon => params[:lon],
                       :zoom => params[:zoom],
                       :name => "#{params[:lat]}, #{params[:lon]}")
       end
 
-      if lon >= -90 && lon <= 90 && lat >= -180 && lat <= 180
+      if lon.between?(-90, 90) && lat.between?(-180, 180)
         @results.push(:lat => params[:lon], :lon => params[:lat],
                       :zoom => params[:zoom],
                       :name => "#{params[:lon]}, #{params[:lat]}")
@@ -54,10 +59,10 @@ class GeocoderController < ApplicationController
       end
     else
       # Coordinates in a query have come with markers for latitude and longitude.
-      if lat < -90 || lat > 90
+      if !lat.between?(-90, 90)
         @error = "Latitude #{lat} out of range"
         render :action => "error"
-      elsif lon < -180 || lon > 180
+      elsif !lon.between?(-180, 180)
         @error = "Longitude #{lon} out of range"
         render :action => "error"
       else
@@ -221,8 +226,6 @@ class GeocoderController < ApplicationController
         params[:latlon_digits] = true
       end
     end
-
-    params.permit(:query, :lat, :lon, :latlon_digits, :zoom, :minlat, :minlon, :maxlat, :maxlon)
   end
 
   def dms_regexp(name_prefix)