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

Setting the camera in viewDidLoad does not take effect #3859

Open
friedbunny opened this issue Feb 9, 2016 · 2 comments
Open

Setting the camera in viewDidLoad does not take effect #3859

friedbunny opened this issue Feb 9, 2016 · 2 comments
Labels
bug gl-ios iOS Mapbox Maps SDK for iOS MapKit parity For feature parity with MapKit on iOS or macOS

Comments

@friedbunny
Copy link
Contributor

Instantiating a map view in viewDidLoad and then trying to set a new camera on that map view no longer works in v3.1.0. Moving the camera setting code to viewDidAppear is enough of a delay to make it work.

MapKit allows viewDidLoad camera manipulation.

The pre-v3.1.0 camera animation example which no longer works:

#import "ViewController.h"
#import <Mapbox/Mapbox.h>

@interface ViewController ()

@property (nonatomic) MGLMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(50.999, 3.3253);

    // Optionally set a starting point, rotated 180°
    [self.mapView setCenterCoordinate:center zoomLevel:5 direction:180 animated:NO];

    [self.view addSubview:self.mapView];

    // Create a camera that rotates around the same center point, back to 0°
    // `fromDistance:` is meters above mean sea level that an eye would have to be in order to see what the map view is showing
    MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:center fromDistance:9000 pitch:45 heading:0];

    // Animate the camera movement over 5 seconds
    [self.mapView setCamera:camera withDuration:5 animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
}

@end

/cc @1ec5

@friedbunny friedbunny added bug GL JS parity For feature parity with Mapbox GL JS iOS Mapbox Maps SDK for iOS labels Feb 9, 2016
friedbunny added a commit to mapbox/ios-sdk-examples that referenced this issue Feb 9, 2016
@1ec5
Copy link
Contributor

1ec5 commented Feb 9, 2016

I suspect this is a result of #3362. The conversion between altitude and zoom level relies on a vertical field of view that’s measured relative to the view’s height. I suspect the map view and its superview haven’t reached their full height inside of -viewDidLoad.

@1ec5 1ec5 added MapKit parity For feature parity with MapKit on iOS or macOS and removed GL JS parity For feature parity with Mapbox GL JS labels Aug 15, 2016
@stale stale bot added the archived Archived because of inactivity label Nov 18, 2018
@stale
Copy link

stale bot commented Nov 20, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug gl-ios iOS Mapbox Maps SDK for iOS MapKit parity For feature parity with MapKit on iOS or macOS
Projects
None yet
Development

No branches or pull requests

3 participants