DEPRECATED-mapbox-ios-sdk
DEPRECATED-mapbox-ios-sdk copied to clipboard
Wrong _metersPerPixel value in -[RMMapView setCenterProjectedPoint:animated:]
Steps to reproduce.
- Center
mapViewat some coordinate using- [RMMapView setZoom:atCoordinate:animated:] - ZoomOut, for example, using two finger tap.
- Show modal viewController.
- From modal ViewController call
- [RMMapView setZoom:atCoordinate:animated:]with another coordinates formapViewofpresentingViewControllerand close modal viewController. mapViewis 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];