@@ -40,6 +40,8 @@ public class AppleMapController : NSObject, FlutterPlatformView, MKMapViewDelega
4040 var circleController : CircleController
4141 var initialCameraPosition : [ String : Any ]
4242 var options : [ String : Any ]
43+ var onCalloutTapGestureRecognizer : UITapGestureRecognizer ?
44+ var currentlySelectedAnnotation : String ?
4345
4446 public init ( withFrame frame: CGRect , withRegistrar registrar: FlutterPluginRegistrar , withargs args: Dictionary < String , Any > , withId id: Int64 ) {
4547 self . options = args [ " options " ] as! [ String : Any ]
@@ -72,18 +74,14 @@ public class AppleMapController : NSObject, FlutterPlatformView, MKMapViewDelega
7274 if let circlesToAdd: NSArray = args [ " circlesToAdd " ] as? NSArray {
7375 self . circleController. addCircles ( circleData: circlesToAdd)
7476 }
77+
78+ self . onCalloutTapGestureRecognizer = UITapGestureRecognizer ( target: self , action: #selector( self . calloutTapped ( _: ) ) )
7579 }
7680
7781 public func view( ) -> UIView {
7882 return mapView
7983 }
8084
81- public func mapView( _ mapView: MKMapView , annotationView view: MKAnnotationView , calloutAccessoryControlTapped control: UIControl ) {
82- if let flutterAnnotation: FlutterAnnotation = view. annotation as? FlutterAnnotation {
83- self . channel. invokeMethod ( " infoWindow#onTap " , arguments: [ " annotationId " : flutterAnnotation. id] )
84- }
85- }
86-
8785 // onIdle
8886 public func mapView( _ mapView: MKMapView , regionDidChangeAnimated animated: Bool ) {
8987 self . channel. invokeMethod ( " camera#onIdle " , arguments: " " )
@@ -95,11 +93,20 @@ public class AppleMapController : NSObject, FlutterPlatformView, MKMapViewDelega
9593 }
9694
9795 public func mapView( _ mapView: MKMapView , didSelect view: MKAnnotationView ) {
96+ let tapGesture = UITapGestureRecognizer ( target: self , action: #selector( self . calloutTapped ( _: ) ) )
97+ view. addGestureRecognizer ( tapGesture)
9898 if let annotation : FlutterAnnotation = view. annotation as? FlutterAnnotation {
99+ self . currentlySelectedAnnotation = annotation. id
99100 self . annotationController. onAnnotationClick ( annotation: annotation)
100101 }
101102 }
102103
104+ public func mapView( _ mapView: MKMapView , didDeselect view: MKAnnotationView ) {
105+ self . currentlySelectedAnnotation = nil
106+ view. removeGestureRecognizer ( self . onCalloutTapGestureRecognizer!)
107+ }
108+
109+
103110 public func mapView( _ mapView: MKMapView , viewFor annotation: MKAnnotation ) -> MKAnnotationView ? {
104111 if annotation is MKUserLocation {
105112 return nil
@@ -120,6 +127,12 @@ public class AppleMapController : NSObject, FlutterPlatformView, MKMapViewDelega
120127 return MKOverlayRenderer ( )
121128 }
122129
130+ @objc func calloutTapped( _ sender: UITapGestureRecognizer ? = nil ) {
131+ if self . currentlySelectedAnnotation != nil {
132+ self . channel. invokeMethod ( " infoWindow#onTap " , arguments: [ " annotationId " : self . currentlySelectedAnnotation!] )
133+ }
134+ }
135+
123136 private func setMethodCallHandlers( ) {
124137 channel. setMethodCallHandler ( { ( call: FlutterMethodCall , result: FlutterResult ) -> Void in
125138 if let args : Dictionary < String , Any > = call. arguments as? Dictionary < String , Any > {
0 commit comments