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
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module GoogleStaticMapsHelper
|
2
3
|
#
|
3
4
|
# The Map keeps track of the state of which we want to build a URL for.
|
@@ -6,16 +7,16 @@ module GoogleStaticMapsHelper
|
|
6
7
|
#
|
7
8
|
class Map
|
8
9
|
include Enumerable
|
9
|
-
|
10
|
+
|
10
11
|
MAX_WIDTH = 640
|
11
12
|
MAX_HEIGHT = 640
|
12
13
|
|
13
14
|
VALID_FORMATS = %w{png png8 png32 gif jpg jpg-basedline}
|
14
15
|
VALID_MAP_TYPES = %w{roadmap satellite terrain hybrid}
|
15
16
|
|
16
|
-
REQUIRED_OPTIONS = [:
|
17
|
-
OPTIONAL_OPTIONS = [:center, :zoom, :format, :maptype, :mobile, :language]
|
18
|
-
|
17
|
+
REQUIRED_OPTIONS = [:size, :sensor]
|
18
|
+
OPTIONAL_OPTIONS = [:key, :center, :zoom, :format, :maptype, :mobile, :language]
|
19
|
+
|
19
20
|
attr_accessor *(REQUIRED_OPTIONS + OPTIONAL_OPTIONS)
|
20
21
|
attr_accessor :width, :height
|
21
22
|
|
@@ -25,7 +26,6 @@ module GoogleStaticMapsHelper
|
|
25
26
|
# <tt>:options</tt>:: The options available are the same as described in
|
26
27
|
# Google's API documentation[http://code.google.com/apis/maps/documentation/staticmaps/#Usage].
|
27
28
|
# In short, valid options are:
|
28
|
-
# <tt>:key</tt>:: Your Google maps API key
|
29
29
|
# <tt>:size</tt>:: The size of the map. Can be a "wxh", [w,h] or {:width => x, :height => y}
|
30
30
|
# <tt>:sensor</tt>:: Set to true if your application is using a sensor. See the API doc.
|
31
31
|
# <tt>:center</tt>:: The center point of your map. Optional if you add markers or path to the map
|
@@ -35,7 +35,7 @@ module GoogleStaticMapsHelper
|
|
35
35
|
# <tt>:mobile</tt>:: Returns map tiles better suited for mobile devices with small screens.
|
36
36
|
# <tt>:language</tt>:: The language used in the map
|
37
37
|
#
|
38
|
-
def initialize(options)
|
38
|
+
def initialize(options = {})
|
39
39
|
inject_defaults_from_module_class_attribute!(options)
|
40
40
|
validate_required_options(options)
|
41
41
|
validate_options(options)
|
@@ -49,13 +49,13 @@ module GoogleStaticMapsHelper
|
|
49
49
|
#
|
50
50
|
def url
|
51
51
|
raise BuildDataMissing, "We have to have markers, paths or center and zoom set when url is called!" unless can_build?
|
52
|
-
|
52
|
+
|
53
53
|
out = "#{API_URL}?"
|
54
54
|
|
55
55
|
params = []
|
56
56
|
(REQUIRED_OPTIONS + OPTIONAL_OPTIONS).each do |key|
|
57
57
|
value = send(key)
|
58
|
-
params << "#{key}=#{URI.escape(value.to_s)}" unless value.nil?
|
58
|
+
params << "#{key}=#{URI::DEFAULT_PARSER.escape(value.to_s)}" unless value.nil?
|
59
59
|
end
|
60
60
|
out += params.join('&')
|
61
61
|
|
@@ -65,7 +65,7 @@ module GoogleStaticMapsHelper
|
|
65
65
|
params << "markers=#{marker_options_as_url_params}|#{markers_locations}"
|
66
66
|
end
|
67
67
|
out += "&#{params.join('&')}" unless params.empty?
|
68
|
-
|
68
|
+
|
69
69
|
params = []
|
70
70
|
paths.each {|path| params << path.url_params}
|
71
71
|
out += "&#{params.join('&')}" unless params.empty?
|
@@ -93,13 +93,13 @@ module GoogleStaticMapsHelper
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# Returns all the paths which this map holds
|
98
98
|
#
|
99
99
|
def paths
|
100
100
|
@map_enteties.select {|e| e.is_a? Path}
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
#
|
104
104
|
# Pushes either a Marker or a Path on to the map
|
105
105
|
#
|
@@ -135,7 +135,7 @@ module GoogleStaticMapsHelper
|
|
135
135
|
def path(*args) # :nodoc:
|
136
136
|
self << Path.new(*args)
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
#
|
140
140
|
# Sets the size of the map
|
141
141
|
#
|
@@ -159,14 +159,14 @@ module GoogleStaticMapsHelper
|
|
159
159
|
self.height = height if height
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
#
|
164
164
|
# Returns size as a string, "wxh"
|
165
165
|
#
|
166
166
|
def size
|
167
167
|
[@width, @height].join('x')
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
#
|
171
171
|
# Defines width and height setter methods
|
172
172
|
#
|
@@ -202,6 +202,26 @@ module GoogleStaticMapsHelper
|
|
202
202
|
raise UnsupportedMaptype unless VALID_MAP_TYPES.include? @maptype
|
203
203
|
end
|
204
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
|
205
225
|
|
206
226
|
private
|
207
227
|
#
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module GoogleStaticMapsHelper
|
2
3
|
#
|
3
4
|
# A marker object is representing a marker with a customizable label, color and size.
|
@@ -6,7 +7,9 @@ module GoogleStaticMapsHelper
|
|
6
7
|
DEFAULT_OPTIONS = {
|
7
8
|
:color => 'red',
|
8
9
|
:size => 'mid',
|
9
|
-
:label => nil
|
10
|
+
:label => nil,
|
11
|
+
:icon => nil,
|
12
|
+
:shadow => nil
|
10
13
|
}
|
11
14
|
|
12
15
|
attr_accessor :location, *DEFAULT_OPTIONS.keys
|
@@ -29,7 +32,7 @@ module GoogleStaticMapsHelper
|
|
29
32
|
#
|
30
33
|
# # Sets location via object which responds to lng and lat
|
31
34
|
# GoogleStaticMapsHelper::Marker.new(location {:label => :a})
|
32
|
-
#
|
35
|
+
#
|
33
36
|
# # ..or include the lng and lat in the option hash
|
34
37
|
# GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :label => :a)
|
35
38
|
#
|
@@ -41,27 +44,30 @@ module GoogleStaticMapsHelper
|
|
41
44
|
options.each_pair { |k, v| send("#{k}=", v) }
|
42
45
|
end
|
43
46
|
|
44
|
-
#
|
47
|
+
#
|
45
48
|
# Returns a string representing this marker
|
46
49
|
# Used by the Map when building url.
|
47
50
|
#
|
48
51
|
def options_to_url_params # :nodoc:
|
49
52
|
params = DEFAULT_OPTIONS.keys.map(&:to_s).sort.inject([]) do |params, attr|
|
50
|
-
|
51
|
-
|
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::DEFAULT_PARSER.escape(value.to_s)}" unless value.nil?
|
52
58
|
params
|
53
59
|
end
|
54
60
|
|
55
61
|
params.join('|')
|
56
62
|
end
|
57
63
|
|
58
|
-
#
|
64
|
+
#
|
59
65
|
# Concatenation of lat and lng value. Used when building URLs and returns them in correct order
|
60
66
|
#
|
61
67
|
def location_to_url # :nodoc:
|
62
68
|
@location.to_url
|
63
69
|
end
|
64
|
-
|
70
|
+
|
65
71
|
def label # :nodoc:
|
66
72
|
@label.to_s.upcase if @label
|
67
73
|
end
|
@@ -70,6 +76,10 @@ module GoogleStaticMapsHelper
|
|
70
76
|
@color.downcase if @color
|
71
77
|
end
|
72
78
|
|
79
|
+
def has_icon?
|
80
|
+
!!@icon
|
81
|
+
end
|
82
|
+
|
73
83
|
|
74
84
|
#
|
75
85
|
# Proxies calls to the internal object which keeps track of this marker's location.
|
@@ -90,5 +100,18 @@ module GoogleStaticMapsHelper
|
|
90
100
|
invalid_options = options.keys - DEFAULT_OPTIONS.keys
|
91
101
|
raise OptionNotExist, "The following options does not exist: #{invalid_options.join(', ')}" unless invalid_options.empty?
|
92
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
|
93
116
|
end
|
94
117
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module GoogleStaticMapsHelper
|
2
3
|
#
|
3
4
|
# A Path is used to draw things in the map, either lines or Polygons.
|
@@ -8,12 +9,12 @@ module GoogleStaticMapsHelper
|
|
8
9
|
|
9
10
|
OPTIONAL_OPTIONS = [:weight, :color, :fillcolor]
|
10
11
|
|
11
|
-
attr_accessor :points, *OPTIONAL_OPTIONS
|
12
|
+
attr_accessor :encode_points, :points, *OPTIONAL_OPTIONS
|
12
13
|
|
13
14
|
#
|
14
15
|
# Creates a new Path which you can push points on to to make up lines or polygons
|
15
16
|
#
|
16
|
-
# The following options are available, for more information see the
|
17
|
+
# The following options are available, for more information see the
|
17
18
|
# Google API documentation[http://code.google.com/apis/maps/documentation/staticmaps/#Paths].
|
18
19
|
#
|
19
20
|
# <tt>:weight</tt>:: The weight is the thickness of the line, defaults to 5
|
@@ -24,10 +25,12 @@ module GoogleStaticMapsHelper
|
|
24
25
|
# as described in the <tt>:color</tt>. When used, the static map will automatically create
|
25
26
|
# a closed shape.
|
26
27
|
# <tt>:points</tt>:: An array of points. You can mix objects responding to lng and lat, and a Hash with lng and lat keys.
|
28
|
+
# <tt>:encode_points:: A flag which tells us if we should encode the points in this path or not. Defaults to <tt>true</tt>
|
27
29
|
#
|
28
30
|
def initialize(*args)
|
29
31
|
@points = []
|
30
|
-
|
32
|
+
@encode_points = true
|
33
|
+
|
31
34
|
extract_options!(args)
|
32
35
|
add_points(args)
|
33
36
|
end
|
@@ -39,24 +42,24 @@ module GoogleStaticMapsHelper
|
|
39
42
|
def url_params # :nodoc:
|
40
43
|
raise BuildDataMissing, "Need at least 2 points to create a path!" unless can_build?
|
41
44
|
out = 'path='
|
42
|
-
|
45
|
+
|
43
46
|
path_params = OPTIONAL_OPTIONS.inject([]) do |path_params, attribute|
|
44
47
|
value = send(attribute)
|
45
|
-
path_params << "#{attribute}:#{URI.escape(value.to_s)}" unless value.nil?
|
48
|
+
path_params << "#{attribute}:#{URI::DEFAULT_PARSER.escape(value.to_s)}" unless value.nil?
|
46
49
|
path_params
|
47
50
|
end.join('|')
|
48
51
|
|
49
52
|
out += "#{path_params}|" unless path_params.empty?
|
50
53
|
|
51
|
-
out +=
|
52
|
-
|
53
|
-
|
54
|
+
out += encoded_url_points if encoding_points?
|
55
|
+
out += unencoded_url_points unless encoding_points?
|
56
|
+
out
|
54
57
|
end
|
55
58
|
|
56
|
-
|
59
|
+
|
57
60
|
#
|
58
61
|
# Sets the points of this Path.
|
59
|
-
#
|
62
|
+
#
|
60
63
|
# *WARNING* Using this method will clear out any points which might be set.
|
61
64
|
#
|
62
65
|
def points=(array)
|
@@ -77,6 +80,10 @@ module GoogleStaticMapsHelper
|
|
77
80
|
length == 0
|
78
81
|
end
|
79
82
|
|
83
|
+
def clear
|
84
|
+
@points = []
|
85
|
+
end
|
86
|
+
|
80
87
|
#
|
81
88
|
# Pushes a new point into the Path
|
82
89
|
#
|
@@ -90,6 +97,14 @@ module GoogleStaticMapsHelper
|
|
90
97
|
self
|
91
98
|
end
|
92
99
|
|
100
|
+
#
|
101
|
+
# Will answer the question if we are encoding the points or not when
|
102
|
+
# building the image URL.
|
103
|
+
#
|
104
|
+
def encoding_points?
|
105
|
+
return !!@encode_points
|
106
|
+
end
|
107
|
+
|
93
108
|
|
94
109
|
private
|
95
110
|
#
|
@@ -100,8 +115,8 @@ module GoogleStaticMapsHelper
|
|
100
115
|
return point if point.instance_of? Location
|
101
116
|
Location.new(point)
|
102
117
|
end
|
103
|
-
|
104
|
-
#
|
118
|
+
|
119
|
+
#
|
105
120
|
# Do we have enough points to build a path?
|
106
121
|
#
|
107
122
|
def can_build?
|
@@ -116,5 +131,19 @@ module GoogleStaticMapsHelper
|
|
116
131
|
def add_points(points)
|
117
132
|
points.each {|point| self << point}
|
118
133
|
end
|
134
|
+
|
135
|
+
def encoded_url_points
|
136
|
+
encoder = GMapPolylineEncoder.new
|
137
|
+
points_as_array = points.map { |location| [location.lat, location.lng]}
|
138
|
+
result = encoder.encode(points_as_array)
|
139
|
+
|
140
|
+
"enc:#{result[:points]}"
|
141
|
+
end
|
142
|
+
|
143
|
+
def unencoded_url_points
|
144
|
+
inject([]) do |point_params, point|
|
145
|
+
point_params << point.to_url
|
146
|
+
end.join('|')
|
147
|
+
end
|
119
148
|
end
|
120
149
|
end
|
metadata
CHANGED
@@ -1,88 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_static_maps_helper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Thorbjørn Hermansen
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
16
42
|
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
17
48
|
type: :development
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
21
52
|
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
version:
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
25
55
|
description: This gem provides a simple interface to the Google Static Maps V2 API.
|
26
|
-
email:
|
56
|
+
email:
|
57
|
+
- thhermansen@gmail.com
|
27
58
|
executables: []
|
28
|
-
|
29
59
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
|
35
|
-
- .
|
36
|
-
- .gitignore
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".document"
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
37
66
|
- LICENSE
|
38
67
|
- README.rdoc
|
39
68
|
- Rakefile
|
40
|
-
- VERSION
|
41
69
|
- changelog.txt
|
42
70
|
- google_static_maps_helper.gemspec
|
43
71
|
- lib/google_static_maps_helper.rb
|
72
|
+
- lib/google_static_maps_helper/gmap_polyline_encoder.rb
|
44
73
|
- lib/google_static_maps_helper/location.rb
|
45
74
|
- lib/google_static_maps_helper/map.rb
|
46
75
|
- lib/google_static_maps_helper/marker.rb
|
47
76
|
- lib/google_static_maps_helper/path.rb
|
48
|
-
-
|
49
|
-
- spec/location_spec.rb
|
50
|
-
- spec/map_spec.rb
|
51
|
-
- spec/marker_spec.rb
|
52
|
-
- spec/path_spec.rb
|
53
|
-
- spec/spec_helper.rb
|
54
|
-
has_rdoc: true
|
77
|
+
- lib/google_static_maps_helper/version.rb
|
55
78
|
homepage: http://github.com/thhermansen/google_static_maps_helper
|
56
|
-
licenses:
|
57
|
-
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata:
|
82
|
+
homepage_uri: http://github.com/thhermansen/google_static_maps_helper
|
83
|
+
source_code_uri: http://github.com/thhermansen/google_static_maps_helper
|
84
|
+
changelog_uri: https://github.com/thhermansen/google_static_maps_helper/blob/master/changelog.txt
|
58
85
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
61
|
-
require_paths:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
62
88
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
65
91
|
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
68
|
-
|
69
|
-
|
70
|
-
requirements:
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
71
96
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
version:
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
75
99
|
requirements: []
|
76
|
-
|
77
|
-
rubyforge_project:
|
78
|
-
rubygems_version: 1.3.5
|
100
|
+
rubygems_version: 3.0.3
|
79
101
|
signing_key:
|
80
|
-
specification_version:
|
102
|
+
specification_version: 4
|
81
103
|
summary: This gem provides a simple interface to the Google Static Maps V2 API
|
82
|
-
test_files:
|
83
|
-
- spec/spec_helper.rb
|
84
|
-
- spec/marker_spec.rb
|
85
|
-
- spec/google_static_maps_helper_spec.rb
|
86
|
-
- spec/location_spec.rb
|
87
|
-
- spec/map_spec.rb
|
88
|
-
- spec/path_spec.rb
|
104
|
+
test_files: []
|