Class: Cartographie::Map
- Inherits:
-
Object
- Object
- Cartographie::Map
- Defined in:
- lib/cartographie/map.rb
Overview
Map represents a map, and contains the details regarding a map’s dimensions, zoom level, the image file format, and whether a GPS sensor was used in determining the map’s location.
Instance Attribute Summary collapse
-
#location ⇒ Object
Public: Gets/Sets the String location of the map.
-
#options ⇒ Object
Public: Gets/Sets the Hash options for the map.
Instance Method Summary collapse
- #api_endpoint ⇒ Object
-
#file_format ⇒ Object
Returns the String file format passed in options, or default.
-
#height ⇒ Object
Returns the Integer height passed in options, or default.
-
#initialize(location = 'Paris, France', options = {}) ⇒ Map
constructor
Public: Initialize a Map.
-
#sensor ⇒ Object
Returns the Boolean indicating sensor usage passed in options, or default.
-
#size ⇒ Object
Returns a string combining width and height into dimensions.
-
#uri ⇒ Object
(also: #to_s)
Public: Build a Google Static Maps image URI.
-
#width ⇒ Object
Returns the Integer width passed in options, or default.
-
#zoom ⇒ Object
Returns the Integer zoom level passed in options, or default.
Constructor Details
#initialize(location = 'Paris, France', options = {}) ⇒ Map
Public: Initialize a Map
location - The String for the map’s location (default: ‘Paris, France’). options - The Hash options used to configure the map (default: {}):
:width - The Integer width of the map (optional).
:height - The Integer height of the map (optional).
:zoom - The Integer zoom level (optional).
:file_format - The String file format for the image (optional).
:sensor - The Boolean indicating GPS usage (optional).
Examples
Cartographie::Map.new('San Francisco, CA', zoom: 10)
27 28 29 30 |
# File 'lib/cartographie/map.rb', line 27 def initialize(location='Paris, France', ={}) self.location = location self. = end |
Instance Attribute Details
#location ⇒ Object
Public: Gets/Sets the String location of the map.
10 11 12 |
# File 'lib/cartographie/map.rb', line 10 def location @location end |
#options ⇒ Object
Public: Gets/Sets the Hash options for the map.
12 13 14 |
# File 'lib/cartographie/map.rb', line 12 def @options end |
Instance Method Details
#api_endpoint ⇒ Object
79 80 81 |
# File 'lib/cartographie/map.rb', line 79 def api_endpoint [:api_endpoint] || Config.api_endpoint end |
#file_format ⇒ Object
Returns the String file format passed in options, or default
65 66 67 |
# File 'lib/cartographie/map.rb', line 65 def file_format [:file_format] || Config.file_format end |
#height ⇒ Object
Returns the Integer height passed in options, or default
55 56 57 |
# File 'lib/cartographie/map.rb', line 55 def height [:height] || Config.height end |
#sensor ⇒ Object
Returns the Boolean indicating sensor usage passed in options, or default
70 71 72 |
# File 'lib/cartographie/map.rb', line 70 def sensor [:sensor] || Config.sensor end |
#size ⇒ Object
Returns a string combining width and height into dimensions
75 76 77 |
# File 'lib/cartographie/map.rb', line 75 def size "#{width}x#{height}" end |
#uri ⇒ Object Also known as: to_s
Public: Build a Google Static Maps image URI
Returns the String URI pointing an image of the map
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cartographie/map.rb', line 35 def uri params = { center: location, size: size, zoom: zoom, format: file_format, sensor: sensor.to_s } Addressable::URI.parse(api_endpoint).tap do |uri| uri.query_values = params end.to_s end |