Class: StaticMap

Inherits:
Object
  • Object
show all
Defined in:
lib/mapbox/static_map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute api_id.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def api_id
  @api_id
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def height
  @height
end

#latitudeObject

Returns the value of attribute latitude.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def longitude
  @longitude
end

#markersObject

Returns the value of attribute markers.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def markers
  @markers
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/mapbox/static_map.rb', line 3

def width
  @width
end

#zoomObject

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_idObject

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_pathObject



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

#latObject



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

#lonObject



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_stringObject

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_sObject

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