[ios, osx] Constrain zoom level when selecting offline pack

When selecting an offline pack for display in iosapp or osxapp, constrain the zoom level to the pack’s minimum and maximum zoom levels.

Fixes #4787.
This commit is contained in:
Minh Nguyễn
2016-04-21 16:50:45 -07:00
committed by Minh Nguyễn
parent 0dbec51401
commit 3a22033b90
4 changed files with 11 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ static NSString * const MBXOfflinePacksTableViewActiveCellReuseIdentifier = @"Ac
- (void)applyToMapView:(MGLMapView *)mapView {
mapView.styleURL = self.styleURL;
[mapView setVisibleCoordinateBounds:self.bounds];
mapView.zoomLevel = MIN(self.maximumZoomLevel, MAX(self.minimumZoomLevel, mapView.zoomLevel));
}
@end

View File

@@ -16,6 +16,8 @@ extern NSString * const MGLMapboxAccessTokenDefaultsKey;
@property (assign) double pendingZoomLevel;
@property (copy) MGLMapCamera *pendingCamera;
@property (assign) MGLCoordinateBounds pendingVisibleCoordinateBounds;
@property (assign) double pendingMinimumZoomLevel;
@property (assign) double pendingMaximumZoomLevel;
@property (copy) NSURL *pendingStyleURL;
@property (assign) MGLMapDebugMaskOptions pendingDebugMask;

View File

@@ -204,6 +204,8 @@ NSString * const MGLLastMapDebugMaskDefaultsKey = @"MGLLastMapDebugMask";
if ([pack.region isKindOfClass:[MGLTilePyramidOfflineRegion class]]) {
MGLTilePyramidOfflineRegion *region = (MGLTilePyramidOfflineRegion *)pack.region;
self.pendingVisibleCoordinateBounds = region.bounds;
self.pendingMinimumZoomLevel = region.minimumZoomLevel;
self.pendingMaximumZoomLevel = region.maximumZoomLevel;
[[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
}
break;

View File

@@ -211,6 +211,12 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
if (appDelegate.pendingDebugMask) {
self.mapView.debugMask = appDelegate.pendingDebugMask;
}
if (appDelegate.pendingMinimumZoomLevel >= 0) {
self.mapView.zoomLevel = MAX(appDelegate.pendingMinimumZoomLevel, self.mapView.zoomLevel);
}
if (appDelegate.pendingMaximumZoomLevel >= 0) {
self.mapView.zoomLevel = MIN(appDelegate.pendingMaximumZoomLevel, self.mapView.zoomLevel);
}
// Temporarily set the display name to the default center coordinate instead
// of “Untitled” until the binding kicks in.