class StaticMap
Attributes
api_id[RW]
height[RW]
latitude[RW]
longitude[RW]
markers[RW]
width[RW]
zoom[RW]
Public Class Methods
api_id()
click to toggle source
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
# File lib/mapbox/static_map.rb, line 74 def self.api_id @@api_id ||= ENV["MAPBOX_API_ID"] end
api_id=(api_id)
click to toggle source
# File lib/mapbox/static_map.rb, line 78 def self.api_id=(api_id) @@api_id = api_id end
api_path()
click to toggle source
# 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)
click to toggle source
# File lib/mapbox/static_map.rb, line 86 def self.api_path=(api_path) @@api_path = api_path end
new(latitude, longitude, zoom, width=640, height=480, api_id=nil, markers=nil)
click to toggle source
# 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
Public Instance Methods
<<(marker)
click to toggle source
# File lib/mapbox/static_map.rb, line 61 def <<(marker) self.markers << marker end
add_marker(marker)
click to toggle source
# File lib/mapbox/static_map.rb, line 57 def add_marker(marker) self.markers << marker end
api_id=(api_id)
click to toggle source
# File lib/mapbox/static_map.rb, line 49 def api_id=(api_id) @api_id = MapboxUtils.validate_api_id(api_id) end
lat()
click to toggle source
# File lib/mapbox/static_map.rb, line 21 def lat self.latitude end
lat=(latitude)
click to toggle source
# File lib/mapbox/static_map.rb, line 29 def lat=(latitude) self.latitude = latitude end
latitude=(latitude)
click to toggle source
# File lib/mapbox/static_map.rb, line 37 def latitude=(latitude) @latitude = MapboxUtils.validate_latitude(latitude) end
lon()
click to toggle source
# File lib/mapbox/static_map.rb, line 25 def lon self.longitude end
lon=(longitude)
click to toggle source
# File lib/mapbox/static_map.rb, line 33 def lon=(longitude) self.longitude = longitude end
longitude=(longitude)
click to toggle source
# File lib/mapbox/static_map.rb, line 41 def longitude=(longitude) @longitude = MapboxUtils.validate_longitude(longitude) end
marker_string()
click to toggle source
make the string from the markers
# 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()
click to toggle source
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
# 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
zoom=(zoom)
click to toggle source
# File lib/mapbox/static_map.rb, line 45 def zoom=(zoom) @zoom = MapboxUtils.validate_zoom(zoom) end