]> git.openstreetmap.org Git - rails.git/blob - app/helpers/geocoder_helper.rb
Merge pull request #6394 from openstreetmap/dependabot/github_actions/ruby/setup...
[rails.git] / app / helpers / geocoder_helper.rb
1 # frozen_string_literal: true
2
3 module GeocoderHelper
4   def result_to_html(result)
5     html_options = { :class => "set_position stretched-link", :data => {} }
6
7     url = if result[:type] && result[:id]
8             url_for(:controller => "/#{result[:type].pluralize}", :action => :show, :id => result[:id])
9           elsif result[:min_lon] && result[:min_lat] && result[:max_lon] && result[:max_lat]
10             "/?bbox=#{result[:min_lon]},#{result[:min_lat]},#{result[:max_lon]},#{result[:max_lat]}"
11           else
12             "/##{map_hash(result)}"
13           end
14
15     result.each do |key, value|
16       html_options[:data][key.to_s.tr("_", "-")] = value
17     end
18
19     html = []
20     html << result[:prefix] if result[:prefix]
21     html << " " if result[:prefix] && result[:name]
22     html << link_to(result[:name], url, html_options) if result[:name]
23     html << " " if result[:suffix] && result[:name]
24     html << result[:suffix] if result[:suffix]
25     safe_join(html)
26   end
27
28   def map_hash(params)
29     return nil unless params[:lat].present? && params[:lon].present?
30
31     "map=#{params[:zoom] || 17}/#{params[:lat]}/#{params[:lon]}"
32   end
33
34   def describe_location(lat, lon, zoom = nil, language = nil)
35     Nominatim.describe_location(lat, lon, zoom, language)
36   end
37 end