Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new GestureManagerDelegate method to track gesture progress #1100

Open
Keltar1977 opened this issue Feb 8, 2022 · 3 comments
Open

Add new GestureManagerDelegate method to track gesture progress #1100

Keltar1977 opened this issue Feb 8, 2022 · 3 comments
Labels
feature 🍏 When working on a new feature or feature enhancement

Comments

@Keltar1977
Copy link

New Feature

We encountered problem that we cannot adjust or track gesture while it is in progress as we cannot track it. We suggest to add new method func gestureManager(_ gestureManager: GestureManager, didChange gestureType: GestureType). It will allow to track gesture progress and update other views or map, if we want specific behaviour like zoom only to centre.

Why

In mapbox 6 there was "regionIsChanging" delegate which we used and anchorPoint method for gestures where we could adjust centre point when user performs a gesture. In new version there no such methods or they are not as obvious to use. We need this, for example, to update angle slider when user rotate map with pinch gesture and also to update map centre while zooming with pinch so map won't move (forbid pan gesture while zooming)

@ZiZasaurus ZiZasaurus added the feature 🍏 When working on a new feature or feature enhancement label Feb 8, 2022
@macdrevx
Copy link
Contributor

macdrevx commented Feb 18, 2022

anchorPoint method for gestures is being added in #1122

to observe camera changes during a gesture, you can add an onEvery(.cameraChanged) listener when the gesture begins and cancel it when the gesture ends.

Something like this…

final class ViewController: UIViewController {

    var mapView: MapView!

    var cameraChangedCancelable: Cancelable?

    override func viewDidLoad() {
        super.viewDidLoad()
        mapView = MapView(frame: view.bounds)
        mapView.gestures.delegate = self
        view.addSubview(mapView)
    }
}

extension ViewController: GestureManagerDelegate {
    func gestureManager(_ gestureManager: GestureManager, didBegin gestureType: GestureType) {
        cameraChangedCancelable = mapView.mapboxMap.onEvery(.cameraChanged, handler: { [weak self] _ in
            guard let self = self else { return }
            // do something with camera state here
            print("camera: \(self.mapView.cameraState)")
        })
    }

    func gestureManager(_ gestureManager: GestureManager, didEnd gestureType: GestureType, willAnimate: Bool) {
        if !willAnimate {
            cameraChangedCancelable?.cancel()
        }
    }

    func gestureManager(_ gestureManager: GestureManager, didEndAnimatingFor gestureType: GestureType) {
        cameraChangedCancelable?.cancel()
    }
}

@shinriyo
Copy link
Contributor

shinriyo commented Nov 28, 2023

Does it have a maximum scale setting?
It ignores the zoom property.

let myRange = Range: CountableCloseRange<UInt8> = 6...14

// something

TilesetDescriptionOptions(
  // something
  zoom: myRange
)

@shinriyo
Copy link
Contributor

pinch gesture also ignores the scale setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🍏 When working on a new feature or feature enhancement
Projects
None yet
Development

No branches or pull requests

4 participants