From 3a22033b90f1c4db4bb49c79a809fe14dc253c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 21 Apr 2016 16:50:45 -0700 Subject: [PATCH] [ios, osx] Constrain zoom level when selecting offline pack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- platform/ios/app/MBXOfflinePacksTableViewController.m | 1 + platform/osx/app/AppDelegate.h | 2 ++ platform/osx/app/AppDelegate.m | 2 ++ platform/osx/app/MapDocument.m | 6 ++++++ 4 files changed, 11 insertions(+) diff --git a/platform/ios/app/MBXOfflinePacksTableViewController.m b/platform/ios/app/MBXOfflinePacksTableViewController.m index 8aad4fbbf..9b1a12a93 100644 --- a/platform/ios/app/MBXOfflinePacksTableViewController.m +++ b/platform/ios/app/MBXOfflinePacksTableViewController.m @@ -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 diff --git a/platform/osx/app/AppDelegate.h b/platform/osx/app/AppDelegate.h index ca9edab77..a1d9297b2 100644 --- a/platform/osx/app/AppDelegate.h +++ b/platform/osx/app/AppDelegate.h @@ -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; diff --git a/platform/osx/app/AppDelegate.m b/platform/osx/app/AppDelegate.m index d9fd96741..b7860cf13 100644 --- a/platform/osx/app/AppDelegate.m +++ b/platform/osx/app/AppDelegate.m @@ -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; diff --git a/platform/osx/app/MapDocument.m b/platform/osx/app/MapDocument.m index 2c5930f00..256bd5b6e 100644 --- a/platform/osx/app/MapDocument.m +++ b/platform/osx/app/MapDocument.m @@ -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.