diff --git a/CHANGELOG.md b/CHANGELOG.md index 407183b..be5d8b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.2.1 * Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated +## 1.3.0 + +* Animate marker position changes instead of removing and re-adding ## 1.2.0 * Added a `markerAnnotationWithHue()` and `pinAnnotationWithHue()` method to allow custom marker/pin colors diff --git a/ios/Classes/Annotations/AnnotationController.swift b/ios/Classes/Annotations/AnnotationController.swift index 735e1c5..09bf6b2 100644 --- a/ios/Classes/Annotations/AnnotationController.swift +++ b/ios/Classes/Annotations/AnnotationController.swift @@ -14,7 +14,7 @@ extension AppleMapController: AnnotationDelegate { if let annotation: FlutterAnnotation = view.annotation as? FlutterAnnotation { self.currentlySelectedAnnotation = annotation.id if !annotation.selectedProgrammatically { - if !self.isAnnoationInFront(zIndex: annotation.zIndex) { + if !self.isAnnotationInFront(zIndex: annotation.zIndex) { self.moveToFront(annotation: annotation) } self.onAnnotationClick(annotation: annotation) @@ -94,7 +94,7 @@ extension AppleMapController: AnnotationDelegate { let newAnnotation = FlutterAnnotation.init(fromDictionary: annotationData, registrar: registrar) if annotationToChange != newAnnotation { if !annotationToChange.wasDragged { - addAnnotation(annotation: newAnnotation) + updateAnnotation(annotation: newAnnotation) } else { annotationToChange.wasDragged = false } @@ -204,6 +204,26 @@ extension AppleMapController: AnnotationDelegate { self.mapView.addAnnotation(annotation) } + private func updateAnnotation(annotation: FlutterAnnotation) { + if let oldAnnotation = self.getAnnotation(with: annotation.id) { + UIView.animate(withDuration: 0.32, animations: { + oldAnnotation.coordinate = annotation.coordinate + oldAnnotation.zIndex = annotation.zIndex + oldAnnotation.anchor = annotation.anchor + oldAnnotation.alpha = annotation.alpha + oldAnnotation.isVisible = annotation.isVisible + oldAnnotation.title = annotation.title + oldAnnotation.subtitle = annotation.subtitle + }) + + // Update the annotation view with the new image + if let view = self.mapView.view(for: oldAnnotation) { + let newAnnotationView = getAnnotationView(annotation: annotation) + view.image = newAnnotationView.image + } + } + } + private func getNextAnnotationZIndex() -> Double { let mapViewAnnotations = self.mapView.getMapViewAnnotations() if mapViewAnnotations.isEmpty { @@ -212,7 +232,7 @@ extension AppleMapController: AnnotationDelegate { return (mapViewAnnotations.last??.zIndex ?? 0) + 1 } - private func isAnnoationInFront(zIndex: Double) -> Bool { + private func isAnnotationInFront(zIndex: Double) -> Bool { return (self.mapView.getMapViewAnnotations().last??.zIndex ?? 0) == zIndex } diff --git a/ios/Classes/MapView/AppleMapController.swift b/ios/Classes/MapView/AppleMapController.swift index c072e31..9d750e0 100644 --- a/ios/Classes/MapView/AppleMapController.swift +++ b/ios/Classes/MapView/AppleMapController.swift @@ -48,13 +48,6 @@ public class AppleMapController: NSObject, FlutterPlatformView { } } - deinit { - self.removeAllAnnotations() - self.removeAllCircles() - self.removeAllPolygons() - self.removeAllPolylines() - } - public func view() -> UIView { return mapView } diff --git a/pubspec.yaml b/pubspec.yaml index b90629a..ff7ca9e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: apple_maps_flutter description: This plugin uses the Flutter platform view to display an Apple Maps widget. -version: 1.2.1 +version: 1.3.0 homepage: https://luisthein.de repository: https://github.com/LuisThein/apple_maps_flutter issue_tracker: https://github.com/LuisThein/apple_maps_flutter/issues