Class: StaticGmaps::Marker

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Marker

Returns a new instance of Marker.

Yields:

  • (_self)

Yield Parameters:



145
146
147
148
149
150
151
152
153
154
# File 'lib/static_gmaps2.rb', line 145

def initialize(options = {}, &block)
  self.location        = options[:location]        || [StaticGmaps::default_latitude, StaticGmaps::default_longitude]
  self.label           = options[:label]           || StaticGmaps::default_alpha_character
  self.color           = options[:color]           || StaticGmaps::default_color
  # original api compatibility
  self.label           = options[:alpha_character] if options[:alpha_character]
  self.latitude        = options[:latitude]        if options[:latitude]
  self.longitude       = options[:longitude]       if options[:longitude]
  yield self if block_given?
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



139
140
141
# File 'lib/static_gmaps2.rb', line 139

def color
  @color
end

#iconObject

Returns the value of attribute icon.



139
140
141
# File 'lib/static_gmaps2.rb', line 139

def icon
  @icon
end

#labelObject

Returns the value of attribute label.



139
140
141
# File 'lib/static_gmaps2.rb', line 139

def label
  @label
end

#shadowObject (readonly)

Returns the value of attribute shadow.



139
140
141
# File 'lib/static_gmaps2.rb', line 139

def shadow
  @shadow
end

#sizeObject (readonly)

Returns the value of attribute size.



139
140
141
# File 'lib/static_gmaps2.rb', line 139

def size
  @size
end

Instance Method Details

#alpha_characterObject



221
222
223
# File 'lib/static_gmaps2.rb', line 221

def alpha_character
  self.label
end

#alpha_character=(value) ⇒ Object

for compatibility with original ruby api



217
218
219
# File 'lib/static_gmaps2.rb', line 217

def alpha_character=(value)
  self.label = value
end

#attributesObject



160
161
162
163
164
165
166
# File 'lib/static_gmaps2.rb', line 160

def attributes
  self.available_parameters.inject({}) do |store, parameter_name|
    value = self.send(parameter_name)
    store[parameter_name] = value if value
    store
  end
end

#available_parametersObject



156
157
158
# File 'lib/static_gmaps2.rb', line 156

def available_parameters
  [:location, :color, :label, :size, :icon, :shadow]
end

#latitudeObject



198
199
200
# File 'lib/static_gmaps2.rb', line 198

def latitude
  @location.value[0] if @location.value.is_a?(Array)
end

#latitude=(f) ⇒ Object



190
191
192
# File 'lib/static_gmaps2.rb', line 190

def latitude=(f)
  @location.value[0] = f
end

#locationObject



186
187
188
# File 'lib/static_gmaps2.rb', line 186

def location
  @location ? @location.value : nil
end

#location=(array_or_string) ⇒ Object



182
183
184
# File 'lib/static_gmaps2.rb', line 182

def location=(array_or_string)
  @location = Location.new(array_or_string)
end

#longitudeObject



202
203
204
# File 'lib/static_gmaps2.rb', line 202

def longitude
  @location.value[1] if @location.value.is_a?(Array)
end

#longitude=(f) ⇒ Object



194
195
196
# File 'lib/static_gmaps2.rb', line 194

def longitude=(f)
  @location.value[1] = f
end

#url_fragmentObject

Raises:

  • (ArgumentError)


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/static_gmaps2.rb', line 225

def url_fragment
  # markers=color:blue|label:S|62.107733,-145.541936&markers=size:tiny|color:green|Delta+Junction,AK
  raise ArgumentError.new("Location must be set before a url_fragment can be generated for Marker.") if !location
  marker_parameter_separator = "|"
  marker_value_separator = ":"
  location = @location.to_s
  str = ""
  attrs = self.attributes
  attrs.delete(:location)
  if !attrs.empty?
    str << attrs.map {|parameter, value| "#{parameter}#{marker_value_separator}#{value}"}.join(marker_parameter_separator)
    str << marker_parameter_separator
  end
  str << location
  str
end