diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index ed0327ea2..5a94ab2f4 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -596,16 +596,34 @@ IB_DESIGNABLE /** Sets the visible region so that the map displays the specified annotations. - + Calling this method updates the value in the visibleCoordinateBounds property - and potentially other properties to reflect the new map region. - + and potentially other properties to reflect the new map region. Defaults to + insetting the annotation bounds by 100,100,100,100, or if map is smaller than + 200x200 in either dimension, sets the insets to 20% of that dimmension on + either side. + @param annotations The annotations that you want to be visible in the map. @param animated `YES` if you want the map region change to be animated, or `NO` if you want the map to display the new region immediately without animations. */ - (void)showAnnotations:(NS_ARRAY_OF(id ) *)annotations animated:(BOOL)animated; +/** + Sets the visible region so that the map displays the specified annotations with + custom insets. + + Calling this method updates the value in the visibleCoordinateBounds property + and potentially other properties to reflect the new map region. It allows for + the customization of the UIEdgeInsets that determine the resultant viewport. + + @param annotations The annotations that you want to be visible in the map. + @param edgeInsets Custom edge insets to contain the the annotations within. + @param animated `YES` if you want the map region change to be animated, or `NO` + if you want the map to display the new region immediately without animations. + */ +- (void)showAnnotations:(NS_ARRAY_OF(id ) *)annotations withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated; + /** A camera representing the current viewpoint of the map. */ diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index dfac4db86..beb043859 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2951,6 +2951,19 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) } - (void)showAnnotations:(NS_ARRAY_OF(id ) *)annotations animated:(BOOL)animated +{ + CGFloat defaultPadding = 100; + CGFloat yPadding = (self.frame.size.height / 2 <= defaultPadding) ? (self.frame.size.height / 5) : defaultPadding; + CGFloat xPadding = (self.frame.size.width / 2 <= defaultPadding) ? (self.frame.size.width / 5) : defaultPadding; + + UIEdgeInsets edgeInsets = UIEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding); + + [self showAnnotations:annotations + withEdgeInsets:edgeInsets + animated:animated]; +} + +- (void)showAnnotations:(NS_ARRAY_OF(id ) *)annotations withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated { if ( ! annotations || ! annotations.count) return; @@ -2968,12 +2981,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) } } - CGFloat defaultPadding = 100; - CGFloat yPadding = (self.frame.size.height / 2 <= defaultPadding) ? (self.frame.size.height / 5) : defaultPadding; - CGFloat xPadding = (self.frame.size.width / 2 <= defaultPadding) ? (self.frame.size.width / 5) : defaultPadding; - [self setVisibleCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(bounds) - edgePadding:UIEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding) + edgePadding:edgeInsets animated:animated]; }