Class: StaticMap
- Inherits:
-
Object
- Object
- StaticMap
- Defined in:
- lib/mapbox/static_map.rb
Instance Attribute Summary collapse
-
#api_id ⇒ Object
Returns the value of attribute api_id.
-
#height ⇒ Object
Returns the value of attribute height.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#markers ⇒ Object
Returns the value of attribute markers.
-
#width ⇒ Object
Returns the value of attribute width.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Class Method Summary collapse
-
.api_id ⇒ Object
Allow the user to class level configure the API ID defaults to reading MAPBOX_API_ID so that you can use this in a very simple fashion with services like heroku.
- .api_id=(api_id) ⇒ Object
- .api_path ⇒ Object
- .api_path=(api_path) ⇒ Object
Instance Method Summary collapse
- #<<(marker) ⇒ Object
- #add_marker(marker) ⇒ Object
-
#initialize(latitude, longitude, zoom, width = 640, height = 480, api_id = nil, markers = nil) ⇒ StaticMap
constructor
A new instance of StaticMap.
- #lat ⇒ Object
- #lat=(latitude) ⇒ Object
- #lon ⇒ Object
- #lon=(longitude) ⇒ Object
-
#marker_string ⇒ Object
make the string from the markers.
-
#to_s ⇒ Object
api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/400x300.png api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png.
Constructor Details
#initialize(latitude, longitude, zoom, width = 640, height = 480, api_id = nil, markers = nil) ⇒ StaticMap
Returns a new instance of StaticMap.
5 6 7 8 9 10 11 12 13 |
# File 'lib/mapbox/static_map.rb', line 5 def initialize(latitude, longitude, zoom, width=640, height=480, api_id=nil, markers=nil) self.latitude = latitude self.longitude = longitude self.zoom = zoom self.width = width self.height = height self.api_id = api_id || StaticMap.api_id self.markers = markers || [] end |
Instance Attribute Details
#api_id ⇒ Object
Returns the value of attribute api_id.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def api_id @api_id end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def height @height end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def longitude @longitude end |
#markers ⇒ Object
Returns the value of attribute markers.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def markers @markers end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def width @width end |
#zoom ⇒ Object
Returns the value of attribute zoom.
3 4 5 |
# File 'lib/mapbox/static_map.rb', line 3 def zoom @zoom end |
Class Method Details
.api_id ⇒ Object
Allow the user to class level configure the API ID defaults to reading MAPBOX_API_ID so that you can use this in a very simple fashion with services like heroku
74 75 76 |
# File 'lib/mapbox/static_map.rb', line 74 def self.api_id @@api_id ||= ENV["MAPBOX_API_ID"] end |
.api_id=(api_id) ⇒ Object
78 79 80 |
# File 'lib/mapbox/static_map.rb', line 78 def self.api_id=(api_id) @@api_id = api_id end |
.api_path ⇒ Object
82 83 84 |
# File 'lib/mapbox/static_map.rb', line 82 def self.api_path @@api_path ||= (ENV["MAPBOX_API_PATH"] || "api.tiles.mapbox.com/v3") end |
.api_path=(api_path) ⇒ Object
86 87 88 |
# File 'lib/mapbox/static_map.rb', line 86 def self.api_path=(api_path) @@api_path = api_path end |
Instance Method Details
#<<(marker) ⇒ Object
61 62 63 |
# File 'lib/mapbox/static_map.rb', line 61 def <<(marker) self.markers << marker end |
#add_marker(marker) ⇒ Object
57 58 59 |
# File 'lib/mapbox/static_map.rb', line 57 def add_marker(marker) self.markers << marker end |
#lat ⇒ Object
21 22 23 |
# File 'lib/mapbox/static_map.rb', line 21 def lat self.latitude end |
#lat=(latitude) ⇒ Object
29 30 31 |
# File 'lib/mapbox/static_map.rb', line 29 def lat=(latitude) self.latitude = latitude end |
#lon ⇒ Object
25 26 27 |
# File 'lib/mapbox/static_map.rb', line 25 def lon self.longitude end |
#lon=(longitude) ⇒ Object
33 34 35 |
# File 'lib/mapbox/static_map.rb', line 33 def lon=(longitude) self.longitude = longitude end |
#marker_string ⇒ Object
make the string from the markers
66 67 68 |
# File 'lib/mapbox/static_map.rb', line 66 def marker_string markers.each.map{|marker| marker.to_s}.join(",") + "/" unless markers.nil? || markers.length == 0 end |
#to_s ⇒ Object
api.tiles.mapbox.com/v3/examples.map-4l7djmvo/-77.04,38.89,13/400x300.png api.tiles.mapbox.com/v3/examples.map-4l7djmvo/pin-m-monument(-77.04,38.89)/-77.04,38.89,13/400x300.png
17 18 19 |
# File 'lib/mapbox/static_map.rb', line 17 def to_s "#{StaticMap.api_path}/#{self.api_id}/#{marker_string}#{lon},#{lat},#{zoom}/#{width}x#{height}.png" end |