diff --git a/README.md b/README.md index 96132b7..b4ab263 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,15 @@ class MyMapScreen < PM::MapScreen latitude: 35.090648651123, title: "Rainbow Falls", subtitle: "Nantahala National Forest", - action: :show_forest + action: :show_forest, + pin_color: :green },{ longitude: -82.966093558105, latitude: 35.092520895652, title: "Turtleback Falls", subtitle: "Nantahala National Forest", - action: :show_forest + action: :show_forest, + pin_color: MKPinAnnotationColorPurple },{ longitude: -82.95916, latitude: 35.07496, @@ -101,6 +103,7 @@ All possible properties: title: "Stairway Falls", # REQUIRED subtitle: "Gorges State Park", image: "my_custom_image", + pin_color: :red, # Defaults to :red. Other options are :green or :purple or any MKPinAnnotationColor left_accessory: my_button, right_accessory: my_other_button, action: :my_action, # Overrides :right_accessory diff --git a/lib/ProMotion/map/map_screen_annotation.rb b/lib/ProMotion/map/map_screen_annotation.rb index bed5c68..c1fb031 100644 --- a/lib/ProMotion/map/map_screen_annotation.rb +++ b/lib/ProMotion/map/map_screen_annotation.rb @@ -22,7 +22,7 @@ def initialize(params = {}) def set_defaults @params = { title: "Title", - pin_color: MKPinAnnotationColorRed, + pin_color: :red, identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}", show_callout: true, animates_drop: false diff --git a/lib/ProMotion/map/map_screen_module.rb b/lib/ProMotion/map/map_screen_module.rb index 07dd63b..847c224 100644 --- a/lib/ProMotion/map/map_screen_module.rb +++ b/lib/ProMotion/map/map_screen_module.rb @@ -1,6 +1,12 @@ module ProMotion module MapScreenModule + PIN_COLORS = { + red: MKPinAnnotationColorRed, + green: MKPinAnnotationColorGreen, + purple: MKPinAnnotationColorPurple + } + def screen_setup self.view = nil self.view = MKMapView.alloc.initWithFrame(self.view.bounds) @@ -139,7 +145,7 @@ def annotation_view(map_view, annotation) end view.image = params[:image] if view.respond_to?("image=") && params[:image] view.animatesDrop = params[:animates_drop] if view.respond_to?("animatesDrop=") - view.pinColor = params[:pin_color] if view.respond_to?("pinColor=") + view.pinColor = (PIN_COLORS[params[:pin_color]] || params[:pin_color]) if view.respond_to?("pinColor=") view.canShowCallout = params[:show_callout] if view.respond_to?("canShowCallout=") if params[:left_accessory] diff --git a/spec/map_spec.rb b/spec/map_spec.rb index 0b8ef96..a6fc299 100644 --- a/spec/map_spec.rb +++ b/spec/map_spec.rb @@ -20,6 +20,13 @@ end end + it "should have a default red colored pin" do + @map.annotations.each do |annotation| + annotation_view = @map.annotation_view(@map.mapview, annotation) + annotation_view.pinColor.should == MKPinAnnotationColorRed + end + end + it "should add an annotation" do ann = { longitude: -82.966093558105, @@ -30,6 +37,28 @@ @map.annotations.count.should == 6 end + it "should add an annotation with a different pin color symbol" do + ann = ProMotion::MapScreenAnnotation.new({ + longitude: -82.966993558105, + latitude: 35.092520495652, + title: "Green Pin", + pin_color: :green + }) + annotation_view = @map.annotation_view(@map.mapview, ann) + annotation_view.pinColor.should == MKPinAnnotationColorGreen + end + + it "should add an annotation with a different pin color constant" do + ann = ProMotion::MapScreenAnnotation.new({ + longitude: -82.966993558105, + latitude: 35.092520495652, + title: "Purple Pin", + pin_color: MKPinAnnotationColorPurple + }) + annotation_view = @map.annotation_view(@map.mapview, ann) + annotation_view.pinColor.should == MKPinAnnotationColorPurple + end + it "should add an annotation with a coordinate" do ann = { coordinate: CLLocationCoordinate2DMake(35.092520895652, -82.966093558105),