@@ -14,7 +14,7 @@ extension AppleMapController: AnnotationDelegate {
1414 if let annotation: FlutterAnnotation = view. annotation as? FlutterAnnotation {
1515 self . currentlySelectedAnnotation = annotation. id
1616 if !annotation. selectedProgrammatically {
17- if !self . isAnnoationInFront ( zIndex: annotation. zIndex) {
17+ if !self . isAnnotationInFront ( zIndex: annotation. zIndex) {
1818 self . moveToFront ( annotation: annotation)
1919 }
2020 self . onAnnotationClick ( annotation: annotation)
@@ -94,7 +94,7 @@ extension AppleMapController: AnnotationDelegate {
9494 let newAnnotation = FlutterAnnotation . init ( fromDictionary: annotationData, registrar: registrar)
9595 if annotationToChange != newAnnotation {
9696 if !annotationToChange. wasDragged {
97- addAnnotation ( annotation: newAnnotation)
97+ updateAnnotation ( annotation: newAnnotation)
9898 } else {
9999 annotationToChange. wasDragged = false
100100 }
@@ -204,6 +204,26 @@ extension AppleMapController: AnnotationDelegate {
204204 self . mapView. addAnnotation ( annotation)
205205 }
206206
207+ private func updateAnnotation( annotation: FlutterAnnotation ) {
208+ if let oldAnnotation = self . getAnnotation ( with: annotation. id) {
209+ UIView . animate ( withDuration: 0.32 , animations: {
210+ oldAnnotation. coordinate = annotation. coordinate
211+ oldAnnotation. zIndex = annotation. zIndex
212+ oldAnnotation. anchor = annotation. anchor
213+ oldAnnotation. alpha = annotation. alpha
214+ oldAnnotation. isVisible = annotation. isVisible
215+ oldAnnotation. title = annotation. title
216+ oldAnnotation. subtitle = annotation. subtitle
217+ } )
218+
219+ // Update the annotation view with the new image
220+ if let view = self . mapView. view ( for: oldAnnotation) {
221+ let newAnnotationView = getAnnotationView ( annotation: annotation)
222+ view. image = newAnnotationView. image
223+ }
224+ }
225+ }
226+
207227 private func getNextAnnotationZIndex( ) -> Double {
208228 let mapViewAnnotations = self . mapView. getMapViewAnnotations ( )
209229 if mapViewAnnotations. isEmpty {
@@ -212,7 +232,7 @@ extension AppleMapController: AnnotationDelegate {
212232 return ( mapViewAnnotations. last?? . zIndex ?? 0 ) + 1
213233 }
214234
215- private func isAnnoationInFront ( zIndex: Double ) -> Bool {
235+ private func isAnnotationInFront ( zIndex: Double ) -> Bool {
216236 return ( self . mapView. getMapViewAnnotations ( ) . last?? . zIndex ?? 0 ) == zIndex
217237 }
218238
0 commit comments