Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Implemented -setVisibleCoordinateBounds:
Browse files Browse the repository at this point in the history
Followup to #1783: Implemented the non-animated version of fit to bounds and makes it a KVO-compliant property.
  • Loading branch information
1ec5 committed Jun 26, 2015
1 parent bcbb56c commit 29fd554
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ IB_DESIGNABLE
* @param animated Specify `YES` if you want the map view to animate scrolling and zooming to the new location or `NO` if you want the map to display the new location immediately. */
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel animated:(BOOL)animated;

/** Returns the coordinate bounds visible in the receiver’s viewport. */
- (MGLCoordinateBounds)visibleCoordinateBounds;
/** The coordinate bounds visible in the receiver’s viewport.
*
* Changing the value of this property updates the receiver immediately. If you want to animate the change, call `setVisibleCoordinateBounds:animated:` instead. */
@property (nonatomic) MGLCoordinateBounds visibleCoordinateBounds;

/** Changes the receiver’s viewport to fit the given coordinate bounds, optionally animating the change.
* @param bounds The bounds that the viewport will show in its entirety.
* @param animated Specify `YES` to animate the change by smoothly scrolling and zooming or `NO` to immediately display the given bounds. */
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;

/** Changes the receiver’s viewport to fit the given coordinate bounds, optionally animating the change.
/** Changes the receiver’s viewport to fit the given coordinate bounds and optionally some additional padding on each side.
* @param bounds The bounds that the viewport will show in its entirety.
* @param insets The minimum padding (in screen points) that will be visible around the given coordinate bounds.
* @param animated Specify `YES` to animate the change by smoothly scrolling and zooming or `NO` to immediately display the given bounds. */
Expand Down
7 changes: 7 additions & 0 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,11 @@ - (MGLCoordinateBounds)visibleCoordinateBounds
return MGLCoordinateBoundsFromLatLngBounds(self.viewportBounds);
}

- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds
{
[self setVisibleCoordinateBounds:bounds animated:NO];
}

- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated
{
[self setVisibleCoordinateBounds:bounds edgePadding:UIEdgeInsetsZero animated:animated];
Expand All @@ -1471,8 +1476,10 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEd
// NOTE: does not disrupt tracking mode
CGFloat duration = animated ? MGLAnimationDuration : 0;

[self willChangeValueForKey:@"visibleCoordinateBounds"];
mbgl::EdgeInsets mbglInsets = {insets.top, insets.left, insets.bottom, insets.right};
_mbglMap->fitBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), mbglInsets, secondsAsDuration(duration));
[self didChangeValueForKey:@"visibleCoordinateBounds"];

[self unrotateIfNeededAnimated:animated];

Expand Down

0 comments on commit 29fd554

Please sign in to comment.