Class: ProMotion::MapScreenAnnotation

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, map_view) ⇒ MapScreenAnnotation

Returns a new instance of MapScreenAnnotation.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 5

def initialize(params = {},map_view)
  @params = params
  @map_view = map_view
  set_defaults
  if @params[:coordinate]
    @params[:latitude] = @params[:coordinate].latitude
    @params[:longitude] = @params[:coordinate].longitude
    @coordinate = @params[:coordinate]
    initWithMapView(map_view, coordinate: @coordinate, andTitle: @params[:title])
  elsif @params[:latitude] && @params[:longitude]
    @coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
    initWithMapView(map_view, coordinate: @coordinate, andTitle: @params[:title])
  else
    PM.logger.error("You are required to specify :latitude and :longitude or :coordinate for annotations.")
    nil
  end
  self.userInfo = @params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 86

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

Class Method Details

.new_with_rmannotation(rmannotation, map_view) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 76

def self.new_with_rmannotation(rmannotation,map_view)
  annotation = self.new(rmannotation.userInfo, map_view)
  %w(coordinate title subtitle userInfo annotationType annotationIcon 
  position layer clusteringEnabled 
  isClusterAnnotation isUserLocationAnnotation).each do |meth|
    annotation.send("#{meth}=", rmannotation.send(meth))
  end
  annotation
end

Instance Method Details

#cllocationObject



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

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

#coordinateObject



55
56
57
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 55

def coordinate
  @coordinate
end

#pin_colorObject



59
60
61
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 59

def pin_color
  @params[:pin_color]
end

#set_defaultsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 24

def set_defaults
  if @params.class == Hash
    @params = {
      title: "Title",
      pin_color: :red,
      identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
      show_callout: true,
      animates_drop: false,
      maki_icon: nil,
    }.merge(@params)
  elsif  @params.class == RMQuadTreeNode # Clustered pins 
    @params = {
      title: @params.annotations.count,
      coordinate: @params.clusterAnnotation.coordinate,
      pin_color: :purple,
      identifier: "Annotation-cluster",
      show_callout: true,
      animates_drop: false,
      maki_icon: nil,
    }
  end
end

#setCoordinate(new_coordinate) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 67

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

#subtitleObject



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

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

#titleObject



47
48
49
# File 'lib/ProMotion/map/map_screen_annotation.rb', line 47

def title
  @params[:title]
end