static-gmaps2 0.0.5
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.
- data/History.txt +46 -0
- data/LICENSE.txt +21 -0
- data/Manifest.txt +6 -0
- data/Rakefile +52 -0
- data/lib/static_gmaps.rb +258 -0
- data/spec/static_gmaps_spec.rb +230 -0
- metadata +94 -0
data/History.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
=== 0.0.5 / 2010-02-14 by nat.lownes@gmail.com
|
2
|
+
* Updated most all of the Ruby API to match the most recent Google Static Maps API. This includes:
|
3
|
+
- Changed the maximum_url_size to 2048
|
4
|
+
- Changing parameters to match their Google API equivalents. i.e.:
|
5
|
+
- Marker's "alpha_character" can be used simply as :label / Marker#label=
|
6
|
+
- Changed available colors restrictions
|
7
|
+
- Updated marker label restriction to capital letters A-Z, 0-9
|
8
|
+
- Added required sensor parameter to Map
|
9
|
+
- Remove requiring a Google Maps API key. It can still be used via the original :key parameter.
|
10
|
+
- Updated Marker to accept:
|
11
|
+
- color
|
12
|
+
- label
|
13
|
+
- icon
|
14
|
+
- size
|
15
|
+
- shadow
|
16
|
+
* Changed MissingArgument instances to ArgumentError instances
|
17
|
+
* Added address support on both Map :center and Marker :location params/setters via a StaticGmaps::Location class.
|
18
|
+
* Added block initializer support if you cannot wield a lengthy hash like a weapon.
|
19
|
+
* All of these changes maintain backward compatibility with previous versions.
|
20
|
+
|
21
|
+
=== 0.0.4 / 2009-02-18 by daniel.mattes@gmx.de
|
22
|
+
|
23
|
+
* No Map::default_center, because of auto centering through google when markers.count > 1
|
24
|
+
* If no option[:markers] are given, they will be set to []. Otherwise the constant markers array will grow to unlimited.
|
25
|
+
* Setting constants like geokit do it.
|
26
|
+
In initializers you can overwrite it like
|
27
|
+
StaticGmaps::default_size = [ 170, 200 ]
|
28
|
+
* Now on http://github.com/dmattes/static-gmaps/
|
29
|
+
|
30
|
+
=== 0.0.3 / 2008-02-26
|
31
|
+
|
32
|
+
* 2 Minor Enhancement:
|
33
|
+
* Now raises exception when there are too many markers.
|
34
|
+
* Now raises exception when the url becomes too long.
|
35
|
+
|
36
|
+
=== 0.0.2 / 2008-02-25
|
37
|
+
|
38
|
+
* 1 Major Enhancement:
|
39
|
+
* Now supports Markers!
|
40
|
+
* 1 Minor Enhancement:
|
41
|
+
* Removed StaticGmaps::Map.to_blob
|
42
|
+
|
43
|
+
=== 0.0.1 / 2008-02-25
|
44
|
+
|
45
|
+
* 1 major enhancement
|
46
|
+
* Birthday!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'hoe'
|
25
|
+
require './lib/static_gmaps.rb'
|
26
|
+
begin
|
27
|
+
require 'spec/rake/spectask'
|
28
|
+
rescue LoadError
|
29
|
+
puts 'To use rspec for testing you must install rspec gem:'
|
30
|
+
puts '$ sudo gem install rspec'
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
Hoe.new('static-gmaps', StaticGmaps::version) do |p|
|
35
|
+
p.rubyforge_name = 'static-gmaps'
|
36
|
+
p.author = 'Daniel Mattes'
|
37
|
+
p.email = 'daniel.mattes@gmx.de'
|
38
|
+
p.summary = 'Provides an interface to the Google Static Maps API.'
|
39
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
40
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
41
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
42
|
+
p.remote_rdoc_dir = ''
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Run all examples"
|
46
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
47
|
+
t.spec_files = FileList['spec/*.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :spec
|
51
|
+
|
52
|
+
# vim: syntax=Ruby
|
data/lib/static_gmaps.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module StaticGmaps
|
4
|
+
@@version = '0.0.5'
|
5
|
+
|
6
|
+
#map
|
7
|
+
@@maximum_url_size = 2048
|
8
|
+
@@maximum_markers = 50
|
9
|
+
@@default_center = [ 0, 0 ]
|
10
|
+
@@default_zoom = 1
|
11
|
+
@@default_size = [ 500, 400 ]
|
12
|
+
@@default_map_type = :roadmap
|
13
|
+
@@default_key = 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA'
|
14
|
+
@@base_uri = 'http://maps.google.com/maps/api/staticmap'
|
15
|
+
|
16
|
+
#marker
|
17
|
+
@@default_latitude = nil
|
18
|
+
@@default_longitude = nil
|
19
|
+
@@default_color = nil
|
20
|
+
@@default_alpha_character = nil
|
21
|
+
@@valid_colors = [ :black, :brown, :green, :purple, :yellow, :blue, :gray, :orange, :red, :white ]
|
22
|
+
@@valid_alpha_characters = []
|
23
|
+
("A").upto("Z") do |letter|
|
24
|
+
@@valid_alpha_characters << letter
|
25
|
+
end
|
26
|
+
0.upto(9) do |n|
|
27
|
+
@@valid_alpha_characters << n.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
[:version, :maximum_url_size, :maximum_markers, :default_center, :default_zoom, :default_size, :default_map_type, :default_key,
|
31
|
+
:default_latitude, :default_longitude, :default_color, :default_alpha_character, :valid_colors, :valid_alpha_characters, :base_uri].each do |sym|
|
32
|
+
class_eval <<-EOS
|
33
|
+
def self.#{sym}
|
34
|
+
@@#{sym}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.#{sym}=(obj)
|
38
|
+
@@#{sym} = obj
|
39
|
+
end
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
class Map
|
44
|
+
|
45
|
+
attr_accessor :zoom,
|
46
|
+
:size,
|
47
|
+
:map_type,
|
48
|
+
:key,
|
49
|
+
:markers,
|
50
|
+
:sensor,
|
51
|
+
:format
|
52
|
+
|
53
|
+
def initialize(options = {}, &block)
|
54
|
+
self.center = options[:center]
|
55
|
+
self.zoom = options[:zoom] || StaticGmaps::default_zoom
|
56
|
+
self.size = options[:size] || StaticGmaps::default_size
|
57
|
+
self.map_type = options[:map_type] || StaticGmaps::default_map_type
|
58
|
+
self.sensor = options[:sensor] || false
|
59
|
+
self.key = options[:key]
|
60
|
+
self.format = options[:format]
|
61
|
+
self.markers = options[:markers] || [ ]
|
62
|
+
yield self if block_given?
|
63
|
+
end
|
64
|
+
|
65
|
+
def width
|
66
|
+
size[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
def height
|
70
|
+
size[1]
|
71
|
+
end
|
72
|
+
|
73
|
+
def center=(array_or_string)
|
74
|
+
@center = Location.new(array_or_string)
|
75
|
+
end
|
76
|
+
|
77
|
+
def center
|
78
|
+
@center ? @center.value : nil
|
79
|
+
end
|
80
|
+
|
81
|
+
# http://code.google.com/apis/maps/documentation/staticmaps/index.html#URL_Parameters
|
82
|
+
def url
|
83
|
+
raise ArgumentError.new("Size must be set before a url can be generated for Map.") if !size || !size[0] || !size[1]
|
84
|
+
|
85
|
+
if(!self.center && !(markers && markers.size >= 1))
|
86
|
+
self.center = StaticGmaps::default_center
|
87
|
+
end
|
88
|
+
|
89
|
+
if !(markers && markers.size >= 1)
|
90
|
+
raise ArgumentError.new("Center must be set before a url can be generated for Map (or multiple markers can be specified).") if !center
|
91
|
+
raise ArgumentError.new("Zoom must be set before a url can be generated for Map (or multiple markers can be specified).") if !zoom
|
92
|
+
end
|
93
|
+
raise "Google will not display more than #{StaticGmaps::maximum_markers} markers." if markers && markers.size > StaticGmaps::maximum_markers
|
94
|
+
parameters = {}
|
95
|
+
parameters[:size] = "#{size[0]}x#{size[1]}"
|
96
|
+
parameters[:key] = "#{key}" if key
|
97
|
+
parameters[:map_type] = "#{map_type}" if map_type
|
98
|
+
parameters[:center] = "#{@center.to_s}" if center
|
99
|
+
parameters[:zoom] = "#{zoom}" if zoom
|
100
|
+
parameters[:markers] = "#{markers_url_fragment}" if markers_url_fragment
|
101
|
+
parameters[:sensor] = "#{sensor}"
|
102
|
+
parameters[:format] = "#{format}" if format
|
103
|
+
parameters = parameters.to_a.sort { |a, b| a[0].to_s <=> b[0].to_s }
|
104
|
+
parameters = parameters.collect { |parameter| "#{parameter[0]}=#{parameter[1]}" }
|
105
|
+
parameters = parameters.join '&'
|
106
|
+
x = "#{StaticGmaps.base_uri}?#{parameters}"
|
107
|
+
raise "Google doesn't like the url to be longer than #{StaticGmaps::maximum_url_size} characters. Try fewer or less precise markers." if x.size > StaticGmaps::maximum_url_size
|
108
|
+
return x
|
109
|
+
end
|
110
|
+
|
111
|
+
def markers_url_fragment
|
112
|
+
if markers && markers.any?
|
113
|
+
return markers.collect{|marker| marker.url_fragment }.join('&markers=')
|
114
|
+
else
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_blob
|
120
|
+
fetch
|
121
|
+
return @blob
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
def fetch
|
126
|
+
if !@last_fetched_url || @last_fetched_url != url || !@blob
|
127
|
+
uri = URI.parse url
|
128
|
+
request = Net::HTTP::Get.new uri.path
|
129
|
+
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request request }
|
130
|
+
@blob = response.body
|
131
|
+
@last_fetched_url = url
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# http://code.google.com/apis/maps/documentation/staticmaps/index.html#Markers
|
137
|
+
class Marker
|
138
|
+
|
139
|
+
attr_reader :color,
|
140
|
+
:label,
|
141
|
+
:size,
|
142
|
+
:icon,
|
143
|
+
:shadow
|
144
|
+
|
145
|
+
def initialize(options = {}, &block)
|
146
|
+
self.location = options[:location] || [StaticGmaps::default_latitude, StaticGmaps::default_longitude]
|
147
|
+
self.label = options[:label] || StaticGmaps::default_alpha_character
|
148
|
+
self.color = options[:color] || StaticGmaps::default_color
|
149
|
+
# original api compatibility
|
150
|
+
self.label = options[:alpha_character] if options[:alpha_character]
|
151
|
+
self.latitude = options[:latitude] if options[:latitude]
|
152
|
+
self.longitude = options[:longitude] if options[:longitude]
|
153
|
+
yield self if block_given?
|
154
|
+
end
|
155
|
+
|
156
|
+
def available_parameters
|
157
|
+
[:location, :color, :label, :size, :icon, :shadow]
|
158
|
+
end
|
159
|
+
|
160
|
+
def attributes
|
161
|
+
self.available_parameters.inject({}) do |store, parameter_name|
|
162
|
+
value = self.send(parameter_name)
|
163
|
+
store[parameter_name] = value if value
|
164
|
+
store
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def color=(value)
|
169
|
+
if value
|
170
|
+
value = value.to_s.downcase.to_sym
|
171
|
+
if !StaticGmaps::valid_colors.include?(value)
|
172
|
+
raise ArgumentError.new("#{value} is not a supported color. Supported colors are #{StaticGmaps::valid_colors.join(', ')}.")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
@color = value
|
176
|
+
end
|
177
|
+
|
178
|
+
def icon=(url)
|
179
|
+
@icon = (URI.encode(url, "?|&"))
|
180
|
+
end
|
181
|
+
|
182
|
+
def location=(array_or_string)
|
183
|
+
@location = Location.new(array_or_string)
|
184
|
+
end
|
185
|
+
|
186
|
+
def location
|
187
|
+
@location ? @location.value : nil
|
188
|
+
end
|
189
|
+
|
190
|
+
def latitude=(f)
|
191
|
+
@location.value[0] = f
|
192
|
+
end
|
193
|
+
|
194
|
+
def longitude=(f)
|
195
|
+
@location.value[1] = f
|
196
|
+
end
|
197
|
+
|
198
|
+
def latitude
|
199
|
+
@location.value[0] if @location.value.is_a?(Array)
|
200
|
+
end
|
201
|
+
|
202
|
+
def longitude
|
203
|
+
@location.value[1] if @location.value.is_a?(Array)
|
204
|
+
end
|
205
|
+
|
206
|
+
def label=(value)
|
207
|
+
if value
|
208
|
+
value = value.to_s.upcase
|
209
|
+
if !StaticGmaps::valid_alpha_characters.include?(value)
|
210
|
+
raise ArgumentError.new("#{value} is not a supported label. Supported labels are #{StaticGmaps::valid_alpha_characters.join(', ')}.")
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@label = value
|
214
|
+
end
|
215
|
+
|
216
|
+
# for compatibility with original ruby api
|
217
|
+
def alpha_character=(value)
|
218
|
+
self.label = value
|
219
|
+
end
|
220
|
+
|
221
|
+
def alpha_character
|
222
|
+
self.label
|
223
|
+
end
|
224
|
+
|
225
|
+
def url_fragment
|
226
|
+
# markers=color:blue|label:S|62.107733,-145.541936&markers=size:tiny|color:green|Delta+Junction,AK
|
227
|
+
raise ArgumentError.new("Location must be set before a url_fragment can be generated for Marker.") if !location
|
228
|
+
marker_parameter_separator = "|"
|
229
|
+
marker_value_separator = ":"
|
230
|
+
location = @location.to_s
|
231
|
+
str = ""
|
232
|
+
attrs = self.attributes
|
233
|
+
attrs.delete(:location)
|
234
|
+
if !attrs.empty?
|
235
|
+
str << attrs.map {|parameter, value| "#{parameter}#{marker_value_separator}#{value}"}.join(marker_parameter_separator)
|
236
|
+
str << marker_parameter_separator
|
237
|
+
end
|
238
|
+
str << location
|
239
|
+
str
|
240
|
+
end
|
241
|
+
end#Marker
|
242
|
+
|
243
|
+
class Location
|
244
|
+
attr_reader :value
|
245
|
+
def initialize(coordinates_array_or_address)
|
246
|
+
@value = if coordinates_array_or_address.is_a?(String)
|
247
|
+
URI.encode(coordinates_array_or_address)
|
248
|
+
else
|
249
|
+
coordinates_array_or_address
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def to_s
|
254
|
+
@value.is_a?(Array) ? @value.join(",") : @value
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'static_gmaps')
|
4
|
+
include StaticGmaps
|
5
|
+
|
6
|
+
STATIC_GOOGLE_MAP_DEFAULT_PARAMETERS_TEST_IMAGE_PATH = File.join File.dirname(__FILE__), 'test_image.gif'
|
7
|
+
|
8
|
+
describe StaticGmaps do
|
9
|
+
describe Map do
|
10
|
+
context "initializing with empty attributes" do
|
11
|
+
before(:each) do
|
12
|
+
@map = StaticGmaps::Map.new
|
13
|
+
end
|
14
|
+
|
15
|
+
#it 'should set center to default' do @map.center.should == StaticGmaps::default_center end
|
16
|
+
# no default center, because of auto adjustment
|
17
|
+
it 'should set zoom to default' do
|
18
|
+
@map.zoom.should == StaticGmaps::default_zoom
|
19
|
+
end
|
20
|
+
it 'should set size to default' do
|
21
|
+
@map.size.should == StaticGmaps::default_size
|
22
|
+
end
|
23
|
+
it 'should set map_type to default' do
|
24
|
+
@map.map_type.should == StaticGmaps::default_map_type
|
25
|
+
end
|
26
|
+
it 'should not set key if not provided' do
|
27
|
+
@map.key.should be_nil
|
28
|
+
end
|
29
|
+
end # initialize without attr
|
30
|
+
|
31
|
+
context 'initializing with all attributes' do
|
32
|
+
before(:each) do
|
33
|
+
@marker = StaticGmaps::Marker.new :latitude => 0, :longitude => 0
|
34
|
+
@map = StaticGmaps::Map.new :center => [ 40.714728, -73.998672 ],
|
35
|
+
:zoom => 12,
|
36
|
+
:size => [ 500, 400 ],
|
37
|
+
:map_type => :roadmap,
|
38
|
+
:key => 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA',
|
39
|
+
:markers => [ @marker ]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should set center' do
|
43
|
+
@map.center.should == [ 40.714728, -73.998672 ]
|
44
|
+
end
|
45
|
+
it 'should set zoom' do
|
46
|
+
@map.zoom.should == 12
|
47
|
+
end
|
48
|
+
it 'should set size' do
|
49
|
+
@map.size.should == [ 500, 400 ]
|
50
|
+
end
|
51
|
+
it 'should set map_type' do
|
52
|
+
@map.map_type.should == :roadmap
|
53
|
+
end
|
54
|
+
it 'should set key if provided' do
|
55
|
+
@map.key.should == 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA'
|
56
|
+
end
|
57
|
+
it 'should set markers' do
|
58
|
+
@map.markers.should == [ @marker ]
|
59
|
+
end
|
60
|
+
|
61
|
+
end#initialize w/all attrs
|
62
|
+
|
63
|
+
context 'with default attributes' do
|
64
|
+
before(:each) do
|
65
|
+
@map = StaticGmaps::Map.new
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should have a url' do
|
69
|
+
@map.url.should == "#{StaticGmaps.base_uri}?center=0,0&map_type=roadmap&sensor=false&size=500x400&zoom=1"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should have a width' do
|
73
|
+
@map.width.should == 500
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should have a height' do
|
77
|
+
@map.height.should == 400
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should set sensor attribute to false' do
|
81
|
+
@map.sensor.should be_false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with default attributes and markers' do
|
86
|
+
before(:each) do
|
87
|
+
@marker_1 = StaticGmaps::Marker.new :latitude => 10, :longitude => 20, :color => 'green', :label => 'A'
|
88
|
+
@marker_2 = StaticGmaps::Marker.new :latitude => 15, :longitude => 25, :color => 'blue', :label => 'B'
|
89
|
+
@map = StaticGmaps::Map.new :markers => [ @marker_1, @marker_2 ]
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should have a markers_url_fragment' do
|
93
|
+
# the first "markers" parameter for multiple markers will be added on in Map#url
|
94
|
+
@map.markers_url_fragment.should match(/color:green/)
|
95
|
+
@map.markers_url_fragment.should match(/color:blue/)
|
96
|
+
@map.markers_url_fragment.should match(/label:A/)
|
97
|
+
@map.markers_url_fragment.should match(/label:B/)
|
98
|
+
@map.markers_url_fragment.should match(/10,20/)
|
99
|
+
@map.markers_url_fragment.should match(/15,25/)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should include the markers_url_fragment its url' do
|
103
|
+
@map.url.should include(@map.markers_url_fragment)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end #describe Map
|
107
|
+
|
108
|
+
describe Marker do
|
109
|
+
context 'initializing with no attributes' do
|
110
|
+
before(:each) do
|
111
|
+
@marker = StaticGmaps::Marker.new
|
112
|
+
end
|
113
|
+
it 'should set latitude to default' do
|
114
|
+
@marker.latitude.should == StaticGmaps::default_latitude
|
115
|
+
end
|
116
|
+
it 'should set longitude to default' do
|
117
|
+
@marker.longitude.should == StaticGmaps::default_longitude
|
118
|
+
end
|
119
|
+
it 'should set color to default' do
|
120
|
+
@marker.color.should == StaticGmaps::default_color
|
121
|
+
end
|
122
|
+
it 'should set alpha_character to default' do
|
123
|
+
@marker.label.should == StaticGmaps::default_alpha_character
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'initialize with all attributes' do
|
128
|
+
before(:each) do
|
129
|
+
@marker = StaticGmaps::Marker.new :latitude => 12,
|
130
|
+
:longitude => 34,
|
131
|
+
:color => 'red',
|
132
|
+
:alpha_character => 'z'
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should set latitude' do
|
136
|
+
@marker.latitude.should == 12
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should set longitude' do
|
140
|
+
@marker.longitude.should == 34
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should set color' do
|
144
|
+
@marker.color.should == :red
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should set alpha_character' do
|
148
|
+
@marker.alpha_character.should == "Z"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'initialize with address as location' do
|
153
|
+
before :each do
|
154
|
+
@address = '1234 Market St. Philadelphia, PA'
|
155
|
+
@marker = Marker.new do |m|
|
156
|
+
m.location = @address
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should return a uri encoded address for location' do
|
161
|
+
@marker.location.should == URI.encode(@address)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should return nil for latitude' do
|
165
|
+
@marker.latitude.should be_nil
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should return nil for longitude' do
|
169
|
+
@marker.longitude.should be_nil
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'url_fragment ordering' do
|
174
|
+
before :each do
|
175
|
+
@address = '1234 Market St. Philadelphia, PA'
|
176
|
+
@marker = Marker.new do |m|
|
177
|
+
m.location = @address
|
178
|
+
m.color = "red"
|
179
|
+
m.label = 1
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should end with the address/coordinates' do
|
184
|
+
@marker.url_fragment.should match /.PA$/
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "using a custom icon" do
|
189
|
+
before :each do
|
190
|
+
@uri = 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=home|FFFF00'
|
191
|
+
@marker = Marker.new do |m|
|
192
|
+
m.location = [40.000, -33.000]
|
193
|
+
m.icon = @uri
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should also encode |, &, and ?' do
|
198
|
+
@marker.icon.should == 'http://chart.apis.google.com/chart%3Fchst=d_map_pin_icon%26chld=home%7CFFFF00'
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end #Marker
|
204
|
+
|
205
|
+
describe Location do
|
206
|
+
before(:each) do
|
207
|
+
@coordinates = [39.967648,-75.156784]
|
208
|
+
@address = '1234 Market St. Philadelphia, PA'
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should initialize with either an array or a string' do
|
212
|
+
lambda {
|
213
|
+
Location.new(@coordinates)
|
214
|
+
}.should_not raise_error
|
215
|
+
|
216
|
+
lambda {
|
217
|
+
Location.new(@address)
|
218
|
+
}.should_not raise_error
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should URI.encode an address string' do
|
222
|
+
Location.new(@address).value.should == URI.encode(@address)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should return either array of coordinates or address with Location#value()' do
|
226
|
+
Location.new(@coordinates).value.should == @coordinates
|
227
|
+
end
|
228
|
+
|
229
|
+
end #describe Location
|
230
|
+
end #describe StaticGmaps
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: static-gmaps2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Wulff
|
14
|
+
- Daniel Mattes
|
15
|
+
- Nat Lownes
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-06-30 00:00:00 -04:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: hoe
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 49
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 8
|
35
|
+
- 3
|
36
|
+
version: 1.8.3
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
description: |-
|
40
|
+
== DESCRIPTION: Provides an interface to the Google Static Maps API V3. Based on static-gmaps
|
41
|
+
== FEATURES/PROBLEMS: * Provides an interface to the Google Static Maps API.
|
42
|
+
email: nat.lownes@gmail.com
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
extra_rdoc_files:
|
48
|
+
- History.txt
|
49
|
+
- LICENSE.txt
|
50
|
+
- Manifest.txt
|
51
|
+
files:
|
52
|
+
- History.txt
|
53
|
+
- LICENSE.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- Rakefile
|
56
|
+
- lib/static_gmaps.rb
|
57
|
+
- spec/static_gmaps_spec.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/natlownes/static-gmaps/
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- readme.txt
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: static-gmaps
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 2
|
92
|
+
summary: Provides an interface to the Google Static Maps API.
|
93
|
+
test_files: []
|
94
|
+
|