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

-[MGLMapViewDelegate mapView: regionDidChangeAnimated:] redundant calls #7119

Closed
andrewstay opened this issue Nov 18, 2016 · 4 comments
Closed
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@andrewstay
Copy link

Platform: iOS
Mapbox SDK version: ios-v3.4.0-beta.2

Steps to trigger behavior

-[MGLMapViewDelegate mapView: regionDidChangeAnimated:] method is called every time a bounds is set, even if the bounds is the same as before.

  1. Implement delegate's method as following:
- (void)mapView:(MGLMapView *)aView regionDidChangeAnimated:(BOOL)animated
{
    CLLocationCoordinate2D sw = {.latitude = 52.685389098664004, .longitude = 5.2769973809771002};
    CLLocationCoordinate2D ne = {.latitude = 52.036343013055998, .longitude = 4.4359466497847002};
    MGLCoordinateBounds bounds = {.sw = sw, .ne = ne};
    [self.mapView setVisibleCoordinateBounds:bounds animated:YES];
}

Expected behavior

Delegate's method should not be called if the bounds are not actually changed as the same bounds is set as before.

Actual behavior

Delegate's method is called every time. The code above cycles the stack.

@1ec5
Copy link
Contributor

1ec5 commented Nov 20, 2016

Assuming bounds is equivalent to self.visibleCoordinateBounds at this point, what you’re seeing is one symptom of #5983 that either #6060 or #7125 aims to address. You can work around the issue by avoiding the call to -setVisibleCoordinateBounds:animated: if MGLCoordinateBoundsEqualToCoordinateBounds(bounds, self.visibleCoordinateBounds) (although you may need to write out the comparison due to floating-point precision issues).

@andrewstay
Copy link
Author

@1ec5 The workaround suggested by you will not work as the newly set bounds are simply not "updated" immediately and on the next delegate call I still get the old ones.

        MGLCoordinateBounds visibleBounds = self.mapView.visibleCoordinateBounds;
        Stay_LogStruct(visibleBounds);
        Stay_LogStruct(self.limitedBounds);
        if (!MGLCoordinateBoundsEqualToCoordinateBounds(self.limitedBounds, visibleBounds))
        {
             [self.mapView setVisibleCoordinateBounds:self.limitedBounds animated:YES];
        }

Generates the following output after first call:

visibleBounds = {
  sw = (latitude = 52.330219750804105, longitude = 4.8401534999993601)
  ne = (latitude = 52.445483002278053, longitude = 4.9679914999995844)
}
limitedBounds = {
  sw = (latitude = 52.685389098664004, longitude = 5.2769973809771002)
  ne = (latitude = 52.036343013055998, longitude = 4.4359466497847002)
}

After second call:

visibleBounds = {
  sw = (latitude = 52.330219750804105, longitude = 4.8401534999993601)
  ne = (latitude = 52.445483002278053, longitude = 4.9679914999995844)
}
limitedBounds = {
  sw = (latitude = 52.685389098664004, longitude = 5.2769973809771002)
  ne = (latitude = 52.036343013055998, longitude = 4.4359466497847002)
}

@lilykaiser
Copy link

Closing due to ticket age. If this is still a problem, please re-open

@1ec5
Copy link
Contributor

1ec5 commented Nov 18, 2017

This issue was originally filed due to difficulty constraining gestures to an offline region. As of #5584, you can implement the -[MGLMapViewDelegate mapView:shouldChangeFromCamera:toCamera:] to achieve this effect. Here’s an example of the delegate method in action.

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

No branches or pull requests

5 participants