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

.centerCoordinate incorrect after zoom gesture #14977

Closed
Tapestes opened this issue Jun 20, 2019 · 6 comments · Fixed by #15097
Closed

.centerCoordinate incorrect after zoom gesture #14977

Tapestes opened this issue Jun 20, 2019 · 6 comments · Fixed by #15097
Assignees
Labels
bug Core The cross-platform C++ core, aka mbgl high priority iOS Mapbox Maps SDK for iOS

Comments

@Tapestes
Copy link

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

@friedbunny friedbunny added bug iOS Mapbox Maps SDK for iOS UX and removed UX labels Jun 20, 2019
@marhas
Copy link

marhas commented Jul 2, 2019

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)"
    }
}

@marhas
Copy link

marhas commented Jul 2, 2019

Here's a video that demonstrates the issue using the code above: https://www.dropbox.com/s/k3sihajq5ojm1u0/mapbox_zoom_bug.mov?dl=0

@victorlsn
Copy link

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.

@chloekraw chloekraw added this to the release-q milestone Jul 6, 2019
@cbo1964
Copy link

cbo1964 commented Jul 9, 2019

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.

@friedbunny
Copy link
Contributor

friedbunny commented Jul 9, 2019

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.

@astojilj astojilj self-assigned this Jul 10, 2019
@chloekraw chloekraw added the Core The cross-platform C++ core, aka mbgl label Jul 10, 2019
astojilj added a commit that referenced this issue Jul 10, 2019
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
@tmpsantos
Copy link
Contributor

Incoming fix #15097

friedbunny pushed a commit that referenced this issue Jul 13, 2019
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
astojilj added a commit that referenced this issue Jul 14, 2019
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
astojilj added a commit that referenced this issue Jul 19, 2019
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
astojilj added a commit that referenced this issue Jul 23, 2019
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Core The cross-platform C++ core, aka mbgl high priority iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants