google_static_maps_helper 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,10 +4,6 @@ This gem provides a simple interface to the Google Static Maps V2 API (http://co
4
4
 
5
5
 
6
6
  = Installation
7
- If you haven't already, add gemcutter as a gem source
8
- [sudo] gem sources --add http://gemcutter.org
9
-
10
- Then install this gem
11
7
  [sudo] gem install google_static_maps_helper
12
8
 
13
9
 
@@ -18,15 +14,14 @@ Then install this gem
18
14
  marker :lng => 3, :lat => 4
19
15
  end
20
16
 
21
- This will return the URL for a map with these markers. Please note that if you do use this approach you have to set key, size and sensor setting.
17
+ This will return the URL for a map with these markers. Please note that if you do use this approach you have to set size and sensor setting.
22
18
  You do this by:
23
- GoogleStaticMapsHelper.key = 'your google key'
24
19
  GoogleStaticMapsHelper.size = '300x600'
25
20
  GoogleStaticMapsHelper.sensor = false
26
21
 
27
- If you are on Rails you can put it in your environment configuration file and while you are there you can add the following line inside the configuration block:
22
+ If you are on Rails (2.3.x) you can put it in your environment configuration file and while you are there you can add the following line inside the configuration block:
28
23
  Rails::Initializer.run do |config|
29
- config.gem 'google_static_maps_helper', :source => 'http://gemcutter.org'
24
+ config.gem 'google_static_maps_helper'
30
25
  ...
31
26
  end
32
27
 
@@ -56,24 +51,24 @@ You uild a marker by simply sending in an object which responds to lng and lat,
56
51
  marker = GoogleStaticMapsHelper::Marker.new(location)
57
52
  marker = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
58
53
 
59
- Google's static maps supports some options on markers. You can change the color, the label and the size.
54
+ Google's static maps supports some options on markers. You can change the color, the label and the size or you can send in your own icon.
60
55
  (http://code.google.com/apis/maps/documentation/staticmaps/#MarkerStyles). You send in options as a second
61
56
  parameter to the new method if you gave a location object, or include it in the hash where lng and lat is.
62
57
  marker = GoogleStaticMapsHelper::Marker.new(location, :color => 'blue')
63
58
  marker = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :color => 'blue')
59
+ marker = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :icon => 'http://www.domain.com/icon.png')
64
60
 
65
61
 
66
62
  == Map
67
- A Map holds many markers, paths, pluss some additional options like the size of the static map, Google key, what zoom level and center point it should be fixed to
63
+ A Map holds many markers, paths, pluss some additional options like the size of the static map, what zoom level and center point it should be fixed to
68
64
  etc. If no zoom or center point is give it will calculate the map view based on the markers or paths. You can leave markers and paths out, but then you have to supply
69
65
  zoom and center. More info can be found here: http://code.google.com/apis/maps/documentation/staticmaps/#URL_Parameters.
70
66
 
71
67
  === How to build a map?
72
- When building a map object you have to supply key, sensor and size. Other options are optional.
73
- map = GoogleStaticMapsHelper::Map.new(:key => YOUR_GOOGLE_KEY, :sensor => false, :size => '200x300')
68
+ When building a map object you have to supply sensor and size. Other options are optional.
69
+ map = GoogleStaticMapsHelper::Map.new(:sensor => false, :size => '200x300')
74
70
 
75
71
  Or, if you have set default options on GoogleStaticMapsHelper, you can skip the required keys when creating a map
76
- GoogleStaticMapsHelper.key = 'your google key'
77
72
  GoogleStaticMapsHelper.size = '300x600'
78
73
  GoogleStaticMapsHelper.sensor = false
79
74
  map = GoogleStaticMapsHelper::Map.new
@@ -88,8 +83,7 @@ We can now ask the map for it's URL to where we'll get the map from. This URL ca
88
83
  map.url
89
84
 
90
85
  Another thing you might want to do is to override the center point and zoom level. This is done during map construction
