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

oldCamera and newCamera have same center coordinate in mapView:shouldChangeFromCamera:toCamera: #10391

Closed
jmkiley opened this issue Nov 6, 2017 · 2 comments
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@jmkiley
Copy link
Contributor

jmkiley commented Nov 6, 2017

Platform: iOS
Mapbox SDK version: v3.7.0-beta.3

Steps to trigger behavior

  1. Create a simple map view that calls -mapView:shouldChangeFromCamera:toCamera: .
  2. Trigger a region change by double tapping on the map view.
  3. Check the centerCoordinate of the oldCamera and newCamera in -mapView:shouldChangeFromCamera:toCamera:.
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate {
    var mapView: MGLMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        let bounds = view.bounds
        mapView = MGLMapView(frame: bounds)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        mapView.delegate = self
        view.addSubview(mapView)
        
        mapView.setCenter(CLLocationCoordinate2D(latitude: 42.5, longitude: -71.2),
                          zoomLevel: 4, animated: false)
    }

    func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool
    {
        print("old: \(oldCamera)")
        print("new: \(newCamera)")
        return true
    }
}

Expected behavior

The oldCamera and newCamera should have different center coordinates.

Actual behavior

They have the same center coordinate in -mapView:shouldChangeFromCamera:toCamera: .

The same behavior occurs with other gesture-based region changes. It looks like the new camera is being created with
(cameraByZoomingToZoomLevel:aroundAnchorPoint)[https://github.com/mapbox/mapbox-gl-native/blob/0ef7b7154f6d4498077a83db5c486c61bc34938c/platform/ios/src/MGLMapView.mm#L1867], but I am not sure whether also creates a center coordinate for the camera.

I explicitly set the new camera's center coordinate after cameraByZoomingToZoomLevel is called here and that seemed to fix the issue for the double tap.
toCamera.centerCoordinate = [self convertPoint:anchorPoint toCoordinateFromView:self];

cc @fabian-guerra

@1ec5
Copy link
Contributor

1ec5 commented Nov 10, 2017

I explicitly set the new camera's center coordinate after cameraByZoomingToZoomLevel is called here and that seemed to fix the issue for the double tap.
toCamera.centerCoordinate = [self convertPoint:anchorPoint toCoordinateFromView:self];

This assumes that the user double-taps on the center of the map view or spreads two fingers apart over the center. However, if the gesture isn’t centered on the map view, then this camera will be calculated as if the view were jumping to the gesture’s center instead of just being anchored there.

@fabian-guerra fabian-guerra added this to the ios-v3.7.0 milestone Nov 13, 2017
@fabian-guerra
Copy link
Contributor

Fixed in #10433

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

3 participants