这是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
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class MyMapScreen < PM::MapScreen
your_param: "CustomWhatever",
action: :show_forest
}, {
longitude: -82.965972900391,
latitude: 35.090648651123,
coordinate: CLLocationCoordinate2DMake(35.090648651123, -82.965972900391)
title: "Rainbow Falls",
subtitle: "Nantahala National Forest",
image: UIImage.imageNamed("custom-pin"),
Expand Down Expand Up @@ -91,8 +90,13 @@ All possible properties:

```ruby
{
longitude: -82.956244328014, # REQUIRED
latitude: 35.085548421623, # REQUIRED
# REQUIRED -or- use :coordinate
longitude: -82.956244328014,
latitude: 35.085548421623,

# REQUIRED -or- use :longitude & :latitude
coordinate: CLLocationCoordinate2DMake(35.085548421623, -82.956244328014)

title: "Stairway Falls", # REQUIRED
subtitle: "Gorges State Park",
image: "my_custom_image",
Expand All @@ -103,7 +107,7 @@ All possible properties:
}
```

You may pass whatever properties you want in the annotation hash, but `:longitude`, `:latitude`, and `:title` are required.
You may pass whatever properties you want in the annotation hash, but (`:longitude` && `:latitude` || `:coordinate`), and `:title` are required.

Use `:image` to specify a custom image. Pass in a string to conserve memory and it will be converted using `UIImage.imageNamed(your_string)`. If you pass in a `UIImage`, we'll use that, but keep in mind that there will be another unnecessary copy of the UIImage in memory.

Expand Down
4 changes: 2 additions & 2 deletions app/test_screens/test_map_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def annotation_data
title: "Rainbow Falls",
subtitle: "Nantahala National Forest",
},{
longitude: -82.966093558105,
latitude: 35.092520895652,
# Example of using :coordinate instead of :latitude & :longitude
coordinate: CLLocationCoordinate2DMake(35.092520895652, -82.966093558105),
title: "Turtleback Falls",
subtitle: "Nantahala National Forest",
},{
Expand Down
13 changes: 9 additions & 4 deletions lib/ProMotion/map/map_screen_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ 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
if @params[:coordinate]
@params[:latitude] = @params[:coordinate].latitude
@params[:longitude] = @params[:coordinate].longitude
@coordinate = @params[:coordinate]
elsif @params[:latitude] && @params[:longitude]
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
else
PM.logger.error("You are required to specify :latitude and :longitude or :coordinate for annotations.")
nil
end
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
end

def set_defaults
Expand Down
11 changes: 10 additions & 1 deletion spec/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
@map.annotations.count.should == 6
end

it "should add an annotation with a coordinate" do
ann = {
coordinate: CLLocationCoordinate2DMake(35.092520895652, -82.966093558105),
title: "A Coordinate"
}
@map.add_annotation(ann)
@map.annotations.count.should == 6
end

it "should return custom annotation parameters" do
ann = {
longitude: -82.966093558105,
Expand Down Expand Up @@ -73,7 +82,7 @@
it "should allow ruby counterparts to MKMapView to be used" do
@map.type.should == MKMapTypeStandard
@map.type = MKMapTypeHybrid
@map.type.should == MKMapTypeHybrid
@map.map.mapType.should == MKMapTypeHybrid

@map.zoom_enabled?.should == true
@map.zoom_enabled = false
Expand Down