diff --git a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift index a1663d3..7710a04 100644 --- a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift +++ b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift @@ -44,6 +44,27 @@ extension MapKitViewHost { return nil } + // Annotation drag lifecycle. + public func mapView(_ mapView: MKMapView, + annotationView view: MKAnnotationView, + didChange newState: MKAnnotationView.DragState, + fromOldState oldState: MKAnnotationView.DragState) { + guard let annotation = view.annotation as? FlutterAnnotation else { return } + let id = annotation.id + let coordinate = PlatformCoordinate.from(annotation.coordinate) + switch newState { + case .starting: + self.flutterApi.onAnnotationDragStart(annotationId: id, coordinate: coordinate) { _ in } + case .dragging: + self.flutterApi.onAnnotationDrag(annotationId: id, coordinate: coordinate) { _ in } + case .ending, .canceling: + annotation.wasDragged = true + self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } + default: + break + } + } + private func getClusterAnnotationView(cluster: MKClusterAnnotation) -> MKAnnotationView { let id = "mapkit.cluster" self.mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: id) diff --git a/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift b/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift index f6cebcf..67a73b3 100644 --- a/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift +++ b/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift @@ -262,27 +262,6 @@ extension MapKitViewHost: MKMapViewDelegate { self.flutterApi.onCameraMoveStarted { _ in } } - // Annotation drag lifecycle. - public func mapView(_ mapView: MKMapView, - annotationView view: MKAnnotationView, - didChange newState: MKAnnotationView.DragState, - fromOldState oldState: MKAnnotationView.DragState) { - guard let annotation = view.annotation as? FlutterAnnotation else { return } - let id = annotation.id - let coordinate = PlatformCoordinate.from(annotation.coordinate) - switch newState { - case .starting: - self.flutterApi.onAnnotationDragStart(annotationId: id, coordinate: coordinate) { _ in } - case .dragging: - self.flutterApi.onAnnotationDrag(annotationId: id, coordinate: coordinate) { _ in } - case .ending, .canceling: - annotation.wasDragged = true - self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } - default: - break - } - } - public func mapViewDidFailLoadingMap(_ mapView: MKMapView, withError error: Error) { self.flutterApi.onDidFailLoadingMap(error: error.localizedDescription) { _ in } }