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.

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

Closed

Description

@andrewstay

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.

Activity

  1. added
    iOS
    on Nov 18, 2016
  2. 1ec5 commented on Nov 20, 2016

    @1ec5
    Contributor

    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).

  3. andrewstay commented on Nov 28, 2016

    @andrewstay
    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)
    }
    
  4. lilykaiser commented on Nov 17, 2017

    @lilykaiser

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

  5. 1ec5 commented on Nov 18, 2017

    @1ec5
    Contributor

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