diff options
author | Jordan Moncharmont <jormon@gmail.com> | 2016-01-22 18:17:30 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-02-01 20:55:55 -0800 |
commit | 909832624e3c3afa28f98e109c5bae188a4f3120 (patch) | |
tree | 105f4b0a7f45ef12141062c8010949bff791e082 | |
parent | 52689796dfed796a1e949d39be411ccca3041933 (diff) | |
download | qtlocation-mapboxgl-909832624e3c3afa28f98e109c5bae188a4f3120.tar.gz |
Custom edgeInsets for fitting in showAnnotations
Keeps sensible defaults already in place, but allows callers to override.
-rw-r--r-- | include/mbgl/ios/MGLMapView.h | 24 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 19 |
2 files changed, 35 insertions, 8 deletions
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index ed0327ea28..5a94ab2f44 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -596,10 +596,13 @@ 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. @@ -607,6 +610,21 @@ IB_DESIGNABLE - (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)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 <MGLAnnotation>) *)annotations withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated; + +/** A camera representing the current viewpoint of the map. */ @property (nonatomic, copy) MGLMapCamera *camera; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index dfac4db862..beb0438591 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2952,6 +2952,19 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) - (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)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 <MGLAnnotation>) *)annotations withEdgeInsets:(UIEdgeInsets)edgeInsets animated:(BOOL)animated +{ if ( ! annotations || ! annotations.count) return; mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable(); @@ -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]; } |