From: Tom Hughes Date: Tue, 7 Aug 2007 23:51:02 +0000 (+0000) Subject: Only use the actual name that matched as the link, which helps to highlight it. X-Git-Tag: live~8247 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/bb43a46babaf2f2853cf33567380b085c02aea9e?hp=eb6114617c219baeeca957d9022f438e981c308e;ds=sidebyside Only use the actual name that matched as the link, which helps to highlight it. --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 34a90935e..1b9ca05b5 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -31,7 +31,8 @@ private unless response.match(/couldn't find this zip/) data = response.split(/\s*,\s+/) # lat,long,town,state,zip results.push({:lat => data[0], :lon => data[1], :zoom => 12, - :description => "#{data[2]}, #{data[3]}, #{data[4]}"}) + :prefix => "#{data[2]}, #{data[3]}, ", + :name => data[4]}) end return { :source => "Geocoder.us", :url => "http://geocoder.us/", :results => results } @@ -50,7 +51,7 @@ private dataline = response.split(/\n/)[1] data = dataline.split(/,/) # easting,northing,postcode,lat,long results.push({:lat => data[3], :lon => data[4], :zoom => 12, - :description => data[2].gsub(/'/, "")}) + :name => data[2].gsub(/'/, "")}) end return { :source => "NPEMap / FreeThePostcode", :url => "http://www.npemap.org.uk/", :results => results } @@ -69,7 +70,7 @@ private results.push({:lat => response.get_text("geodata/latt").to_s, :lon => response.get_text("geodata/longt").to_s, :zoom => 12, - :description => query.upcase}) + :name => query.upcase}) end return { :source => "Geocoder.CA", :url => "http://geocoder.ca/", :results => results } @@ -91,15 +92,19 @@ private place = named.elements["place/named"] || named.elements["nearestplaces/named"] type = named.attributes["info"].to_s.capitalize name = named.attributes["name"].to_s + description = named.elements["description"].to_s if place distance = format_distance(place.attributes["approxdistance"].to_i) direction = format_direction(place.attributes["direction"].to_i) placename = place.attributes["name"].to_s results.push({:lat => lat, :lon => lon, :zoom => zoom, - :description => "#{type} #{name}, #{distance} #{direction} of #{placename}"}) + :prefix => "#{type} ", :name => name, + :suffix => ", #{distance} #{direction} of #{placename}", + :description => description}) else results.push({:lat => lat, :lon => lon, :zoom => zoom, - :description => "#{type} #{name}"}) + :prefix => "#{type} ", :name => name, + :description => description}) end end @@ -121,7 +126,8 @@ private name = geoname.get_text("name").to_s country = geoname.get_text("countryName").to_s results.push({:lat => lat, :lon => lon, :zoom => 12, - :description => "#{name}, #{country}"}) + :name => name, + :suffix => ", #{country}"}) end return { :source => "GeoNames", :url => "http://www.geonames.org/", :results => results } diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb new file mode 100644 index 000000000..879b1dca1 --- /dev/null +++ b/app/helpers/geocoder_helper.rb @@ -0,0 +1,11 @@ +module GeocoderHelper + def result_to_html(result) + html_options = {} + #html_options[:title] = strip_tags(result[:description]) if result[:description] + html = "" + html << result[:prefix] if result[:prefix] + html << link_to_function(result[:name], "setPosition(#{result[:lat]}, #{result[:lon]}, #{result[:zoom]})", html_options) + html << result[:suffix] if result[:suffix] + return html + end +end diff --git a/app/views/geocoder/search.rhtml b/app/views/geocoder/search.rhtml index a3674f745..7ffde3194 100644 --- a/app/views/geocoder/search.rhtml +++ b/app/views/geocoder/search.rhtml @@ -5,7 +5,7 @@

No results found

<% else %> <% source[:results].each do |result| %> -

<%= link_to_function result[:description], "setPosition(#{result[:lat]}, #{result[:lon]}, #{result[:zoom]})" %>

+

<%= result_to_html(result) %>

<% end %> <% end %> <% else %>