X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/914fff9d4dec3d502d524f5b0f60797f66f8af65..e72b6e6612e9a68e69b1d5f9f99260287410cc4f:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 85b4476f6..81c179a67 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -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 @@ -101,10 +106,14 @@ class GeocoderController < ApplicationController if klass == "boundary" && type == "administrative" rank = (place.attributes["address_rank"].to_i + 1) / 2 prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name + border_type = nil + place_type = nil place_tags = %w[linked_place place] place.elements["extratags"].elements.each("tag") do |extratag| - prefix_name = t "geocoder.search_osm_nominatim.prefix.place.#{extratag.attributes['value']}", :default => prefix_name if place_tags.include?(extratag.attributes["key"]) + border_type = t "geocoder.search_osm_nominatim.border_types.#{extratag.attributes['value']}", :default => border_type if extratag.attributes["key"] == "border_type" + place_type = t "geocoder.search_osm_nominatim.prefix.place.#{extratag.attributes['value']}", :default => place_type if place_tags.include?(extratag.attributes["key"]) end + prefix_name = place_type || border_type || prefix_name end prefix = t ".prefix_format", :name => prefix_name object_type = place.attributes["osm_type"] @@ -217,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)