Val Moratalla
Val Moratalla

Reputation: 211

Mapbox v10 iOS Updating the camera while dragging viewAnnotation outside screen bounds causes rapid camera movement

With the Mapbox v10 iOS SDK, a lot of APIs changed including the drag and camera options. Basically, when using v6, everything is working perfectly fine when dragging an annotation view(subclasss MGLAnnotationView) outside of map bounds just by using the mapView.setCenter and passing in the screenCoordinates (please check code snippet).

As of v10, there is no more MGLAnnotationView and I used ViewAnnotations(https://docs.mapbox.com/ios/maps/guides/annotations/view-annotations/) to display my custom annotations. Additionally, we need to create a camera options instance and pass in the screen coordinates and use that to set camera.

The problem is using v10, whenever I drag the annotation view outside the map/screen bounds, it moves rapidly. Did anyone encounter it using v10 and what fix did you do?

Appreciate any help.

Using Mapbox iOS SDK v6

func handleDragging(_ annotationView: AnnotationView) {  // AnnotationView is a subclass of MGLAnnotationView
 guard let gesture = annotationView.gestureRecognizers?.first as? UIPanGestureRecognizer else { return }
    let gesturePoint = gesture.location(in: view)
let screenCoordinate = mapView.convert(gesturePoint, toCoordinateFrom: nil)
let mapBounds = CGRect(x: UIScreen.main.bounds.origin.x + 30, y: UIScreen.main.bounds.origin.y + 30, width: UIScreen.main.bounds.size.width - 60, height: UIScreen.main.bounds.size.height - 60)
 if !mapBounds.contains(gesturePoint) {
     mapView.setCenter(screenCoordinate, zoomLevel: 15, animated: true)
    }
}

Using Mapbox iOS SDK v10.4.3

func handleDragging(_ annotationView: AnnotationView) { // AnnotationView is a subclass of UIView only
guard let gesture = annotationView.gestureRecognizers?.first as? UIPanGestureRecognizer else { return }
    let gesturePoint = gesture.location(in: view)
let screenCoordinate = self.mapView.mapboxMap.coordinate(for: gesturePoint)
    let mapBounds = CGRect(x: UIScreen.main.bounds.origin.x + 30, y: UIScreen.main.bounds.origin.y + 30, width: UIScreen.main.bounds.size.width - 60, height: UIScreen.main.bounds.size.height - 60)
    if !mapBounds.contains(gesturePoint) {
      let cameraOptions = CameraOptions(center: screenCoordinate, zoom: self.mapView.cameraState.zoom, bearing: self.mapView.cameraState.bearing, pitch: self.mapView.cameraState.pitch)
          self.mapView.mapboxMap.setCamera(to: cameraOptions)
    }
}

Upvotes: 1

Views: 880

Answers (1)

Val Moratalla
Val Moratalla

Reputation: 211

This issue has been resolved with the 'MapboxMaps', '~> 10.7.0' version. Additionally, set self.mapView.viewport.options.transitionsToIdleUponUserInteraction = false.

This is a MapboxMaps version issue.

Upvotes: 1

Related Questions