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