Zoom after search

This commit is contained in:
Erik Michaels-Ober 2011-02-25 16:34:01 -05:00
parent 92233b08bf
commit 322e6403bb
6 changed files with 38 additions and 94 deletions

View File

@ -1,2 +1,12 @@
class WelcomeController < ApplicationController
def index
# Default coordinates: Boston center
@lat, @lng = 42.358431, -71.059773
@zoom = 15
address, city, state = params[:address], params[:city], params[:state]
if address && city && state
@lat, @lng = Address.find_lat_lng("#{address}, #{city}, #{state}")
@zoom = 18
end
end
end

View File

@ -5,8 +5,19 @@
<%= stylesheet_link_tag "main" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" %>
<%= javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false" %>
<%= javascript_include_tag "maps" %>
<%= javascript_include_tag "snowstorm" %>
<script type="text/javascript">
$(function() {
var map;
var latlng = new google.maps.LatLng(<%= @lat %>, <%= @lng %>);
var myOptions = {
zoom: <%= @zoom %>,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
})
</script>
<%= csrf_meta_tag %>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>

View File

@ -3,29 +3,19 @@
<p id="tagline">
Claim responsibility for shoveling out a fire hydrant after it snows.
</p>
<form>
<label for="address">
Address
</label>
<input id="address" name="address" type="text" value="" tabindex="1" />
<label for="city">
City
</label>
<select id="city" name="city" tabindex="2">
<option value="Boston">Boston</option>
</select>
<label for="state">
State
</label>
<select id="state" name="state" tabindex="3">
<option value="MA">Massachusetts</option>
</select>
<button tabindex="4">Find Fire Hydrants</button>
</form>
<img id="boston-logo" src="images/logos/boston.png" alt="City of Boston" title="City of Boston" />
<img id="cert-logo" src="images/logos/cert.png" alt="Community Emergency Response Team" title="Community Emergency Response Team" />
<img id="cfa-logo" src="images/logos/cfa.png" alt="Code for America" title="Code for America" />
<img id="hydrant-in-snow" src="images/hydrant-in-snow.jpg">
<%= form_tag root_path, :method => :get do %>
<%= label_tag "address" %>
<%= text_field_tag "address", params[:address], :tabindex => 1 %>
<%= label_tag "city" %>
<%= select_tag "city", '<option value="Boston" selected="selected">Boston</option>'.html_safe, :tabindex => 2 %>
<%= label_tag "state" %>
<%= select_tag "state", '<option value="MA" selected="selected">Massachusetts</option>'.html_safe, :tabindex => 3 %>
<%= submit_tag "Find Fire Hydrants", :tabindex => 4 %>
<% end %>
<%= image_tag "logos/boston.png", :alt => "City of Boston", :title => "City of Boston" %>
<%= image_tag "logos/cert.png", :alt => "Community Emergency Response Team", :title => "Community Emergency Response Team" %>
<%= image_tag "logos/cfa.png", :alt => "Code for America", :title => "Code for America" %>
<%= image_tag "hydrant-in-snow.jpg" %>
</div>
<div id="map_canvas">
</div>

View File

@ -1,58 +1,4 @@
AdoptAHydrant::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
get "javascripts/:action" => "javascripts#action"
root :to => "welcome#index"
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end

View File

@ -1,12 +0,0 @@
$(function() {
var map;
var latlng = new google.maps.LatLng(42.358431,-71.059773);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
})

View File

@ -48,14 +48,13 @@ label, input {
text-align: left;
}
input, select, option, button {
input, select, option, input[type="submit"] {
margin-bottom: 10px;
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 1.0em;
width: 100%;
}
button {
input[type="submit"] {
text-align: center;
height: 2em;
}