Add the search boxes to the edit page.
This commit is contained in:
parent
c99992f85f
commit
f7f2b7482d
5 changed files with 53 additions and 37 deletions
|
@ -39,13 +39,13 @@ class GeocoderController < ApplicationController
|
|||
Net::HTTP.start('rpc.geocoder.us') do |http|
|
||||
resp = http.get("/service/csv?zip=#{postcode}")
|
||||
if resp.body.match(/couldn't find this zip/)
|
||||
redirect_to "/index.html?error=invalid_zip_code"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :error => "invalid_zip_code"
|
||||
return
|
||||
end
|
||||
data = resp.body.split(/, /) # lat,long,town,state,zip
|
||||
lat = data[0]
|
||||
lon = data[1]
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :mlat => lat, :mlon => lon, :zoom => 14
|
||||
return
|
||||
end
|
||||
elsif postcode.match(/^([A-Z]{1,2}\d+[A-Z]?\s*\d[A-Z]{2})/)
|
||||
|
@ -57,7 +57,7 @@ class GeocoderController < ApplicationController
|
|||
data = dataline.split(/,/) # easting,northing,postcode,lat,long
|
||||
lat = data[3]
|
||||
lon = data[4]
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :mlat => lat, :mlon => lon, :zoom => 14
|
||||
return
|
||||
end
|
||||
elsif postcode.match(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d/)
|
||||
|
@ -70,7 +70,7 @@ class GeocoderController < ApplicationController
|
|||
data_lon = resp.body.slice(/longt>.*?</)
|
||||
lat = data_lat.split(/[<>]/)[1]
|
||||
lon = data_lon.split(/[<>]/)[1]
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :mlat => lat, :mlon => lon, :zoom => 14
|
||||
return
|
||||
end
|
||||
elsif postcode.match(/(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})
|
||||
|
@ -81,15 +81,13 @@ class GeocoderController < ApplicationController
|
|||
resp = http.get("/geocode?postcode=#{postcode}")
|
||||
lat = resp.body.scan(/[4-6][0-9]\.?[0-9]+/)
|
||||
lon = resp.body.scan(/[-+][0-9]\.?[0-9]+/)
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :mlat => lat, :mlon => lon, :zoom => 14
|
||||
return
|
||||
end
|
||||
rescue
|
||||
redirect_to "/index.html"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :error => "invalid_postcode"
|
||||
#redirect to somewhere else
|
||||
end
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
#redirect_to "/index.html?error=unknown_postcode_or_zip"
|
||||
elsif
|
||||
# Some other postcode / zip code
|
||||
# Throw it at geonames, and see if they have any luck with it
|
||||
|
@ -98,23 +96,23 @@ class GeocoderController < ApplicationController
|
|||
hits = resp.body.slice(/totalResultsCount>.*?</).split(/[<>]/)[1]
|
||||
if hits == "0"
|
||||
# Geonames doesn't know, it's probably wrong
|
||||
redirect_to "/index.html?error=unknown_postcode_or_zip"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :error => "invalid_postcode_or_zip"
|
||||
return
|
||||
end
|
||||
data_lat = resp.body.slice(/lat>.*?</)
|
||||
data_lon = resp.body.slice(/lng>.*?</)
|
||||
lat = data_lat.split(/[<>]/)[1]
|
||||
lon = data_lon.split(/[<>]/)[1]
|
||||
redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :mlat => lat, :mlon => lon, :zoom => 14
|
||||
end
|
||||
else
|
||||
# Some other postcode / zip file
|
||||
redirect_to "/index.html?error=unknown_postcode_or_zip"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :error => "invalid_postcode_or_zip"
|
||||
return
|
||||
end
|
||||
rescue
|
||||
#Its likely that an api is down
|
||||
redirect_to "/index.html?error=api_dpwn"
|
||||
redirect_to :controller => params[:next_controller], :action => params[:next_action], :error => "api_down"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Country</th>
|
||||
<th><Go to the Map </th>
|
||||
<th><Get from the API </th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @res_ary.each do |hsh| %>
|
||||
|
@ -21,6 +22,9 @@
|
|||
<%= link_to('Map', url="/index.html?mlat=#{hsh['lat']}&mlon=#{hsh['lon']}&zoom=12") %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to('Edit', url="/edit.html?mlat=#{hsh['lat']}&mlon=#{hsh['lon']}&zoom=12") %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to('API', url="/#FIXME") %>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
20
app/views/site/_search.rhtml
Normal file
20
app/views/site/_search.rhtml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<div id="geocoder">
|
||||
<% form_tag :controller => 'geocoder', :action => 'search' do %>
|
||||
<%= hidden_field_tag 'next_controller', @controller.controller_name %>
|
||||
<%= hidden_field_tag 'next_action', @controller.action_name %>
|
||||
<%= text_field 'query', 'postcode' %>
|
||||
<%= text_field 'query', 'place_name'%>
|
||||
<%= submit_tag 'Search' %>
|
||||
<% end %>
|
||||
|
||||
<div id="geocoder-attribution">
|
||||
Geolocation provided by <a href="http://npemap.org.uk/">npemap.org.uk</a>,
|
||||
<a href="http://geocoder.us/">geocoder.us</a>, <a href="http://geocoder.ca/">geocoder.ca</a> and <a href="http://www.geonames.org/">geonames.org</a>
|
||||
</div>
|
||||
<div id="postcode-helper">
|
||||
Enter a postcode or zip code, eg: SW15 6JH, 95472
|
||||
</div>
|
||||
<div id="placename-helper">
|
||||
Enter a place-name, eg:Essen
|
||||
</div>
|
||||
</div>
|
|
@ -1,3 +1,19 @@
|
|||
<%= render :partial => 'search' %>
|
||||
|
||||
<% if params['mlon'] and params['mlat'] %>
|
||||
<% lon = params['mlon'] %>
|
||||
<% lat = params['mlat'] %>
|
||||
<% zoom = params['zoom'] || '12' %>
|
||||
<% elsif @user and params['lon'].nil? and params['lat'].nil? %>
|
||||
<% lon = @user.home_lon %>
|
||||
<% lat = @user.home_lat %>
|
||||
<% zoom = '10' %>
|
||||
<%else%>
|
||||
<% lon = params['lon'] || '-0.1' %>
|
||||
<% lat = params['lat'] || '51.5' %>
|
||||
<% zoom = params['zoom'] || '4' %>
|
||||
<% end %>
|
||||
|
||||
<div id="mapcontent">You need a Flash player to use Potlatch, the
|
||||
OpenStreetMap Flash editor. You can <a href="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">download Flash Player from Adobe.com</a>.
|
||||
|
||||
|
@ -13,9 +29,6 @@
|
|||
fo.addVariable('token','<%= @user.token %>');
|
||||
fo.write("mapcontent");
|
||||
}
|
||||
<% lon = params['lon'] || @user.home_lon || '-0.1' %>
|
||||
<% lat = params['lat'] || @user.home_lat || '51.5' %>
|
||||
<% zoom = params['zoom'] || 12 %>
|
||||
|
||||
doSWF(<%= lat %>,<%= lon %>,<%= zoom %>);
|
||||
|
||||
|
|
|
@ -1,23 +1,4 @@
|
|||
|
||||
|
||||
<div id="geocoder">
|
||||
<% form_tag :controller => 'geocoder', :action => 'search' do %>
|
||||
<%= text_field 'query', 'postcode' %>
|
||||
<%= text_field 'query', 'place_name'%>
|
||||
<%= submit_tag 'Search' %>
|
||||
<% end %>
|
||||
|
||||
<div id="geocoder-attribution">
|
||||
Geolocation provided by <a href="http://npemap.org.uk/">npemap.org.uk</a>,
|
||||
<a href="http://geocoder.us/">geocoder.us</a>, <a href="http://geocoder.ca/">geocoder.ca</a> and <a href="http://www.geonames.org/">geonames.org</a>
|
||||
</div>
|
||||
<div id="postcode-helper">
|
||||
Enter a postcode or zip code, eg: SW15 6JH, 95472
|
||||
</div>
|
||||
<div id="placename-helper">
|
||||
Enter a place-name, eg:Essen
|
||||
</div>
|
||||
</div>
|
||||
<%= render :partial => 'search' %>
|
||||
|
||||
<% if params['mlon'] and params['mlat'] %>
|
||||
<% marker = true %>
|
||||
|
|
Loading…
Add table
Reference in a new issue