lib/ProMotion/map/map_screen_annotation.rb in ProMotion-mapbox-0.1.3 vs lib/ProMotion/map/map_screen_annotation.rb in ProMotion-mapbox-0.2.0
- old
+ new
@@ -1,49 +1,37 @@
module ProMotion
- class MapScreenAnnotation < RMAnnotation
+ class MapScreenAnnotation
attr_reader :params
- def initialize(params = {},map_view)
+ # Creates the new annotation object
+ def initialize(params = {})
@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
-
+
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
+ @params = {
+ title: "Title",
+ pin_color: :red,
+ identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
+ show_callout: true,
+ animates_drop: false,
+ image: nil,
+ left_accessory: nil,
+ right_accessory: nil,
+ }.merge(@params)
end
def title
@params[:title]
end
@@ -53,44 +41,43 @@
end
def coordinate
@coordinate
end
-
- def pin_color
- @params[:pin_color]
+
+ def left_accessory
+ @params[:left_accessory]
end
+ def right_accessory
+ @params[:right_accessory]
+ end
+
def cllocation
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
end
- def setCoordinate(new_coordinate)
- super
+ 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
-
- 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
-
+
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
+
+ # Deprecated
+ def annotation_params
+ PM.logger.warn("annotation.annotation_params is deprecated and will be removed soon. Please use annotation.params instead.")
+ @params
end
end
end