diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index db22a7f83..69c156638 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -3,6 +3,7 @@ MapLibre welcomes participation and contributions from everyone. Please read [`Contributing Guide`](https://github.com/maplibre/maplibre-native/blob/master/CONTRIBUTING.md) to get started. ## main +* Add `flyToCamera` with `edgePadding` for `MLNMapView` * Add `MLNMapView.setLatLngBounds` and `MLNMapView.clearLatLnBounds` * 💥 Breaking: Changed the prefix of files, classes, methods, variables and everything from `MGL` to `MLN`. ([#919](https://github.com/maplibre/maplibre-native/pull/919)). diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index a661c2965..419edfbfb 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -116,6 +116,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MBXSettingsMiscellaneousSetContentInsets, MBXSettingsMiscellaneousShowCustomLocationManager, MBXSettingsMiscellaneousOrnamentsPlacement, + MBXSettingsMiscellaneousLatLngBoundsWithPadding, MBXSettingsMiscellaneousPrintLogFile, MBXSettingsMiscellaneousDeleteLogFile }; @@ -445,6 +446,7 @@ CLLocationCoordinate2D randomWorldCoordinate(void) { [NSString stringWithFormat:@"Turn %@ Content Insets", (_contentInsetsEnabled ? @"Off" : @"On")], @"View Route Simulation", @"Ornaments Placement", + @"Lat Long bounds with padding" ]]; break; @@ -759,6 +761,9 @@ CLLocationCoordinate2D randomWorldCoordinate(void) { [self.navigationController pushViewController:ornamentsViewController animated:YES]; break; } + case MBXSettingsMiscellaneousLatLngBoundsWithPadding: + [self flyToWithLatLngBoundsAndPadding]; + break; default: NSAssert(NO, @"All miscellaneous setting rows should be implemented"); break; @@ -1739,6 +1744,30 @@ CLLocationCoordinate2D randomWorldCoordinate(void) { return backupImage; } +- (void)flyToWithLatLngBoundsAndPadding +{ + [self.mapView removeAnnotations:self.mapView.annotations]; + CLLocationCoordinate2D sw = CLLocationCoordinate2DMake(48, 11); + CLLocationCoordinate2D ne = CLLocationCoordinate2DMake(50, 12); + + UIEdgeInsets padding = UIEdgeInsetsMake(200, 200, 0, 0); + MLNMapCamera *cameraWithoutPadding = [self.mapView cameraThatFitsCoordinateBounds:MLNCoordinateBoundsMake(sw, ne) + edgePadding:padding]; + + + MLNPointAnnotation *annotation = [MLNPointAnnotation new]; + annotation.coordinate = cameraWithoutPadding.centerCoordinate; + annotation.title = @"Bounds center"; + [self.mapView addAnnotation: annotation]; + + __weak MBXViewController *weakSelf = self; + [self.mapView flyToCamera:cameraWithoutPadding edgePadding:padding withDuration:5 completionHandler:^{ + [weakSelf.mapView flyToCamera:cameraWithoutPadding edgePadding:UIEdgeInsetsZero withDuration:5 completionHandler:^{ + + }]; + }]; +} + // MARK: - Random World Tour - (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius { diff --git a/platform/ios/src/MLNMapView.h b/platform/ios/src/MLNMapView.h index bca22c29b..ddeb9bb6e 100644 --- a/platform/ios/src/MLNMapView.h +++ b/platform/ios/src/MLNMapView.h @@ -1253,6 +1253,25 @@ MLN_EXPORT */ - (void)flyToCamera:(MLNMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion; + +/** + Moves the viewpoint to a different location using a transition animation that + evokes powered flight. + + The transition animation seamlessly incorporates zooming and panning to help + the user find his or her bearings even after traversing a great distance. + + @param camera The new viewpoint. + @param duration The amount of time, measured in seconds, that the transition + animation should take. Specify `0` to jump to the new viewpoint + instantaneously. Specify a negative value to use the default duration, which + is based on the length of the flight path. + @param edgePadding The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @param completion The block to execute after the animation finishes. + */ +- (void)flyToCamera:(MLNMapCamera *)camera edgePadding:(UIEdgeInsets)insets withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion; + /** Returns the camera that best fits the given coordinate bounds. diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index 74ffc1cd4..192a96c78 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -4218,6 +4218,14 @@ static void *windowScreenContext = &windowScreenContext; [self _flyToCamera:camera edgePadding:self.contentInset withDuration:duration peakAltitude:peakAltitude completionHandler:completion]; } +- (void)flyToCamera:(MLNMapCamera *)camera edgePadding:(UIEdgeInsets)insets withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion { + UIEdgeInsets finalEdgeInsets = UIEdgeInsetsMake(self.contentInset.top + insets.top, + self.contentInset.left + insets.left, + self.contentInset.bottom + insets.bottom, + self.contentInset.right + insets.right); + [self _flyToCamera:camera edgePadding:finalEdgeInsets withDuration:duration peakAltitude:-1 completionHandler:completion]; +} + - (void)_flyToCamera:(MLNMapCamera *)camera edgePadding:(UIEdgeInsets)insets withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion { if (!_mbglMap) @@ -4259,7 +4267,6 @@ static void *windowScreenContext = &windowScreenContext; dispatch_async(dispatch_get_main_queue(), pendingCompletion); }; } - if ([self.camera isEqualToMapCamera:camera] && UIEdgeInsetsEqualToEdgeInsets(_contentInset, insets)) { if (pendingCompletion)