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

MGLMapView setCamera: does not check if new camera is the same as current camera #2456

Closed
friedbunny opened this issue Sep 29, 2015 · 1 comment · Fixed by #3362
Closed
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@friedbunny
Copy link
Contributor

-[MGLMapView setCamera:withDuration:animationTimingFunction:] will happily pass along the current (unchanged) camera to _mbglMap->easeTo(), which eventually sends false region change notifications.

This is especially bothersome when trying to set the camera in one of the region change delegate methods, because any call to a -[MGLMapView setCamera:] variant will keep looping but accomplish nothing.

Example:

#import "ViewController.h"
#import "Mapbox.h"

@interface ViewController () <MGLMapViewDelegate>

@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) MGLMapCamera *camera;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

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

    self.mapView.delegate = self;

    self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(51.002040, 3.324372) fromDistance:20000 pitch:60 heading:180];

    [self.mapView setCamera:self.camera];

    [self.view addSubview:self.mapView];
}

- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    NSLog(@"regionDidChangeAnimated");

    [self.mapView setCamera:self.camera];
//               withDuration:2
//    animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
}

@end

Which results in this strangely mesmerizing effect:

camera-pan-no-animation 1 44 58 pm

/cc @incanus @1ec5

@friedbunny friedbunny added bug iOS Mapbox Maps SDK for iOS labels Sep 29, 2015
@friedbunny
Copy link
Contributor Author

The questions here are:

  1. Where to validate that the camera needs changing — MGLMapView or some place in Transform?
  2. How to efficiently perform this validation — which parameter changes matter?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant