这是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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ Adds more than one annotation at a time to the map.

Removes all annotations from the `MapScreen`.

#### zoom_to_fit_annotations(animated=true)
#### zoom_to_fit_annotations({animated:true, include_user:false})

Changes the zoom and center point of the `MapScreen` to fit all the annotations.
Changes the zoom and center point of the `MapScreen` to fit all the annotations. Passing `include_user` as `true` will cause the zoom to not only include the annotations from `annotation_data` but also the user pin in the zoom region calculation.

#### set_region(region, animated=true)

Expand Down
22 changes: 16 additions & 6 deletions lib/ProMotion/map/map_screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def showing_user_location?
end

def user_location
self.view.userLocation.location.nil? ? nil : self.view.userLocation.location.coordinate
user_annotation.nil? ? nil : user_annotation.coordinate
end

def user_annotation
self.view.userLocation.location.nil? ? nil : self.view.userLocation.location
end

def zoom_to_user(radius = 0.05, animated=true)
Expand Down Expand Up @@ -174,16 +178,22 @@ def set_up_start_position
end

# TODO: Why is this so complex?
def zoom_to_fit_annotations(animated=true)
def zoom_to_fit_annotations(args={})
# Preserve backwards compatibility
args = {animated: args} if args == true || args == false
args = {animated: true, include_user: false}.merge(args)

ann = args[:include_user] ? (annotations + [user_annotation]).compact : annotations

#Don't attempt the rezoom of there are no pins
return if annotations.count == 0
return if ann.count == 0

#Set some crazy boundaries
topLeft = CLLocationCoordinate2D.new(-90, 180)
bottomRight = CLLocationCoordinate2D.new(90, -180)

#Find the bounds of the pins
annotations.each do |a|
ann.each do |a|
topLeft.longitude = [topLeft.longitude, a.coordinate.longitude].min
topLeft.latitude = [topLeft.latitude, a.coordinate.latitude].max
bottomRight.longitude = [bottomRight.longitude, a.coordinate.longitude].max
Expand All @@ -203,9 +213,9 @@ def zoom_to_fit_annotations(animated=true)
)

region = MKCoordinateRegionMake(coord, span)
fits = self.view.regionThatFits(region);
fits = self.view.regionThatFits(region)

set_region(fits, animated:animated)
set_region(fits, animated: args[:animated])
end

def set_region(region, animated=true)
Expand Down