91
- map = GoogleStaticMapsHelper::Map.new(:key => YOUR_GOOGLE_KEY,
92
- :sensor => false,
86
+ map = GoogleStaticMapsHelper::Map.new(:sensor => false,
93
87
  :size => '200x300',
94
88
  :center => '1,2',
95
89
  :zoom => 4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.4
1
+ 1.3.5
data/changelog.txt CHANGED
@@ -1,3 +1,7 @@
1
+ = v.1.3.5
2
+ * Added support for icon on markers.
3
+ * DEPRECATED Google API key as its no longer required when requesting a static map (will be removed from this gem in upcoming versions).
4
+
1
5
  = v.1.3.4
2
6
  * Paths are now as default encoding it's points with Google's encoding algorithm. Thanks to Joel Rosenberg for providing an easy class to use.
3
7
  This will cut the length of the generated URL quite a bit; down to between 1/3 and 1/2 of the old size.
@@ -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.3.4"
8
+ s.version = "1.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Thorbjørn Hermansen"]
12
- s.date = %q{2009-12-03}
11
+ s.authors = ["Thorbj\303\270rn Hermansen"]
12
+ s.date = %q{2010-03-08}
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 = [
@@ -44,12 +44,12 @@ Gem::Specification.new do |s|
44
44
  s.rubygems_version = %q{1.3.5}
45
45
  s.summary = %q{This gem provides a simple interface to the Google Static Maps V2 API}
46
46
  s.test_files = [
47
- "spec/marker_spec.rb",
47
+ "spec/path_spec.rb",
48
+ "spec/marker_spec.rb",
48
49
  "spec/map_spec.rb",
49
- "spec/spec_helper.rb",
50
50
  "spec/location_spec.rb",
51
- "spec/path_spec.rb",
52
- "spec/google_static_maps_helper_spec.rb"
51
+ "spec/google_static_maps_helper_spec.rb",
52
+ "spec/spec_helper.rb"
53
53
  ]
54
54
 
55
55
  if s.respond_to? :specification_version then
@@ -64,5 +64,11 @@ module GoogleStaticMapsHelper
64
64
  block.arity < 1 ? map.instance_eval(&block) : block.call(map)
65
65
  map.url
66
66
  end
67
+
68
+
69
+ def key=(key)# :nodoc:
70
+ warn "[DEPRECATION] 'key' is deprecated. Key is no longer used when require a static map. Key will be removed from this gem soon!"
71
+ @key = key
72
+ end
67
73
  end
68
74
  end
@@ -14,8 +14,8 @@ module GoogleStaticMapsHelper
14
14
  VALID_FORMATS = %w{png png8 png32 gif jpg jpg-basedline}
15
15
  VALID_MAP_TYPES = %w{roadmap satellite terrain hybrid}
16
16
 
17
- REQUIRED_OPTIONS = [:key, :size, :sensor]
18
- OPTIONAL_OPTIONS = [:center, :zoom, :format, :maptype, :mobile, :language]
17
+ REQUIRED_OPTIONS = [:size, :sensor]
18
+ OPTIONAL_OPTIONS = [:key, :center, :zoom, :format, :maptype, :mobile, :language]
19
19
 
20
20
  attr_accessor *(REQUIRED_OPTIONS + OPTIONAL_OPTIONS)
21
21
  attr_accessor :width, :height
@@ -26,7 +26,6 @@ module GoogleStaticMapsHelper
26
26
  # <tt>:options</tt>:: The options available are the same as described in
27
27
  # Google's API documentation[http://code.google.com/apis/maps/documentation/staticmaps/#Usage].
28
28
  # In short, valid options are:
29
- # <tt>:key</tt>:: Your Google maps API key
30
29
  # <tt>:size</tt>:: The size of the map. Can be a "wxh", [w,h] or {:width => x, :height => y}
31
30
  # <tt>:sensor</tt>:: Set to true if your application is using a sensor. See the API doc.
32
31
  # <tt>:center</tt>:: The center point of your map. Optional if you add markers or path to the map
@@ -203,6 +202,26 @@ module GoogleStaticMapsHelper
203
202
  raise UnsupportedMaptype unless VALID_MAP_TYPES.include? @maptype
204
203
  end
205
204
 
205
+ #
206
+ # Google static maps does no longer use key when a map is requested,
207
+ # thus this is deprecated.
208
+ #
209
+ def key=(key)# :nodoc:
210
+ warn "[DEPRECATION] 'key' is deprecated. Key is no longer used when require a static map. Key will be removed from this gem soon!"
211
+ @key = key
212
+ end
213
+
214
+ #
215
+ # Just a setter method for key which sets it without warning
216
+ # to be called from rspec so all tests still passes without
217
+ # warnings.
218
+ #
219
+ # It's just a couple of places we still test that key is working
220
+ # as it should.
221
+ #
222
+ def key_without_warning=(key)# :nodoc:
223
+ @key = key
224
+ end
206
225
 
207
226
  private
208
227
  #
@@ -7,7 +7,9 @@ module GoogleStaticMapsHelper
7
7
  DEFAULT_OPTIONS = {
8
8
  :color => 'red',
9
9
  :size => 'mid',
10
- :label => nil
10
+ :label => nil,
11
+ :icon => nil,
12
+ :shadow => nil
11
13
  }
12
14
 
13
15
  attr_accessor :location, *DEFAULT_OPTIONS.keys
@@ -48,8 +50,11 @@ module GoogleStaticMapsHelper
48
50
  #
49
51
  def options_to_url_params # :nodoc:
50
52
  params = DEFAULT_OPTIONS.keys.map(&:to_s).sort.inject([]) do |params, attr|
51
- value = send(attr)
52
- params << "#{attr}:#{URI.escape(value)}" unless value.nil?
53
+ primary_getter = "#{attr}_to_be_used_in_param"
54
+ secondary_getter = attr
55
+
56
+ value = send(primary_getter) rescue send(secondary_getter)
57
+ params << "#{attr}:#{URI.escape(value.to_s)}" unless value.nil?
53
58
  params
54
59
  end
55
60
 
@@ -71,6 +76,10 @@ module GoogleStaticMapsHelper
71
76
  @color.downcase if @color
72
77
  end
73
78
 
79
+ def has_icon?
80
+ !!@icon
81
+ end
82
+
74
83
 
75
84
  #
76
85
  # Proxies calls to the internal object which keeps track of this marker's location.
@@ -91,5 +100,18 @@ module GoogleStaticMapsHelper
91
100
  invalid_options = options.keys - DEFAULT_OPTIONS.keys
92
101
  raise OptionNotExist, "The following options does not exist: #{invalid_options.join(', ')}" unless invalid_options.empty?
93
102
  end
103
+
104
+ # Some attributes should be nil when a marker has icon
105
+ [:color, :label, :size].each do |getter|
106
+ define_method "#{getter}_to_be_used_in_param" do
107
+ return nil if has_icon?
108
+ send(getter)
109
+ end
110
+ end
111
+
112
+ def shadow_to_be_used_in_param
113
+ return nil unless has_icon?
114
+ shadow
115
+ end
94
116
  end
95
117
  end
@@ -5,7 +5,6 @@ describe GoogleStaticMapsHelper do
5
5
  describe "Friendly DSL API" do
6
6
  describe "url_for" do
7
7
  before do
8
- GoogleStaticMapsHelper.key = 'my_key'
9
8
  GoogleStaticMapsHelper.size = '300x500'
10
9
  GoogleStaticMapsHelper.sensor = false
11
10
  end
data/spec/map_spec.rb CHANGED
@@ -4,7 +4,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
4
  describe GoogleStaticMapsHelper::Map do
5
5
  reguire_options = {
6
6
  :size => '600x400',
7
- :key => 'MY_GOOGLE_KEY',
8
7
  :sensor => false
9
8
  }
10
9
 
@@ -84,7 +83,7 @@ describe GoogleStaticMapsHelper::Map do
84
83
 
85
84
  @marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
86
85
  @marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
87
- @map = GoogleStaticMapsHelper::Map.new(:key => @key, :size => @size, :sensor => @sensor)
86
+ @map = GoogleStaticMapsHelper::Map.new(:size => @size, :sensor => @sensor)
88
87
  end
89
88
 
90
89
  it "should return options_to_url_params as key, array with markers as value" do
@@ -222,16 +221,19 @@ describe GoogleStaticMapsHelper::Map do
222
221
 
223
222
  describe "URL" do
224
223
  before :each do
225
- @key = 'MY_GOOGLE_KEY'
224
+ @key =
226
225
  @size = '400x600'
227
226
  @sensor = false
228
- @map = GoogleStaticMapsHelper::Map.new(:key => @key, :size => @size, :sensor => @sensor)
227
+ @map = GoogleStaticMapsHelper::Map.new(:size => @size, :sensor => @sensor)
229
228
 
230
229
  @marker1 = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
231
230
  @marker11 = GoogleStaticMapsHelper::Marker.new(:lng => 3, :lat => 4)
232
231
 
233
232
  @marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
234
233
  @marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
234
+
235
+ @marker3 = GoogleStaticMapsHelper::Marker.new(:lng => 9, :lat => 10, :icon => 'http://image.com/')
236
+ @marker33 = GoogleStaticMapsHelper::Marker.new(:lng => 11, :lat => 12, :icon => 'http://image.com/')
235
237
  end
236
238
 
237
239
  describe "valid state to run URL" do
@@ -262,7 +264,13 @@ describe GoogleStaticMapsHelper::Map do
262
264
  end
263
265
 
264
266
  it "should include the key" do
265
- @map.url.should include("key=#{@key}")
267
+ @map.key_without_warning = 'MY_GOOGLE_KEY'
268
+ @map.url.should include("key=MY_GOOGLE_KEY")
269
+ end
270
+
271
+ it "should not include key if it's nil" do
272
+ @map.key_without_warning = nil
273
+ @map.url.should_not include("key=")
266
274
  end
267
275
 
268
276
  it "should include the size" do
@@ -316,16 +324,16 @@ describe GoogleStaticMapsHelper::Map do
316
324
  before :each do
317
325
  @map << @marker1
318
326
  @map << @marker2
327
+ @map << @marker3
319
328
  end
320
329
 
321
330
  [
322
- ['key', 'MY_GOOGLE_KEY'],
323
331
  ['sensor', 'false'],
324
332
  ['size', '400x600'],
325
333
  ['markers', 'color:green|size:mid|6,5'],
326
- ['markers', 'color:red|size:mid|2,1']
327
- ].each do |pair|
328
- key, value = pair
334
+ ['markers', 'color:red|size:mid|2,1'],
335
+ ['markers', 'icon:http://image.com/|10,9']
336
+ ].each do |(key, value)|
329
337
  it "should have key: #{key} and value: #{value}" do
330
338
  @map.url.should include("#{key}=#{value}")
331
339
  end
@@ -339,16 +347,17 @@ describe GoogleStaticMapsHelper::Map do
339
347
  @map << @marker11
340
348
  @map << @marker2
341
349
  @map << @marker22
350
+ @map << @marker3
351
+ @map << @marker33
342
352
  end
343
353
 
344
354
  [
345
- ['key', 'MY_GOOGLE_KEY'],
346
355
  ['sensor', 'true'],
347
356
  ['size', '400x600'],
348
357
  ['markers', 'color:green|size:mid|6,5|8,7'],
349
- ['markers', 'color:red|size:mid|2,1|4,3']
350
- ].each do |pair|
351
- key, value = pair
358
+ ['markers', 'color:red|size:mid|2,1|4,3'],
359
+ ['markers', 'icon:http://image.com/|10,9|12,11']
360
+ ].each do |(key, value)|
352
361
  it "should have key: #{key} and value: #{value}" do
