class GoogleStaticMapsHelper::Marker
A marker object is representing a marker with a customizable label, color and size.
Constants
- DEFAULT_OPTIONS
Attributes
location[RW]
Public Class Methods
new(location_object_or_options, *args)
click to toggle source
Creates a new Marker
object. A marker object will, when added to a Map
, represent one marker which you can customize with color, size and label.
:location_object_or_options
-
Either an object which responds to lat and lng or simply a option hash
:args
-
A hash of options. Can have keys like
:color
,:size
, and:label
. See Google's API documentation for more information. If a location object hasn't been given you must also include:lat
and:lng
values.
Usage:
# Sets location via object which responds to lng and lat GoogleStaticMapsHelper::Marker.new(location {:label => :a}) # ..or include the lng and lat in the option hash GoogleStaticMapsHelper::Marker.new(:lng => 1, :lat => 2, :label => :a)
# File lib/google_static_maps_helper/marker.rb, line 38 def initialize(*args) raise ArgumentError, "Must have one or two arguments." if args.length == 0 extract_location!(args) options = DEFAULT_OPTIONS.merge(args.shift || {}) validate_options(options) options.each_pair { |k, v| send("#{k}=", v) } end
Public Instance Methods
has_icon?()
click to toggle source
# File lib/google_static_maps_helper/marker.rb, line 78 def has_icon? !!@icon end
method_missing(method, *args)
click to toggle source
Proxies calls to the internal object which keeps track of this marker's location. So, if @location responds to method missing in this object, it will respond to it.
Calls superclass method
# File lib/google_static_maps_helper/marker.rb, line 87 def method_missing(method, *args) return @location.send(method, *args) if @location.respond_to? method super end
Private Instance Methods
extract_location!(args)
click to toggle source
# File lib/google_static_maps_helper/marker.rb, line 93 def extract_location!(args) @location = Location.new(*args) args.shift unless args.first.is_a? Hash end
shadow_to_be_used_in_param()
click to toggle source
# File lib/google_static_maps_helper/marker.rb, line 111 def shadow_to_be_used_in_param return nil unless has_icon? shadow end
validate_options(options)
click to toggle source
# File lib/google_static_maps_helper/marker.rb, line 98 def validate_options(options) invalid_options = options.keys - DEFAULT_OPTIONS.keys raise OptionNotExist, "The following options does not exist: #{invalid_options.join(', ')}" unless invalid_options.empty? end