DEPRECATED-mapbox-ios-sdk icon indicating copy to clipboard operation
DEPRECATED-mapbox-ios-sdk copied to clipboard

Wrong _metersPerPixel value in -[RMMapView setCenterProjectedPoint:animated:]

Open vzqwer opened this issue 11 years ago • 0 comments

Steps to reproduce.

  1. Center mapView at some coordinate using - [RMMapView setZoom:atCoordinate:animated:]
  2. ZoomOut, for example, using two finger tap.
  3. Show modal viewController.
  4. From modal ViewController call - [RMMapView setZoom:atCoordinate:animated:] with another coordinates for mapView of presentingViewController and close modal viewController.
  5. mapView is centered at wrong coordinate.

As I investigated problem comes from -[RMMapView setCenterProjectedPoint:animated:] The value of _metersPerPixel is wrong because -[RMMapView observeValueForKeyPath:ofObject:change:context:] triggers after -[RMMapView setCenterProjectedPoint:animated:]

This error appears on iPhone5s. On iPhone4s and iPhone5 everything works well.

Fast solution is to replace

[_mapScrollView setContentOffset:CGPointMake(normalizedProjectedPoint.x / _metersPerPixel - _mapScrollView.bounds.size.width/2.0,
                                                _mapScrollView.contentSize.height - ((normalizedProjectedPoint.y / _metersPerPixel) + _mapScrollView.bounds.size.height/2.0))
                           animated:animated];

with

double currentMetersPerPixel = planetBounds.size.width / _mapScrollView.contentSize.width;
[_mapScrollView setContentOffset:CGPointMake(normalizedProjectedPoint.x / currentMetersPerPixel - _mapScrollView.bounds.size.width/2.0,
                                                _mapScrollView.contentSize.height - ((normalizedProjectedPoint.y / currentMetersPerPixel) + _mapScrollView.bounds.size.height/2.0))
                           animated:animated];

vzqwer avatar Sep 08 '14 12:09 vzqwer