353
362
  @map.url.should include("#{key}=#{value}")
354
363
  end
@@ -375,7 +384,6 @@ describe GoogleStaticMapsHelper::Map do
375
384
  end
376
385
 
377
386
  [
378
- ['key', 'MY_GOOGLE_KEY'],
379
387
  ['sensor', 'false'],
380
388
  ['size', '400x600'],
381
389
  ['path', 'weight:5|1,2|3,4'],
data/spec/marker_spec.rb CHANGED
@@ -49,24 +49,39 @@ describe GoogleStaticMapsHelper::Marker do
49
49
 
50
50
  describe "options" do
51
51
  describe "defaults" do
52
+ before do
53
+ @marker = GoogleStaticMapsHelper::Marker.new(@location_object)
54
+ end
55
+
52
56
  it "should have a predefined color which location should use" do
53
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
54
- marker.color.should == 'red'
57
+ @marker.color.should == 'red'
55
58
  end
56
59
 
57
60
  it "should have a predefined size" do
58
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
59
- marker.size.should == 'mid'
61
+ @marker.size.should == 'mid'
60
62
  end
61
63
 
62
64
  it "should have a predefined label which should be nil" do
63
- marker = GoogleStaticMapsHelper::Marker.new(@location_object)
64
- marker.label.should be_nil
65
+ @marker.label.should be_nil
66
+ end
67
+
68
+ it "should have an icon predefined to nil" do
69
+ @marker.icon.should be_nil
70
+ end
71
+
72
+ it "should have an shadow predefined to nil" do
73
+ @marker.shadow.should be_nil
65
74
  end
66
75
  end
67
76
 
68
77
  describe "override options as second parameters, location given as object as first param" do
69
- {:color => 'blue', :size => 'small', :label => 'A'}.each_pair do |key, value|
78
+ {
79
+ :color => 'blue',
80
+ :size => 'small',
81
+ :label => 'A',
82
+ :icon => 'http://www.url.to/img.png',
83
+ :shadow => 'true'
84
+ }.each_pair do |key, value|
70
85
  it "should be possible to override #{key} to #{value}" do
71
86
  marker = GoogleStaticMapsHelper::Marker.new(@location_object, {key => value})
72
87
  marker.send(key).should == value
@@ -75,7 +90,13 @@ describe GoogleStaticMapsHelper::Marker do
75
90
  end
76
91
 
77
92
  describe "override options as first parameter, location mixed into the same hash" do
78
- {:color => 'blue', :size => 'small', :label => 'A'}.each_pair do |key, value|
93
+ {
94
+ :color => 'blue',
95
+ :size => 'small',
96
+ :label => 'A',
97
+ :icon => 'http://www.url.to/img.png',
98
+ :shadow => 'true'
99
+ }.each_pair do |key, value|
79
100
  it "should be possible to override #{key} to #{value}" do
80
101
  marker = GoogleStaticMapsHelper::Marker.new(@location_hash.merge({key => value}))
81
102
  marker.send(key).should == value
@@ -99,6 +120,14 @@ describe GoogleStaticMapsHelper::Marker do
99
120
  GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:color => 'Green')).color.should == 'green'
