lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.4.2 vs lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.5.0

- old
+ new

@@ -65,13 +65,17 @@ def showing_user_location? self.view.showsUserLocation 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) show_user_location unless showing_user_location? set_region(MKCoordinateRegionMake(user_location, [radius, radius]), animated) end @@ -172,20 +176,26 @@ self.set_start_position self.class.get_start_position_params end 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 bottomRight.latitude = [bottomRight.latitude, a.coordinate.latitude].min end @@ -201,12 +211,12 @@ ((topLeft.latitude - bottomRight.latitude) * 1.075).abs, ((bottomRight.longitude - topLeft.longitude) * 1.075).abs ) 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) self.view.setRegion(region, animated:animated) end