Class: ProMotion::MapScreenAnnotation

Inherits:
Object
  • Object
show all
Defined in:
lib/ProMotion/map/map_screen_annotation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ MapScreenAnnotation

Creates the new annotation object



6
7
8
9
10
11
12
13
14
15
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 6

def initialize(params = {})
  @params = params
  set_defaults

  unless @params[:latitude] && @params[:longitude]
    PM.logger.error("You are required to specify :latitude and :longitude for annotations.")
    return nil
  end
  @coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 51

def method_missing(meth, *args)
  if @params[meth.to_sym]
    @params[meth.to_sym]
  else
    PM.logger.warn "The annotation parameter \"#{meth}\" does not exist on this pin."
    nil
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 3

def params
  @params
end

Instance Method Details

#annotation_paramsObject

Deprecated



61
62
63
64
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 61

def annotation_params
  PM.logger.warn("annotation.annotation_params is deprecated and will be removed soon. Please use annotation.params instead.")
  @params
end

#cllocationObject



39
40
41
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 39

def cllocation
  CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
end

#coordinateObject



35
36
37
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 35

def coordinate
  @coordinate
end

#set_defaultsObject



17
18
19
20
21
22
23
24
25
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 17

def set_defaults
  @params = {
    title: "Title",
    pin_color: MKPinAnnotationColorRed,
    identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
    show_callout: true,
    animates_drop: false
  }.merge(@params)
end

#setCoordinate(new_coordinate) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 43

def setCoordinate(new_coordinate);
  if new_coordinate.is_a? Hash
    @coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
  else
    @coordinate = new_coordinate
  end
end

#subtitleObject



31
32
33
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 31

def subtitle
  @params[:subtitle] ||= nil
end

#titleObject



27
28
29
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 27

def title
  @params[:title]
end