Permalink
Browse files

dont provide a default zoom of 15 when generating for multiple addresses

google will figure out a zoom that fits all markers for you.
  • Loading branch information...
1 parent 0ec7f1d commit d281de3f0cab3411fa879c3587babff737c3b0ed @ratbeard ratbeard committed Feb 22, 2011
Showing with 30 additions and 3 deletions.
  1. +4 −3 lib/bhm/google_maps/static_map.rb
  2. +26 −0 test/static_map_test.rb
@@ -12,7 +12,7 @@ def initialize(options = {})
p[:sensor] = false
p[:size] = "#{@width}x#{@height}"
p[:maptype] = options.fetch(:type, "roadmap")
- p[:zoom] = options.fetch(:zoom, 15)
+ p[:zoom] = options.fetch(:zoom, 15) if options[:zoom] != nil
end
end
@@ -34,7 +34,8 @@ def self.for_address(address, opts = {})
end
def self.for_addresses(*addresses)
- map = self.new(addresses.extract_options!)
+ options = addresses.extract_options!.reverse_merge(:zoom => nil)
+ map = self.new(options)
addresses.flatten.each { |a| map << a }
map.to_url
end
@@ -58,4 +59,4 @@ def to_ll(address)
end
end
-end
+end
View
@@ -0,0 +1,26 @@
+ require 'test_helper'
+require 'ostruct'
+
+
+class StaticMapTest < ActiveSupport::TestCase
+
+ def setup_default_addresses
+ @address1 = Struct.new(:lat, :lng, :to_s).new(10.0, 10.0, "Some address")
+ @address2 = Struct.new(:lat, :lng, :to_s).new(12.0, 12.0, "Some address 2")
+ @addresses = [@address1, @address2]
+ end
+
+ setup :setup_default_addresses
+
+ test ".for_address inserts a default zoom of 15" do
+ url = BHM::GoogleMaps::StaticMap.for_address(@address1)
+ assert_match /zoom=15/, url
+ end
+
+ # Google maps provides a zoom that fits all markers, provided you don't supply a zoom
+ test ".for_addresses does not include zoom in the url" do
+ url = BHM::GoogleMaps::StaticMap.for_addresses(@addresses)
+ assert_no_match /zoom/, url
+ end
+
+end

0 comments on commit d281de3

Please sign in to comment.