这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ProMotion/map/map_screen_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/ProMotion/map/map_screen_module.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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]
Expand Down
29 changes: 29 additions & 0 deletions spec/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down