google_static_maps_helper 1.3.2 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +35 -0
- data/README.rdoc +18 -24
- data/Rakefile +1 -48
- data/changelog.txt +18 -1
- data/google_static_maps_helper.gemspec +24 -60
- data/lib/google_static_maps_helper.rb +13 -5
- data/lib/google_static_maps_helper/gmap_polyline_encoder.rb +390 -0
- data/lib/google_static_maps_helper/location.rb +1 -0
- data/lib/google_static_maps_helper/map.rb +34 -14
- data/lib/google_static_maps_helper/marker.rb +30 -7
- data/lib/google_static_maps_helper/path.rb +41 -12
- data/lib/google_static_maps_helper/version.rb +3 -0
- metadata +76 -60
- data/VERSION +0 -1
- data/spec/google_static_maps_helper_spec.rb +0 -62
- data/spec/location_spec.rb +0 -141
- data/spec/map_spec.rb +0 -392
- data/spec/marker_spec.rb +0 -129
- data/spec/path_spec.rb +0 -151
- data/spec/spec_helper.rb +0 -9
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.3.2
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe GoogleStaticMapsHelper do
|
4
|
-
describe "Friendly DSL API" do
|
5
|
-
describe "url_for" do
|
6
|
-
before do
|
7
|
-
GoogleStaticMapsHelper.key = 'my_key'
|
8
|
-
GoogleStaticMapsHelper.size = '300x500'
|
9
|
-
GoogleStaticMapsHelper.sensor = false
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have a responding method" do
|
13
|
-
GoogleStaticMapsHelper.respond_to?(:url_for).should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should be possible to add markers to map through a b block" do
|
17
|
-
out = GoogleStaticMapsHelper.url_for do
|
18
|
-
marker :lat => 1, :lng => 2
|
19
|
-
end
|
20
|
-
|
21
|
-
out.should include('markers=color:red|size:mid|1,2')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should be possible to override the default map construction values" do
|
25
|
-
out = GoogleStaticMapsHelper.url_for(:size => '600x400') do
|
26
|
-
marker :lat => 1, :lng => 2
|
27
|
-
end
|
28
|
-
|
29
|
-
out.should include('size=600x400')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be able to add paths" do
|
33
|
-
point = {:lat => 1, :lng => 2}
|
34
|
-
point2 = {:lat => 3, :lng => 4}
|
35
|
-
|
36
|
-
out = GoogleStaticMapsHelper.url_for do
|
37
|
-
path point, point2, :color => :red
|
38
|
-
end
|
39
|
-
|
40
|
-
out.should include('path=color:red|1,2|3,4')
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be possible to use inside a class, using attributes of that class" do
|
44
|
-
class TestingClass
|
45
|
-
attr_reader :location
|
46
|
-
|
47
|
-
def initialize
|
48
|
-
@location = {:lat => 1, :lng => 5}
|
49
|
-
end
|
50
|
-
|
51
|
-
def url
|
52
|
-
GoogleStaticMapsHelper.url_for do |map|
|
53
|
-
map.marker location
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
TestingClass.new.url.should include('markers=color:red|size:mid|1,5')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/spec/location_spec.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe GoogleStaticMapsHelper::Location do
|
4
|
-
before :each do
|
5
|
-
@location_hash = {:lat => 10, :lng => 20}
|
6
|
-
@location_object = mock(:location, @location_hash)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "initialize" do
|
10
|
-
it "should raise ArgumentError if no arguments are given" do
|
11
|
-
lambda {GoogleStaticMapsHelper::Location.new}.should raise_error(ArgumentError)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "get location as object" do
|
15
|
-
[:lat, :lng].each do |location_property|
|
16
|
-
it "should extract #{location_property} from first argument if that is object" do
|
17
|
-
marker = GoogleStaticMapsHelper::Location.new(@location_object)
|
18
|
-
marker.send(location_property).should == @location_object.send(location_property)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should raise NoLngMethod if object doesn't respond to lng" do
|
23
|
-
lambda {GoogleStaticMapsHelper::Location.new(mock(:location, :lat => 10))}.should raise_error(GoogleStaticMapsHelper::Location::NoLngMethod)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should raise NoLatMethod if object doesn't respond to lat" do
|
27
|
-
lambda {GoogleStaticMapsHelper::Location.new(mock(:location, :lng => 20))}.should raise_error(GoogleStaticMapsHelper::Location::NoLatMethod)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "get location from hash" do
|
32
|
-
[:lat, :lng].each do |location_property|
|
33
|
-
it "should extract #{location_property} from hash" do
|
34
|
-
marker = GoogleStaticMapsHelper::Location.new(@location_hash)
|
35
|
-
marker.send(location_property).should == @location_object.send(location_property)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should raise NoLngKey if hash doesn't have key lng" do
|
40
|
-
lambda {GoogleStaticMapsHelper::Location.new(:lat => 10)}.should raise_error(GoogleStaticMapsHelper::Location::NoLngKey)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should raise NoLatKey if hash doesn't have key lat" do
|
44
|
-
lambda {GoogleStaticMapsHelper::Location.new(:lng => 20)}.should raise_error(GoogleStaticMapsHelper::Location::NoLatKey)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should return to_url with its lat and lng value" do
|
50
|
-
GoogleStaticMapsHelper::Location.new(@location_hash).to_url.should == '10,20'
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "reduce and round off lng and lat" do
|
54
|
-
before do
|
55
|
-
@location = GoogleStaticMapsHelper::Location.new(:lng => 0, :lat => 1)
|
56
|
-
end
|
57
|
-
|
58
|
-
[:lng, :lat].each do |attribute|
|
59
|
-
it "should not round #{attribute} when it is a number with a precision less than 6" do
|
60
|
-
@location.send("#{attribute}=", 12.000014)
|
61
|
-
@location.send(attribute).should == 12.000014
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should round #{attribute} when it is a number with a precision above 6" do
|
65
|
-
@location.send("#{attribute}=", 12.0000051)
|
66
|
-
@location.send(attribute).should == 12.000005
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should round and reduce #{attribute} when it's value is a float which can be represented with a descrete value" do
|
70
|
-
@location.send("#{attribute}=", 12.00000000001)
|
71
|
-
@location.send(attribute).to_s.should == "12"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "helper methods" do
|
77
|
-
[
|
78
|
-
[{:lat => 60, :lng => 0}, 0],
|
79
|
-
[{:lat => 60, :lng => 1}, 55597],
|
80
|
-
[{:lat => 61, :lng => 0}, 111195],
|
81
|
-
[{:lat => 60, :lng => 0.01}, 556]
|
82
|
-
].each do |point_distance|
|
83
|
-
it "should calculate correct distance to another location" do
|
84
|
-
another_point, expected_distance = point_distance
|
85
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 60, :lng => 0)
|
86
|
-
another_point = GoogleStaticMapsHelper::Location.new(another_point)
|
87
|
-
base.distance_to(another_point).should == expected_distance
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
[
|
93
|
-
[1000, 360, {:lat => 59.841958, :lng => 10.439303}],
|
94
|
-
[1000, 324, {:lat => 59.84024, :lng => 10.428782}],
|
95
|
-
[1000, 114, {:lat => 59.829306, :lng=> 10.45565}],
|
96
|
-
[1000, 18, {:lat => 59.841518, :lng => 10.444835}]
|
97
|
-
].each do |distance_heading_new_point|
|
98
|
-
it "should calculate new end point with given distance and heading" do
|
99
|
-
distance, heading, excpexted_point = distance_heading_new_point
|
100
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
|
101
|
-
new_point = base.endpoint(distance, heading)
|
102
|
-
|
103
|
-
new_point.lat.should == excpexted_point[:lat]
|
104
|
-
new_point.lng.should == excpexted_point[:lng]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "endpoints_for_circle_with_radius" do
|
109
|
-
it "should 30 + 1 end points for circle as default" do
|
110
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
|
111
|
-
endpoints = base.endpoints_for_circle_with_radius(1000)
|
112
|
-
endpoints.length.should == 31
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should have the same point as start and end (to make a closed circle)" do
|
116
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
|
117
|
-
endpoints = base.endpoints_for_circle_with_radius(1000)
|
118
|
-
endpoints.first.should == endpoints.last
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should reley on endpoint method to calculate new endpoints when creating circle points" do
|
122
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59.832964751405214, :lng => 10.439303436108082)
|
123
|
-
base.should_receive(:endpoint).with(1000, 0 * 360 / 4)
|
124
|
-
base.should_receive(:endpoint).with(1000, 1 * 360 / 4)
|
125
|
-
base.should_receive(:endpoint).with(1000, 2 * 360 / 4)
|
126
|
-
base.should_receive(:endpoint).with(1000, 3 * 360 / 4)
|
127
|
-
endpoints = base.endpoints_for_circle_with_radius(1000, 4)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should raise argument error if number of points asked to returned when creating a circle is above 360" do
|
131
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59, :lng => 10)
|
132
|
-
lambda {base.endpoints_for_circle_with_radius(1000, 361)}.should raise_error(ArgumentError)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should raise argument error if number of points asked to returned when creating a circle is less than 1" do
|
136
|
-
base = GoogleStaticMapsHelper::Location.new(:lat => 59, :lng => 10)
|
137
|
-
lambda {base.endpoints_for_circle_with_radius(1000, 0)}.should raise_error(ArgumentError)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
data/spec/map_spec.rb
DELETED
@@ -1,392 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe GoogleStaticMapsHelper::Map do
|
4
|
-
@@require_options = {
|
5
|
-
:size => '600x400',
|
6
|
-
:key => 'MY_GOOGLE_KEY',
|
7
|
-
:sensor => false
|
8
|
-
}
|
9
|
-
|
10
|
-
describe "initialize" do
|
11
|
-
before do
|
12
|
-
@@require_options.each_key {|k| GoogleStaticMapsHelper.send("#{k}=", nil)}
|
13
|
-
end
|
14
|
-
|
15
|
-
@@require_options.each_key do |key|
|
16
|
-
it "should raise OptionMissing if #{key} is not given" do
|
17
|
-
option_with_missing_option = @@require_options.dup
|
18
|
-
option_with_missing_option.delete(key)
|
19
|
-
lambda {GoogleStaticMapsHelper::Map.new(option_with_missing_option)}.should raise_error(GoogleStaticMapsHelper::OptionMissing)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should raise OptionNotExist if incomming option doesn't exists" do
|
24
|
-
lambda {GoogleStaticMapsHelper::Map.new(@@require_options.merge(:invalid_option => 'error?'))}.should raise_error(GoogleStaticMapsHelper::OptionNotExist)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to read initialized key option from object" do
|
28
|
-
GoogleStaticMapsHelper::Map.new(@@require_options).key.should == @@require_options[:key]
|
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
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "markers" do
|
42
|
-
before :each do
|
43
|
-
@marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 2)
|
44
|
-
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should be empty as default" do
|
48
|
-
@map.should be_empty
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should be able to push markers onto map" do
|
52
|
-
@map << @marker
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should not be possible to push the same marker twice" do
|
56
|
-
@map << @marker
|
57
|
-
@map << @marker
|
58
|
-
@map.length.should == 1
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should be able to push map << marker << marker" do
|
62
|
-
@map << @marker << GoogleStaticMapsHelper::Marker.new(:lat => 3, :lng => 5)
|
63
|
-
@map.length.should == 2
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should return it's markers via markers" do
|
67
|
-
@map << @marker
|
68
|
-
@map << GoogleStaticMapsHelper::Path.new
|
69
|
-
@map.markers.should == [@marker]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
describe "Grouped markers" do
|
75
|
-
before :each do
|
76
|
-
@marker1 = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
|
77
|
-
@marker11 = GoogleStaticMapsHelper::Marker.new(:lng => 3, :lat => 4)
|
78
|
-
|
79
|
-
@marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
|
80
|
-
@marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
|
81
|
-
@map = GoogleStaticMapsHelper::Map.new(:key => @key, :size => @size, :sensor => @sensor)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return options_to_url_params as key, array with markers as value" do
|
85
|
-
@map << @marker1
|
86
|
-
@map << @marker11
|
87
|
-
@map << @marker2
|
88
|
-
@map << @marker22
|
89
|
-
@map.grouped_markers.should == {
|
90
|
-
@marker1.options_to_url_params => [@marker1, @marker11],
|
91
|
-
@marker2.options_to_url_params => [@marker2, @marker22]
|
92
|
-
}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "paths" do
|
97
|
-
before do
|
98
|
-
@path = GoogleStaticMapsHelper::Path.new
|
99
|
-
@point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
|
100
|
-
@point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
|
101
|
-
@path << @point << @point2
|
102
|
-
|
103
|
-
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should be able to push paths on to map" do
|
107
|
-
@map << @path
|
108
|
-
@map.first.should == @path
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should be able to paths via paths" do
|
112
|
-
@marker = GoogleStaticMapsHelper::Marker.new(:lat => 1, :lng => 2)
|
113
|
-
@map << @path
|
114
|
-
@map << @marker
|
115
|
-
@map.paths.should == [@path]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
describe "size" do
|
121
|
-
before do
|
122
|
-
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
123
|
-
@map.size = '300x400'
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should return map's width" do
|
127
|
-
@map.width.should == 300
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should return map's height" do
|
131
|
-
@map.height.should == 400
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should be able to set width with width :-)" do
|
135
|
-
@map.width = '300'
|
136
|
-
@map.width.should == 300
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should be able to set height" do
|
140
|
-
@map.height = '300'
|
141
|
-
@map.height.should == 300
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should be able to set width and height via size as an array" do
|
145
|
-
@map.size = [200, 300]
|
146
|
-
@map.size.should == '200x300'
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should be able to set width and height via size as a hash" do
|
150
|
-
@map.size = {:width => 100, :height => 500}
|
151
|
-
@map.size.should == '100x500'
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should be possible to only set height via size as a hash" do
|
155
|
-
@map.size = {:height => 500}
|
156
|
-
@map.size.should == '300x500'
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should be possible to only set width via size as a hash" do
|
160
|
-
@map.size = {:width => 500}
|
161
|
-
@map.size.should == '500x400'
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should raise an error if width is above 640px as it is not supported by Google Maps" do
|
165
|
-
lambda {@map.width = 641}.should raise_error
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should raise an error if height is above 640px as it is not supported by Google Maps" do
|
169
|
-
lambda {@map.height = 641}.should raise_error
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "format" do
|
174
|
-
before do
|
175
|
-
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
176
|
-
end
|
177
|
-
|
178
|
-
%w{png png8 png32 gif jpg jpg-basedline}.each do |format|
|
179
|
-
it "should be possible to set a format to #{format}" do
|
180
|
-
@map.format = format
|
181
|
-
@map.format.should == format
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should be able to set format as symbol" do
|
186
|
-
@map.format = :jpg
|
187
|
-
@map.format.should == 'jpg'
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should raise an error if format is not supported" do
|
191
|
-
lambda {@map.format = :not_supported}.should raise_error(GoogleStaticMapsHelper::UnsupportedFormat)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "map type" do
|
196
|
-
before do
|
197
|
-
@map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
198
|
-
end
|
199
|
-
|
200
|
-
%w{roadmap satellite terrain hybrid}.each do |type|
|
201
|
-
it "should be possible to set map type to #{type}" do
|
202
|
-
@map.maptype = type
|
203
|
-
@map.maptype.should == type
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should be possible to set map type as a symbol" do
|
208
|
-
@map.maptype = :satellite
|
209
|
-
@map.maptype.should == 'satellite'
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should raise error if map type is not supported" do
|
213
|
-
lambda {@map.maptype = :not_supported}.should raise_error(GoogleStaticMapsHelper::UnsupportedMaptype)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "URL" do
|
218
|
-
before :each do
|
219
|
-
@key = 'MY_GOOGLE_KEY'
|
220
|
-
@size = '400x600'
|
221
|
-
@sensor = false
|
222
|
-
@map = GoogleStaticMapsHelper::Map.new(:key => @key, :size => @size, :sensor => @sensor)
|
223
|
-
|
224
|
-
@marker1 = GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2)
|
225
|
-
@marker11 = GoogleStaticMapsHelper::Marker.new(:lng => 3, :lat => 4)
|
226
|
-
|
227
|
-
@marker2 = GoogleStaticMapsHelper::Marker.new(:lng => 5, :lat => 6, :color => 'green')
|
228
|
-
@marker22 = GoogleStaticMapsHelper::Marker.new(:lng => 7, :lat => 8, :color => 'green')
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "valid state to run URL" do
|
232
|
-
it "should raise exception if called with no markers nor center and zoom" do
|
233
|
-
lambda{@map.url}.should raise_error(GoogleStaticMapsHelper::BuildDataMissing)
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should not raise exception if markers are in map" do
|
237
|
-
@map << @marker1
|
238
|
-
lambda{@map.url}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should not raise exception if center and zoom is set" do
|
242
|
-
@map.zoom = 1
|
243
|
-
@map.center = '1,1'
|
244
|
-
lambda{@map.url}.should_not raise_error(GoogleStaticMapsHelper::BuildDataMissing)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe "required parameters" do
|
249
|
-
before :each do
|
250
|
-
@map.zoom = 1
|
251
|
-
@map.center = '1,1'
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should start with the URL to the API" do
|
255
|
-
@map.url.should include(GoogleStaticMapsHelper::API_URL)
|
256
|
-
end
|
257
|
-
|
258
|
-
it "should include the key" do
|
259
|
-
@map.url.should include("key=#{@key}")
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should include the size" do
|
263
|
-
@map.url.should include("size=#{@size}")
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should include the sensor" do
|
267
|
-
@map.url.should include("sensor=#{@sensor}")
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should not include format as default" do
|
271
|
-
@map.url.should_not include("format=")
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should include format if it has been set" do
|
275
|
-
@map.format = :jpg
|
276
|
-
@map.url.should include("format=jpg")
|
277
|
-
end
|
278
|
-
|
279
|
-
it "should not include map type as default" do
|
280
|
-
@map.url.should_not include("maptype=")
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should include map type if it has been set" do
|
284
|
-
@map.maptype = :satellite
|
285
|
-
@map.url.should include("maptype=satellite")
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe "with no markers in map" do
|
290
|
-
before :each do
|
291
|
-
@map.zoom = 1
|
292
|
-
@map.center = '1,1'
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should contain center=2,3" do
|
296
|
-
@map.url.should include("center=1,1")
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should contain zoom=1" do
|
300
|
-
@map.url.should include("zoom=1")
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should not include markers param" do
|
304
|
-
@map.url.should_not include("markers=")
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
|
309
|
-
describe "with markers, no one grouped" do
|
310
|
-
before :each do
|
311
|
-
@map << @marker1
|
312
|
-
@map << @marker2
|
313
|
-
end
|
314
|
-
|
315
|
-
[
|
316
|
-
['key', 'MY_GOOGLE_KEY'],
|
317
|
-
['sensor', 'false'],
|
318
|
-
['size', '400x600'],
|
319
|
-
['markers', 'color:green|size:mid|6,5'],
|
320
|
-
['markers', 'color:red|size:mid|2,1']
|
321
|
-
].each do |pair|
|
322
|
-
key, value = pair
|
323
|
-
it "should have key: #{key} and value: #{value}" do
|
324
|
-
@map.url.should include("#{key}=#{value}")
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
describe "with markers grouped together" do
|
330
|
-
before :each do
|
331
|
-
@map.sensor = true
|
332
|
-
@map << @marker1
|
333
|
-
@map << @marker11
|
334
|
-
@map << @marker2
|
335
|
-
@map << @marker22
|
336
|
-
end
|
337
|
-
|
338
|
-
[
|
339
|
-
['key', 'MY_GOOGLE_KEY'],
|
340
|
-
['sensor', 'true'],
|
341
|
-
['size', '400x600'],
|
342
|
-
['markers', 'color:green|size:mid|6,5|8,7'],
|
343
|
-
['markers', 'color:red|size:mid|2,1|4,3']
|
344
|
-
].each do |pair|
|
345
|
-
key, value = pair
|
346
|
-
it "should have key: #{key} and value: #{value}" do
|
347
|
-
@map.url.should include("#{key}=#{value}")
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe "paths" do
|
353
|
-
before do
|
354
|
-
@path = GoogleStaticMapsHelper::Path.new
|
355
|
-
@point = GoogleStaticMapsHelper::Location.new(:lat => 1, :lng => 2)
|
356
|
-
@point2 = GoogleStaticMapsHelper::Location.new(:lat => 3, :lng => 4)
|
357
|
-
@path << @point << @point2
|
358
|
-
end
|
359
|
-
|
360
|
-
it "should not include path in url if no paths are represented in the map" do
|
361
|
-
@map.center = '1,2'
|
362
|
-
@map.zoom = 11
|
363
|
-
@map.url.should_not include("path=")
|
364
|
-
end
|
365
|
-
|
366
|
-
it "should include path in url if paths are represented in the map" do
|
367
|
-
@map << @path
|
368
|
-
@map.url.should include("path=")
|
369
|
-
end
|
370
|
-
|
371
|
-
[
|
372
|
-
['key', 'MY_GOOGLE_KEY'],
|
373
|
-
['sensor', 'false'],
|
374
|
-
['size', '400x600'],
|
375
|
-
['path', 'weight:5|1,2|3,4'],
|
376
|
-
].each do |pair|
|
377
|
-
key, value = pair
|
378
|
-
it "should have key: #{key} and value: #{value}" do
|
379
|
-
@path.weight = 5
|
380
|
-
@map << @path
|
381
|
-
@map.url.should include("#{key}=#{value}")
|
382
|
-
end
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should provide a helper method named marker which will create a new marker and add it to the map" do
|
388
|
-
map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
389
|
-
map.marker(:lat => 1, :lng => 2)
|
390
|
-
map.length.should eql(1)
|
391
|
-
end
|
392
|
-
end
|