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

[iOS] implement long click #268

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
mapView.addGestureRecognizer(singleTap)

let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleMapLongPress(sender:)))
for recognizer in mapView.gestureRecognizers! where recognizer is UILongPressGestureRecognizer {
longPress.require(toFail: recognizer)
}
mapView.addGestureRecognizer(longPress)

if let args = args as? [String: Any] {
Convert.interpretMapboxMapOptions(options: args["options"], delegate: self)
if let initialCameraPosition = args["initialCameraPosition"] as? [String: Any],
Expand Down Expand Up @@ -325,6 +331,28 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
])
}

/*
* UILongPressGestureRecognizer
* After a long press invoke the map#onMapLongClick callback.
*/
@objc @IBAction func handleMapLongPress(sender: UILongPressGestureRecognizer) {
//Only fire at the end of the long press
if (sender.state == .ended) {
// Get the CGPoint where the user tapped.
let point = sender.location(in: mapView)
let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
channel?.invokeMethod("map#onMapLongClick", arguments: [
"x": point.x,
"y": point.y,
"lng": coordinate.longitude,
"lat": coordinate.latitude,
])
}

}



/*
* MGLAnnotationControllerDelegate
*/
Expand Down