diff --git a/app/assets/javascripts/places.js.coffee.erb b/app/assets/javascripts/places.js.coffee.erb deleted file mode 100644 index fbf448837..000000000 --- a/app/assets/javascripts/places.js.coffee.erb +++ /dev/null @@ -1,17 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ - -map = L.map('map').setView([0.0, -0.0], 2); -L.tileLayer("http://{s}.tile.cloudmade.com/<%= ENV['CLOUDMADE_KEY'] %>/997/256/{z}/{x}/{y}.png", { - attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © CloudMade', - maxZoom: 18 -}).addTo(map); - -<% Member.located.each do |m| %> -map.addLayer( - new L.Marker( - new L.LatLng(<%= m.latitude %>, <%= m.longitude %>) - ); -); -<% end %> diff --git a/app/controllers/places_controller.rb b/app/controllers/places_controller.rb index b6bf59d5d..35f37424c 100644 --- a/app/controllers/places_controller.rb +++ b/app/controllers/places_controller.rb @@ -24,6 +24,20 @@ class PlacesController < ApplicationController @units = :km end + location = Geocoder.search(Geocoder::Query.new(@place, :distance => @distance, :units => @units)) + + if location + @latitude, @longitude = location[0].coordinates + @sw_lat, @sw_lng, @ne_lat, @ne_lng = Geocoder::Calculations.bounding_box( + location[0].coordinates, + @distance, + options = { :units => @units } + ) + else + @latitude, @longitude = [0, 0] + end + + @nearby_members = @place ? Member.near(@place, @distance, :units => @units) : [] respond_to do |format| diff --git a/app/views/members/_popover.html.haml b/app/views/members/_popover.html.haml new file mode 100644 index 000000000..04d69e7b8 --- /dev/null +++ b/app/views/members/_popover.html.haml @@ -0,0 +1,3 @@ +%p= link_to member, member +%p= member.location +%p REPLACE THIS WHEN YOU MERGE FROM THE REDESIGNED HOMEPAGE! diff --git a/app/views/places/index.html.haml b/app/views/places/index.html.haml index 49e5bd5e9..75a2b51b2 100644 --- a/app/views/places/index.html.haml +++ b/app/views/places/index.html.haml @@ -1,3 +1,19 @@ -content_for :title, "Places" %div#map{ :style => "height:500px"} + + + +:javascript + map = L.map('map').setView([0.0, -0.0], 2); + L.tileLayer("http://{s}.tile.cloudmade.com/#{ ENV['CLOUDMADE_KEY'] }/997/256/{z}/{x}/{y}.png", { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © CloudMade', + maxZoom: 18 + }).addTo(map); + +- Member.located.each do |m| + :javascript + marker = new L.Marker(new L.LatLng(#{m.latitude}, #{m.longitude})); + marker.bindPopup('#{ escape_javascript( render :partial => 'members/popover', :locals => { :member => m }) }').openPopup(); + map.addLayer(marker); + diff --git a/app/views/places/show.html.haml b/app/views/places/show.html.haml index 063be1298..a123cc1cf 100644 --- a/app/views/places/show.html.haml +++ b/app/views/places/show.html.haml @@ -1,7 +1,21 @@ -content_for :title, @place -%p This would be a google map. -= image_tag("http://placehold.it/700x300", :alt => "map goes here!") + + +%div#map{ :style => "height:300px"} + +:javascript + map = L.map('map').setView([#{ @latitude }, #{ @longitude }]).fitBounds([ [#{@sw_lat}, #{@sw_lng}], [#{@ne_lat}, #{@ne_lng}] ]); + L.tileLayer("http://{s}.tile.cloudmade.com/#{ ENV['CLOUDMADE_KEY'] }/997/256/{z}/{x}/{y}.png", { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © CloudMade', + maxZoom: 18 + }).addTo(map); + +- Member.located.each do |m| + :javascript + marker = new L.Marker(new L.LatLng(#{m.latitude}, #{m.longitude})); + marker.bindPopup('#{ escape_javascript( render :partial => 'members/popover', :locals => { :member => m }) }').openPopup(); + map.addLayer(marker); %h3 = Growstuff::Application.config.site_name