Class: ProMotion::MapScreenAnnotation

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

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ MapScreenAnnotation

Creates the new annotation object



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

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



55
56
57
58
59
60
61
62
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 55

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 Method Details

#annotation_paramsObject

Allows for retrieving your own custom values on the annotation



51
52
53
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 51

def annotation_params
  @params
end

#cllocationObject



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

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

#coordinateObject



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

def coordinate
  @coordinate
end

#set_defaultsObject



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

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



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

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



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

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

#titleObject



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

def title
  @params[:title]
end