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.

.centerCoordinate incorrect after zoom gesture #14977

Closed

Description

@Tapestes

In v5.1, It looks the mapView.centerCoordinate is being set to the center of the two finger zoom gesture, rather than the center of the mapView. Panning with one finger does not cause an issue. The issue does not exist in v4.9 (did not test v5.0).

Steps to reproduce

  1. Set the center coordinate of the map like so mapView.setCenter(someCoord, zoomLevel: 9, direction: 0.0, animated: true)
  2. Pan the map with one finger
  3. Read mapView.centerCoordinate on mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool). The center coordinate correctly reflects the new center of the mapView
  4. Zoom and pan the map with two finger pinch gesture so that the zoom and center point change
  5. Read mapView.centerCoordinate on mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool). The center coordinate does not correctly reflect the new center of the mapView

Expected behavior

.centerCoordinate reports the center of the mapView after two finger zoom/pan

Actual behavior

.centerCoordinate appears to report the center two finger gesture as the .centerPoint on regionDidChange

Configuration

Mapbox v5.1
iOS 12.3.1 (MacOS 10.14.5)
iPad Air 2
Xcode 10.2.1

Activity

  1. added
    iOS
    and removed on Jun 20, 2019
  2. marhas commented on Jul 2, 2019

    @marhas

    Hi!
    I was directed here by Mapbox support since I was reporting a similar issue which probably is the very same bug. Fwiw I'm adding my findings here.

    This bug turned up when we upgraded from 4.9 to 5.1 and I'm certain it wasn't there before. Also, I've only been able to reproduce on a physical device and not on a simulator. Maybe this is because the simulator doesn't pan and zoom in the same gesture as the physical device does?

    I've modified the SimpleMapViewExample_Swift class from the demo app to help demonstrate the issue:

    import Mapbox
    
    @objc(SimpleMapViewExample_Swift)
    
    class SimpleMapViewExample_Swift: UIViewController {
    
        let coordinateLabel = UITextField()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let mapView = MGLMapView(frame: view.bounds)
            mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    
            let mapCenterMarker = UIView()
            mapCenterMarker.backgroundColor = .blue
            mapCenterMarker.frame = CGRect(x: mapView.frame.origin.x + mapView.frame.width / 2, y: mapView.frame.origin.y + mapView.frame.height / 2, width: 2, height: 2)
            view.addSubview(mapView)
            mapView.addSubview(mapCenterMarker)
            view.addSubview(coordinateLabel)
            coordinateLabel.isUserInteractionEnabled = true
            coordinateLabel.backgroundColor = .white
            coordinateLabel.textColor = .black
            coordinateLabel.frame = CGRect(x: 20, y: 100, width: 350, height: 30)
            mapView.delegate = self
        }
    }
    
    extension SimpleMapViewExample_Swift: MGLMapViewDelegate {
    
        func mapView(_ mapView: MGLMapView, regionIsChangingWith reason: MGLCameraChangeReason) {
            updateCoordinateLabel(mapView: mapView)
        }
    
        func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
            mapView.setCenter(CLLocationCoordinate2D(latitude: 59.309986754152305, longitude: 18.062128527216686), zoomLevel: 18, animated: false)
            updateCoordinateLabel(mapView: mapView)
        }
    
        private func updateCoordinateLabel(mapView: MGLMapView) {
            let lat = String(format: "%.8f", mapView.centerCoordinate.latitude)
            let lon = String(format: "%.8f", mapView.centerCoordinate.longitude)
            coordinateLabel.text = "\(lat), \(lon)"
        }
    }
    
    
  3. marhas commented on Jul 2, 2019

    @marhas
  4. victorlsn commented on Jul 2, 2019

    @victorlsn

    I'm pretty sure issue #14192 is also related to that...
    After pinching gesture to zoom, trying to tap at features/annotations becomes a messy thing - but if you double tap to zoom, it's fine.

  5. added this to the release-q milestone on Jul 6, 2019
  6. cbo1964 commented on Jul 9, 2019

    @cbo1964

    Hi,
    I think also the problem I'm facing #15082 is strictly related.
    Very easy to replicate:

    1. With demo App on iOS enter a pin with long pressure
    2. When you tap on it you get the Callout
    3. now pan and zoom with 2 fingers, soon you will no more be able to tap on the pin
    4. Now .. funny .. rotate it and press the compass (so to unrotae and go to standard zoom level) .. and bingo it works again.
  7. friedbunny commented on Jul 9, 2019

    @friedbunny
    Contributor

    Similar to what you’re describing, @cbo1964, this issue also seems to be manifesting during any rotation gesture:

    1. Rotate gesture somewhere besides the center of the view.
    2. Tap the compass to reorient the map to north.
    3. The map will incorrectly recenter at the gesture origin, when it should use the center of the view.
  8. self-assigned this
    on Jul 10, 2019
  9. added
    Core
    on Jul 10, 2019
  10. tmpsantos commented on Jul 12, 2019

    @tmpsantos
    Contributor

    Incoming fix #15097

  11. added a commit that references this issue on Jul 13, 2019
    e874264
  12. added 3 commits that reference this issue on Jul 14, 2019
    d968cbb
    dc393fd
    0cf8fcb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Corebughigh priorityiOS

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions