From 0a736c3a76e3594c12868ed9dd5f1d8da3ca8050 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 2 Apr 2015 19:56:47 -0700 Subject: [PATCH 1/2] fixes #1181: fix lat/lng & zoom ordering problems --- platform/ios/MGLMapView.mm | 15 ++++++++++----- src/mbgl/map/map.cpp | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 962e3a112..a3c25f267 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -46,8 +46,9 @@ NSString *const MGLDefaultStyleName = @"Emerald"; NSString *const MGLStyleVersion = @"v7"; NSString *const MGLDefaultStyleMarkerSymbolName = @"default_marker"; -NSTimeInterval const MGLAnimationDuration = 0.3; +const NSTimeInterval MGLAnimationDuration = 0.3; const CGSize MGLAnnotationUpdateViewportOutset = {150, 150}; +const CGFloat MGLMinZoom = 3; NSString *const MGLAnnotationIDKey = @"MGLAnnotationIDKey"; @@ -1129,7 +1130,9 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; { CGFloat duration = (animated ? MGLAnimationDuration : 0); - mbglMap->setLatLng(coordinateToLatLng(coordinate), secondsAsDuration(duration)); + mbglMap->setLatLngZoom(coordinateToLatLng(coordinate), + fmaxf(mbglMap->getZoom(), MGLMinZoom), + secondsAsDuration(duration)); [self notifyMapChange:@(animated ? mbgl::MapChangeRegionDidChangeAnimated : mbgl::MapChangeRegionDidChange)]; } @@ -1168,7 +1171,9 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; CGFloat duration = (animated ? MGLAnimationDuration : 0); - mbglMap->setZoom(zoomLevel, secondsAsDuration(duration)); + mbglMap->setLatLngZoom(mbglMap->getLatLng(), + fmaxf(zoomLevel, MGLMinZoom), + secondsAsDuration(duration)); [self unrotateIfNeededAnimated:animated]; @@ -1738,7 +1743,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng) { self.showsUserLocation = YES; - if (self.zoomLevel < 3) [self setZoomLevel:3 animated:YES]; + if (self.zoomLevel < MGLMinZoom) [self setZoomLevel:MGLMinZoom animated:YES]; if (self.userLocationAnnotationView) { @@ -1949,7 +1954,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng) - (BOOL)isRotationAllowed { - return (self.zoomLevel > 3); + return (self.zoomLevel > MGLMinZoom); } // correct rotations to north as needed diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 509986a6d..09e6b08a1 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -470,7 +470,7 @@ void Map::setLatLng(LatLng latLng, Duration duration) { } LatLng Map::getLatLng() const { - return state.getLatLng(); + return transform.getLatLng(); } void Map::resetPosition() { From c253232473b82c5e3ae2fcb937301581c89bab50 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Fri, 3 Apr 2015 09:06:20 -0700 Subject: [PATCH 2/2] account for GL-level min zoom --- platform/ios/MGLMapView.mm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index a3c25f267..d48694917 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -48,7 +48,7 @@ NSString *const MGLDefaultStyleMarkerSymbolName = @"default_marker"; const NSTimeInterval MGLAnimationDuration = 0.3; const CGSize MGLAnnotationUpdateViewportOutset = {150, 150}; -const CGFloat MGLMinZoom = 3; +const CGFloat MGLMinimumZoom = 3; NSString *const MGLAnnotationIDKey = @"MGLAnnotationIDKey"; @@ -1131,7 +1131,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; CGFloat duration = (animated ? MGLAnimationDuration : 0); mbglMap->setLatLngZoom(coordinateToLatLng(coordinate), - fmaxf(mbglMap->getZoom(), MGLMinZoom), + fmaxf(mbglMap->getZoom(), self.currentMinimumZoom), secondsAsDuration(duration)); [self notifyMapChange:@(animated ? mbgl::MapChangeRegionDidChangeAnimated : mbgl::MapChangeRegionDidChange)]; @@ -1172,7 +1172,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; CGFloat duration = (animated ? MGLAnimationDuration : 0); mbglMap->setLatLngZoom(mbglMap->getLatLng(), - fmaxf(zoomLevel, MGLMinZoom), + fmaxf(zoomLevel, self.currentMinimumZoom), secondsAsDuration(duration)); [self unrotateIfNeededAnimated:animated]; @@ -1743,7 +1743,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng) { self.showsUserLocation = YES; - if (self.zoomLevel < MGLMinZoom) [self setZoomLevel:MGLMinZoom animated:YES]; + if (self.zoomLevel < self.currentMinimumZoom) [self setZoomLevel:self.currentMinimumZoom animated:YES]; if (self.userLocationAnnotationView) { @@ -1952,9 +1952,14 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), animations); } +- (CGFloat)currentMinimumZoom +{ + return fmaxf(mbglMap->getMinZoom(), MGLMinimumZoom); +} + - (BOOL)isRotationAllowed { - return (self.zoomLevel > MGLMinZoom); + return (self.zoomLevel >= self.currentMinimumZoom); } // correct rotations to north as needed