100
121
  end
101
122
 
123
+ it "should answer false when asked if it has an icon when it doesn't" do
124
+ GoogleStaticMapsHelper::Marker.new(@location_hash).should_not have_icon
125
+ end
126
+
127
+ it "should answer true when asked if it has an icon when it does" do
128
+ GoogleStaticMapsHelper::Marker.new(@location_hash.merge(:icon => 'http://icon.com/')).should have_icon
129
+ end
130
+
102
131
 
103
132
  describe "generating url parameters" do
104
133
  before :each do
@@ -126,5 +155,37 @@ describe GoogleStaticMapsHelper::Marker do
126
155
  it "should build location_to_url" do
127
156
  @marker.location_to_url.should == '1,2'
128
157
  end
158
+
159
+ describe "icon and shadow" do
160
+ before do
161
+ @marker.icon = 'http://www.icon.com/'
162
+ @marker.shadow = false
163
+ end
164
+
165
+ it "should contain the icon param" do
166
+ @marker.options_to_url_params.should include('icon:http://www.icon.com/')
167
+ end
168
+
169
+ it "should URL encode the URL" do
170
+ @marker.icon = 'http://www.icon.com/foo bar/'
171
+ @marker.options_to_url_params.should include('icon:http://www.icon.com/foo%20bar/')
172
+ end
173
+
174
+ it "should contain the shadow param" do
175
+ @marker.options_to_url_params.should include('shadow:false')
176
+ end
177
+
178
+ [:color, :label, :size].each do |property|
179
+ it "should not contain #{property} when icon is set" do
180
+ @marker.options_to_url_params.should_not include(property.to_s)
181
+ end
182
+ end
183
+
184
+ it "should not include shadow if it hasn't an icon" do
185
+ @marker.shadow = true
186
+ @marker.icon = nil
187
+ @marker.options_to_url_params.should_not include('shadow:true')
188
+ end
189
+ end
129
190
  end
130
191
  end
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.3.4
4
+ version: 1.3.5
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-12-03 00:00:00 +01:00
12
+ date: 2010-03-08 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -81,9 +81,9 @@ signing_key:
81
81
  specification_version: 3
82
82
  summary: This gem provides a simple interface to the Google Static Maps V2 API
83
83
  test_files:
84
+ - spec/path_spec.rb
84
85
  - spec/marker_spec.rb
85
86
  - spec/map_spec.rb
86
- - spec/spec_helper.rb
87
87
  - spec/location_spec.rb
88
- - spec/path_spec.rb
89
88
  - spec/google_static_maps_helper_spec.rb
89
+ - spec/spec_helper.rb