googlestaticmap 1.2.4 → 1.2.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.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/README.md +1 -1
- data/lib/googlestaticmap.rb +25 -1
- data/test/tc_google_static_map.rb +33 -0
- data/test/tc_map_marker.rb +4 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5b6fcba846462e64275c8edcedc7e4b42d85de
|
4
|
+
data.tar.gz: 1d921c206a737b39936ce5668767a939e228e019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a93b1e16dc3779d1465f43ec6d79c76dcdf0ed4a51eaca0a7c5a8d35a434c944e602bbd5be6b80fab97a63e7b136d238cedcf2010bd498f003a909c8f833f56
|
7
|
+
data.tar.gz: f7aa37ed92164ea33e8be0437d817c3908d7250c0358dedc4b30b16dddc8986558a6998e6655a72fa105d4147a227d044087907b8177f095e4ccb61472b499f5
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ this URL as the src of an img element on an HTML page
|
|
30
30
|
When using the url function you can force the final url to use http or https:
|
31
31
|
|
32
32
|
image_url = map.url('http')
|
33
|
-
|
33
|
+
|
34
34
|
Get a map with blue markers at the White House and the Supreme Court, zoomed
|
35
35
|
the closest that the map can be with both markers visible, at the default
|
36
36
|
size. image will be the binary data of the map
|
data/lib/googlestaticmap.rb
CHANGED
@@ -87,6 +87,16 @@ class GoogleStaticMap
|
|
87
87
|
# see https://developers.google.com/maps/documentation/static-maps/intro for details
|
88
88
|
attr_accessor :language
|
89
89
|
|
90
|
+
# Styles - see https://developers.google.com/maps/documentation/maps-static/styling
|
91
|
+
# styles is should be represented as array of objects
|
92
|
+
# [{feature: 'featureArgument, element: 'elementArgument', rule1: 'rule1Arguement', rule2: 'rule2Arguement', ...},
|
93
|
+
# ...]
|
94
|
+
attr_accessor :styles
|
95
|
+
|
96
|
+
# In case when some parameter should be inserted manually
|
97
|
+
# For example, using https://mapstyle.withgoogle.com/ tool and inserting generated style as is
|
98
|
+
attr_accessor :plain_string
|
99
|
+
|
90
100
|
# Takes an optional hash of attributes
|
91
101
|
def initialize(attrs={})
|
92
102
|
defaults = {:width => 500, :height => 350, :markers => [],
|
@@ -123,7 +133,7 @@ class GoogleStaticMap
|
|
123
133
|
attrs = GoogleStaticMapHelpers.safe_instance_variables(self,
|
124
134
|
["markers", "paths", "width", "height", "center",
|
125
135
|
"proxy_address", "proxy_port", "api_key", "client_id",
|
126
|
-
"private_key"],
|
136
|
+
"private_key", "styles", "plain_string"],
|
127
137
|
:cgi_escape_values => true).to_a
|
128
138
|
attrs << ["size", "#{@width}x#{@height}"] if @width && @height
|
129
139
|
@markers.each {|m| attrs << ["markers",m.to_s] }
|
@@ -131,7 +141,9 @@ class GoogleStaticMap
|
|
131
141
|
attrs << ["center", @center.to_s] if !@center.nil?
|
132
142
|
attrs << ["key", @api_key] if !@api_key.nil?
|
133
143
|
attrs << ["client", @client_id] if !@client_id.nil?
|
144
|
+
get_styles.each { |style| attrs << style } if !@styles.nil?
|
134
145
|
path << attrs.sort_by {|k,v| k}.collect {|attr| "#{attr[0]}=#{attr[1]}"}.join("&")
|
146
|
+
path << "&#{@plain_string}" if !@plain_string.nil?
|
135
147
|
if (!@api_key.nil? || !@client_id.nil?) && !@private_key.nil?
|
136
148
|
signature = GoogleStaticMapHelpers.sign(path, @private_key)
|
137
149
|
path << "&signature=" << signature
|
@@ -175,6 +187,14 @@ class GoogleStaticMap
|
|
175
187
|
end
|
176
188
|
end
|
177
189
|
|
190
|
+
def get_styles
|
191
|
+
@styles.map do |style|
|
192
|
+
values = style.each_pair.map do |(key, value)|
|
193
|
+
"#{key.to_s}:#{value}"
|
194
|
+
end
|
195
|
+
["style", values.join(CGI.escape('|'))]
|
196
|
+
end
|
197
|
+
end
|
178
198
|
end
|
179
199
|
|
180
200
|
# Container class for a location on the map. Set either a latitude and
|
@@ -231,6 +251,10 @@ class MapMarker
|
|
231
251
|
# visible region and its opacity/transparency.
|
232
252
|
attr_accessor :shadow
|
233
253
|
|
254
|
+
# Manage position of marker (anchor:center/bottom/top..)
|
255
|
+
# See - https://developers.google.com/maps/documentation/maps-static/intro#Markers
|
256
|
+
attr_accessor :anchor
|
257
|
+
|
234
258
|
# Takes an optional hash of attributes
|
235
259
|
def initialize(attrs={})
|
236
260
|
attrs.each {|k,v| self.send("#{k}=".to_sym,v)}
|
@@ -117,6 +117,39 @@ class GoogleStaticMapTest < Test::Unit::TestCase #:nodoc: all
|
|
117
117
|
assert_no_match /^https:\/\/maps.googleapis.com/, f
|
118
118
|
end
|
119
119
|
|
120
|
+
def test_url_styles
|
121
|
+
g = default_map
|
122
|
+
g.styles = [
|
123
|
+
{ feature: 'road.local', element: 'geometry', color: '0x00ff00' },
|
124
|
+
{ feature: 'landscape', element: 'geometry.fill', color: '0x000000' },
|
125
|
+
{ element: 'labels', invert_lightness: true },
|
126
|
+
{ feature: 'road.arterial', element: 'labels', invert_lightness: false }
|
127
|
+
]
|
128
|
+
u = nil
|
129
|
+
|
130
|
+
assert_nothing_raised { u = g.url }
|
131
|
+
assert_equal 11, u.split("&").length, u
|
132
|
+
assert !u.include?("styles"), "styles have to be convered to array of 'style'"
|
133
|
+
assert u.include?('style=feature:road.local%7Celement:geometry%7Ccolor:0x00ff00'), u
|
134
|
+
assert u.include?('style=feature:landscape%7Celement:geometry.fill%7Ccolor:0x000000'), u
|
135
|
+
assert u.include?('style=element:labels%7Cinvert_lightness:true&style=feature:road.arterial%7Celement:labels%7Cinvert_lightness:false'), u
|
136
|
+
|
137
|
+
assert_nothing_raised {g.relative_url}
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_url_plain_string
|
141
|
+
g = default_map
|
142
|
+
g.plain_string = "style=feature:road.local%7Celement:geometry%7Ccolor:0x00ff00&style=feature:landscape%7Celement:geometry.fill%7Ccolor:0x000000"
|
143
|
+
u = nil
|
144
|
+
|
145
|
+
assert_nothing_raised { u = g.url }
|
146
|
+
assert_equal 9, u.split("&").length, u
|
147
|
+
assert !u.include?("plain_string")
|
148
|
+
assert u.include?('&style=feature:road.local%7Celement:geometry%7Ccolor:0x00ff00&style=feature:landscape%7Celement:geometry.fill%7Ccolor:0x000000')
|
149
|
+
|
150
|
+
assert_nothing_raised {g.relative_url}
|
151
|
+
end
|
152
|
+
|
120
153
|
def test_url_api_key
|
121
154
|
g = default_map
|
122
155
|
g.api_key = "asdfapikey"
|
data/test/tc_map_marker.rb
CHANGED
@@ -27,16 +27,18 @@ class MapMarkerTest < Test::Unit::TestCase #:nodoc: all
|
|
27
27
|
assert_equal "B", m.label
|
28
28
|
assert_equal "http://www.google.com", m.icon
|
29
29
|
assert_equal false, m.shadow
|
30
|
+
assert_equal 'center', m.anchor
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_get_string
|
33
34
|
m = default_marker
|
34
35
|
s = nil
|
35
36
|
assert_nothing_raised {s = m.to_s}
|
36
|
-
assert_equal
|
37
|
+
assert_equal 7, s.split(MAP_SEPARATOR).length
|
37
38
|
assert s.include?(CGI.escape("Washington, DC"))
|
38
39
|
assert s.include?("color:green")
|
39
40
|
assert s.include?("icon:http://www.google.com")
|
41
|
+
assert s.include?("anchor:center")
|
40
42
|
end
|
41
43
|
|
42
44
|
def test_string_is_a_valid_ruby_uri
|
@@ -51,6 +53,7 @@ class MapMarkerTest < Test::Unit::TestCase #:nodoc: all
|
|
51
53
|
:size => "tiny",
|
52
54
|
:label => "B",
|
53
55
|
:icon => "http://www.google.com",
|
56
|
+
:anchor => 'center',
|
54
57
|
:shadow => false)
|
55
58
|
end
|
56
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googlestaticmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Sowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -92,13 +92,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.8
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Class for retrieving maps from the Google Maps Static API service
|
99
99
|
test_files:
|
100
100
|
- test/tc_map_path_and_polygon.rb
|
101
|
-
- test/tc_helper.rb
|
102
|
-
- test/tc_google_static_map.rb
|
103
101
|
- test/tc_map_location.rb
|
102
|
+
- test/tc_google_static_map.rb
|
103
|
+
- test/tc_helper.rb
|
104
104
|
- test/tc_map_marker.rb
|