Class: StaticGmaps::Map
- Inherits:
-
Object
- Object
- StaticGmaps::Map
- Defined in:
- lib/static_gmaps2.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#key ⇒ Object
Returns the value of attribute key.
-
#map_type ⇒ Object
Returns the value of attribute map_type.
-
#markers ⇒ Object
Returns the value of attribute markers.
-
#sensor ⇒ Object
Returns the value of attribute sensor.
-
#size ⇒ Object
Returns the value of attribute size.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
- #center ⇒ Object
- #center=(array_or_string) ⇒ Object
- #height ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Map
constructor
A new instance of Map.
- #markers_url_fragment ⇒ Object
- #to_blob ⇒ Object
- #url ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Map
Returns a new instance of Map.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/static_gmaps2.rb', line 53 def initialize( = {}, &block) self.center = [:center] self.zoom = [:zoom] || StaticGmaps::default_zoom self.size = [:size] || StaticGmaps::default_size self.map_type = [:map_type] || StaticGmaps::default_map_type self.sensor = [:sensor] || false self.key = [:key] self.format = [:format] self.markers = [:markers] || [ ] yield self if block_given? end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def format @format end |
#key ⇒ Object
Returns the value of attribute key.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def key @key end |
#map_type ⇒ Object
Returns the value of attribute map_type.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def map_type @map_type end |
#markers ⇒ Object
Returns the value of attribute markers.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def markers @markers end |
#sensor ⇒ Object
Returns the value of attribute sensor.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def sensor @sensor end |
#size ⇒ Object
Returns the value of attribute size.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def size @size end |
#zoom ⇒ Object
Returns the value of attribute zoom.
45 46 47 |
# File 'lib/static_gmaps2.rb', line 45 def zoom @zoom end |
Instance Method Details
#center ⇒ Object
77 78 79 |
# File 'lib/static_gmaps2.rb', line 77 def center @center ? @center.value : nil end |
#center=(array_or_string) ⇒ Object
73 74 75 |
# File 'lib/static_gmaps2.rb', line 73 def center=(array_or_string) @center = Location.new(array_or_string) end |
#height ⇒ Object
69 70 71 |
# File 'lib/static_gmaps2.rb', line 69 def height size[1] end |
#markers_url_fragment ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/static_gmaps2.rb', line 111 def markers_url_fragment if markers && markers.any? return markers.collect{|marker| marker.url_fragment }.join('&markers=') else return nil end end |
#to_blob ⇒ Object
119 120 121 122 |
# File 'lib/static_gmaps2.rb', line 119 def to_blob fetch return @blob end |
#url ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/static_gmaps2.rb', line 82 def url raise ArgumentError.new("Size must be set before a url can be generated for Map.") if !size || !size[0] || !size[1] if(!self.center && !(markers && markers.size >= 1)) self.center = StaticGmaps::default_center end if !(markers && markers.size >= 1) raise ArgumentError.new("Center must be set before a url can be generated for Map (or multiple markers can be specified).") if !center raise ArgumentError.new("Zoom must be set before a url can be generated for Map (or multiple markers can be specified).") if !zoom end raise "Google will not display more than #{StaticGmaps::maximum_markers} markers." if markers && markers.size > StaticGmaps::maximum_markers parameters = {} parameters[:size] = "#{size[0]}x#{size[1]}" parameters[:key] = "#{key}" if key parameters[:map_type] = "#{map_type}" if map_type parameters[:center] = "#{@center.to_s}" if center parameters[:zoom] = "#{zoom}" if zoom parameters[:markers] = "#{markers_url_fragment}" if markers_url_fragment parameters[:sensor] = "#{sensor}" parameters[:format] = "#{format}" if format parameters = parameters.to_a.sort { |a, b| a[0].to_s <=> b[0].to_s } parameters = parameters.collect { |parameter| "#{parameter[0]}=#{parameter[1]}" } parameters = parameters.join '&' x = "#{StaticGmaps.base_uri}?#{parameters}" raise "Google doesn't like the url to be longer than #{StaticGmaps::maximum_url_size} characters. Try fewer or less precise markers." if x.size > StaticGmaps::maximum_url_size return x end |
#width ⇒ Object
65 66 67 |
# File 'lib/static_gmaps2.rb', line 65 def width size[0] end |