Class: StaticGmaps::Map
- Inherits:
-
Object
- Object
- StaticGmaps::Map
- Defined in:
- lib/static_gmaps.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
Returns the value of attribute center.
-
#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.
-
#size ⇒ Object
Returns the value of attribute size.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(options = {}) ⇒ Map
constructor
A new instance of Map.
- #markers_url_fragment ⇒ Object
- #to_blob ⇒ Object
- #url ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Map
Returns a new instance of Map.
70 71 72 73 74 75 76 77 |
# File 'lib/static_gmaps.rb', line 70 def initialize( = {}) 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.key = [:key] || StaticGmaps::default_key self.markers = [:markers] || [ ] end |
Instance Attribute Details
#center ⇒ Object
Returns the value of attribute center.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def center @center end |
#key ⇒ Object
Returns the value of attribute key.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def key @key end |
#map_type ⇒ Object
Returns the value of attribute map_type.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def map_type @map_type end |
#markers ⇒ Object
Returns the value of attribute markers.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def markers @markers end |
#size ⇒ Object
Returns the value of attribute size.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def size @size end |
#zoom ⇒ Object
Returns the value of attribute zoom.
63 64 65 |
# File 'lib/static_gmaps.rb', line 63 def zoom @zoom end |
Instance Method Details
#height ⇒ Object
83 84 85 |
# File 'lib/static_gmaps.rb', line 83 def height size[1] end |
#markers_url_fragment ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/static_gmaps.rb', line 116 def markers_url_fragment if markers && markers.any? return markers.collect{|marker| marker.url_fragment }.join('|') else return nil end end |
#to_blob ⇒ Object
124 125 126 127 |
# File 'lib/static_gmaps.rb', line 124 def to_blob fetch return @blob end |
#url ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/static_gmaps.rb', line 88 def url raise MissingArgument.new("Size must be set before a url can be generated for Map.") if !size || !size[0] || !size[1] raise MissingArgument.new("Key must be set before a url can be generated for Map.") if !key if(!self.center && !(markers && markers.size >= 1)) self.center = StaticGmaps::default_center end if !(markers && markers.size >= 1) raise MissingArgument.new("Center must be set before a url can be generated for Map (or multiple markers can be specified).") if !center raise MissingArgument.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}" parameters[:map_type] = "#{map_type}" if map_type parameters[:center] = "#{center[0]},#{center[1]}" if center parameters[:zoom] = "#{zoom}" if zoom parameters[:markers] = "#{markers_url_fragment}" if markers_url_fragment 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 = "http://maps.google.com/staticmap?#{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
79 80 81 |
# File 'lib/static_gmaps.rb', line 79 def width size[0] end |