Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was 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

Description

@friedbunny

-[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

Activity

  1. added
    iOS
    on Sep 29, 2015
  2. friedbunny commented on Sep 29, 2015

    @friedbunny
    ContributorAuthor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions