google_static_maps_helper 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/changelog.txt +23 -0
- data/google_static_maps_helper.gemspec +3 -2
- data/lib/google_static_maps_helper.rb +1 -1
- data/lib/google_static_maps_helper/map.rb +44 -0
- data/spec/google_static_maps_helper_spec.rb +2 -2
- data/spec/map_spec.rb +66 -2
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -18,7 +18,7 @@ Then install this gem
|
|
18
18
|
marker :lng => 3, :lat => 4
|
19
19
|
end
|
20
20
|
|
21
|
-
This will return the url for map with these markers.
|
21
|
+
This will return the url for map with these markers. Please note that if you do use this approach you have to set key, size and sensor setting.
|
22
22
|
You do this by:
|
23
23
|
GoogleStaticMapsHelper.key = 'your google key'
|
24
24
|
GoogleStaticMapsHelper.size = '300x600'
|
@@ -60,6 +60,12 @@ zoom and center. More info can be found here: http://code.google.com/apis/maps/d
|
|
60
60
|
When building a map object you have to supply key, sensor and size. Other options are optional.
|
61
61
|
map = GoogleStaticMapsHelper::Map.new(:key => YOUR_GOOGLE_KEY, :sensor => false, :size => '200x300')
|
62
62
|
|
63
|
+
Or, if you have set default options on GoogleStaticMapsHelper, you can skip the required keys when creating a map
|
64
|
+
GoogleStaticMapsHelper.key = 'your google key'
|
65
|
+
GoogleStaticMapsHelper.size = '300x600'
|
66
|
+
GoogleStaticMapsHelper.sensor = false
|
67
|
+
map = GoogleStaticMapsHelper::Map.new
|
68
|
+
|
63
69
|
|
64
70
|
== Generate static map URL
|
65
71
|
With the map object made, we are ready to add some markers to it:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
data/changelog.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= v.1.2.3
|
2
|
+
* It is no longer needed to send in key, sensor and size to the Map's constructor as long as these values are set on GoogleStaticMapsHelper.
|
3
|
+
* A map does now respond to width and height.
|
4
|
+
* The map can now receive size as string, array or hash.
|
5
|
+
* The map will raise an error if width/height is above the limit which Google currently has (640 pixels).
|
6
|
+
|
7
|
+
= v.1.2.2
|
8
|
+
* It is now possible to chain the pushing of markers on to map.
|
9
|
+
|
10
|
+
= v.1.2.1
|
11
|
+
* Bugfix: Sensor wasn't included in the generated URL if it was false.
|
12
|
+
|
13
|
+
= v.1.2.0
|
14
|
+
* Added a simple DSL interface which should make it easier to use.
|
15
|
+
* Fixed a missing escape of an get parameter.
|
16
|
+
|
17
|
+
= v.1.1.0
|
18
|
+
* Refactored Map class. No longer using internal hash to store the options, but instance variables
|
19
|
+
* Refactored Marker class. Same as above.
|
20
|
+
* Wrote better test for testing params the URL returned.
|
21
|
+
|
22
|
+
= v.1.0.0
|
23
|
+
First release. Basic functionality in place which makes usable.
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google_static_maps_helper}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thorbj\303\270rn Hermansen"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-25}
|
13
13
|
s.description = %q{This gem provides a simple interface to the Google Static Maps V2 API.}
|
14
14
|
s.email = %q{thhermansen@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
"README.rdoc",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
|
+
"changelog.txt",
|
26
27
|
"google_static_maps_helper.gemspec",
|
27
28
|
"lib/google_static_maps_helper.rb",
|
28
29
|
"lib/google_static_maps_helper/map.rb",
|
@@ -13,7 +13,7 @@ module GoogleStaticMapsHelper
|
|
13
13
|
attr_accessor :key, :size, :sensor
|
14
14
|
|
15
15
|
def url_for(map_options = {}, &block)
|
16
|
-
map = Map.new(
|
16
|
+
map = Map.new(map_options)
|
17
17
|
block.arity < 1 ? map.instance_eval(&block) : block.call(map)
|
18
18
|
map.url
|
19
19
|
end
|
@@ -5,16 +5,21 @@ module GoogleStaticMapsHelper
|
|
5
5
|
class Map
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
+
MAX_WIDTH = 640
|
9
|
+
MAX_HEIGHT = 640
|
10
|
+
|
8
11
|
REQUIRED_OPTIONS = [:key, :size, :sensor]
|
9
12
|
OPTIONAL_OPTIONS = [:center, :zoom, :format, :maptype, :mobile, :language]
|
10
13
|
|
11
14
|
attr_accessor *(REQUIRED_OPTIONS + OPTIONAL_OPTIONS)
|
15
|
+
attr_accessor :width, :height
|
12
16
|
|
13
17
|
# Initialize a new Map object
|
14
18
|
#
|
15
19
|
# Takes a hash of options where :key, :size and :sensor are required.
|
16
20
|
# Other options are center, zoom, format, maptype, mobile and language
|
17
21
|
def initialize(options)
|
22
|
+
inject_defaults_from_module_class_attribute!(options)
|
18
23
|
validate_required_options(options)
|
19
24
|
validate_options(options)
|
20
25
|
|
@@ -73,7 +78,38 @@ module GoogleStaticMapsHelper
|
|
73
78
|
marker = Marker.new(*args)
|
74
79
|
self << marker
|
75
80
|
end
|
81
|
+
|
82
|
+
def size=(size)
|
83
|
+
unless size.nil?
|
84
|
+
case size
|
85
|
+
when String
|
86
|
+
width, height = size.split('x')
|
87
|
+
when Array
|
88
|
+
width, height = size
|
89
|
+
when Hash
|
90
|
+
width = size[:width]
|
91
|
+
height = size[:height]
|
92
|
+
else
|
93
|
+
raise "Don't know how to set size from #{size.class}!"
|
94
|
+
end
|
95
|
+
|
96
|
+
self.width = width if width
|
97
|
+
self.height = height if height
|
98
|
+
end
|
99
|
+
end
|
76
100
|
|
101
|
+
def size
|
102
|
+
[@width, @height].join('x')
|
103
|
+
end
|
104
|
+
|
105
|
+
[:width, :height].each do |name|
|
106
|
+
define_method "#{name}=" do |dimension|
|
107
|
+
dimension = dimension.to_i
|
108
|
+
max_dimension = self.class.const_get("MAX_#{name.to_s.upcase}")
|
109
|
+
raise "Incomming dimension (#{dimension}) above max limit (#{max_dimension})." if dimension > max_dimension
|
110
|
+
instance_variable_set("@#{name}", dimension)
|
111
|
+
end
|
112
|
+
end
|
77
113
|
|
78
114
|
private
|
79
115
|
def can_build?
|
@@ -89,5 +125,13 @@ module GoogleStaticMapsHelper
|
|
89
125
|
invalid_options = options.keys - REQUIRED_OPTIONS - OPTIONAL_OPTIONS
|
90
126
|
raise OptionNotExist, "The following options does not exist: #{invalid_options.join(', ')}" unless invalid_options.empty?
|
91
127
|
end
|
128
|
+
|
129
|
+
def inject_defaults_from_module_class_attribute!(options)
|
130
|
+
REQUIRED_OPTIONS.each do |option_key|
|
131
|
+
next if options.has_key? option_key
|
132
|
+
value_from_modul = GoogleStaticMapsHelper.send(option_key)
|
133
|
+
options[option_key] = value_from_modul unless value_from_modul.nil?
|
134
|
+
end
|
135
|
+
end
|
92
136
|
end
|
93
137
|
end
|
@@ -22,11 +22,11 @@ describe GoogleStaticMapsHelper do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be possible to override the default map construction values" do
|
25
|
-
out = GoogleStaticMapsHelper.url_for(:size => '
|
25
|
+
out = GoogleStaticMapsHelper.url_for(:size => '600x400') do
|
26
26
|
marker :lat => 1, :lng => 2
|
27
27
|
end
|
28
28
|
|
29
|
-
out.should include('size=
|
29
|
+
out.should include('size=600x400')
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be possible to use inside a class, using attributes of that class" do
|
data/spec/map_spec.rb
CHANGED
@@ -2,13 +2,16 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe GoogleStaticMapsHelper::Map do
|
4
4
|
@@require_options = {
|
5
|
-
:size => '
|
5
|
+
:size => '600x400',
|
6
6
|
:key => 'MY_GOOGLE_KEY',
|
7
7
|
:sensor => false
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
10
|
describe "initialize" do
|
11
|
+
before do
|
12
|
+
@@require_options.each_key {|k| GoogleStaticMapsHelper.send("#{k}=", nil)}
|
13
|
+
end
|
14
|
+
|
12
15
|
@@require_options.each_key do |key|
|
13
16
|
it "should raise OptionMissing if #{key} is not given" do
|
14
17
|
option_with_missing_option = @@require_options.dup
|
@@ -24,6 +27,15 @@ describe GoogleStaticMapsHelper::Map do
|
|
24
27
|
it "should be able to read initialized key option from object" do
|
25
28
|
GoogleStaticMapsHelper::Map.new(@@require_options).key.should == @@require_options[:key]
|
26
29
|
end
|
30
|
+
|
31
|
+
@@require_options.each_key do |key|
|
32
|
+
it "should use #{key} from GoogleStaticMapsHelper class attribute if set" do
|
33
|
+
option_with_missing_option = @@require_options.dup
|
34
|
+
GoogleStaticMapsHelper.send("#{key}=", option_with_missing_option.delete(key))
|
35
|
+
map = GoogleStaticMapsHelper::Map.new(option_with_missing_option)
|
36
|
+
map.send(key).should == GoogleStaticMapsHelper.send(key)
|
37
|
+
end
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
describe "markers" do
|
@@ -76,6 +88,58 @@ describe GoogleStaticMapsHelper::Map do
|
|
76
88
|
end
|
77
89
|
|
78
90
|
|
91
|
+
describe "size" do
|
92
|
+
before do
|
93
|
+
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
94
|
+
@map.size = '300x400'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return map's width" do
|
98
|
+
@map.width.should == 300
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return map's height" do
|
102
|
+
@map.height.should == 400
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be able to set width with width :-)" do
|
106
|
+
@map.width = '300'
|
107
|
+
@map.width.should == 300
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be able to set height" do
|
111
|
+
@map.height = '300'
|
112
|
+
@map.height.should == 300
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be able to set width and height via size as an array" do
|
116
|
+
@map.size = [200, 300]
|
117
|
+
@map.size.should == '200x300'
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should be able to set width and height via size as a hash" do
|
121
|
+
@map.size = {:width => 100, :height => 500}
|
122
|
+
@map.size.should == '100x500'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should be possible to only set height via size as a hash" do
|
126
|
+
@map.size = {:height => 500}
|
127
|
+
@map.size.should == '300x500'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be possible to only set width via size as a hash" do
|
131
|
+
@map.size = {:width => 500}
|
132
|
+
@map.size.should == '500x400'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should raise an error if width is above 640px as it is not supported by Google Maps" do
|
136
|
+
lambda {@map.width = 641}.should raise_error
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should raise an error if height is above 640px as it is not supported by Google Maps" do
|
140
|
+
lambda {@map.height = 641}.should raise_error
|
141
|
+
end
|
142
|
+
end
|
79
143
|
|
80
144
|
describe "URL" do
|
81
145
|
before :each do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_static_maps_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Thorbj\xC3\xB8rn Hermansen"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-25 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
|
+
- changelog.txt
|
41
42
|
- google_static_maps_helper.gemspec
|
42
43
|
- lib/google_static_maps_helper.rb
|
43
44
|
- lib/google_static_maps_helper/map.rb
|