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.

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

Closed

Description

@jmkiley

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

Activity

  1. added
    iOS
    on Nov 6, 2017
  2. 1ec5 commented on Nov 10, 2017

    @1ec5
    Contributor

    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.

  3. added this to the milestone on Nov 13, 2017
  4. fabian-guerra commented on Nov 16, 2017

    @fabian-guerra
    Contributor

    Fixed in #10433

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions