@@ -14,7 +14,7 @@ extension AppleMapController: AnnotationDelegate {
14
14
if let annotation: FlutterAnnotation = view. annotation as? FlutterAnnotation {
15
15
self . currentlySelectedAnnotation = annotation. id
16
16
if !annotation. selectedProgrammatically {
17
- if !self . isAnnoationInFront ( zIndex: annotation. zIndex) {
17
+ if !self . isAnnotationInFront ( zIndex: annotation. zIndex) {
18
18
self . moveToFront ( annotation: annotation)
19
19
}
20
20
self . onAnnotationClick ( annotation: annotation)
@@ -94,7 +94,7 @@ extension AppleMapController: AnnotationDelegate {
94
94
let newAnnotation = FlutterAnnotation . init ( fromDictionary: annotationData, registrar: registrar)
95
95
if annotationToChange != newAnnotation {
96
96
if !annotationToChange. wasDragged {
97
- addAnnotation ( annotation: newAnnotation)
97
+ updateAnnotation ( annotation: newAnnotation)
98
98
} else {
99
99
annotationToChange. wasDragged = false
100
100
}
@@ -204,6 +204,26 @@ extension AppleMapController: AnnotationDelegate {
204
204
self . mapView. addAnnotation ( annotation)
205
205
}
206
206
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
+
207
227
private func getNextAnnotationZIndex( ) -> Double {
208
228
let mapViewAnnotations = self . mapView. getMapViewAnnotations ( )
209
229
if mapViewAnnotations. isEmpty {
@@ -212,7 +232,7 @@ extension AppleMapController: AnnotationDelegate {
212
232
return ( mapViewAnnotations. last?? . zIndex ?? 0 ) + 1
213
233
}
214
234
215
- private func isAnnoationInFront ( zIndex: Double ) -> Bool {
235
+ private func isAnnotationInFront ( zIndex: Double ) -> Bool {
216
236
return ( self . mapView. getMapViewAnnotations ( ) . last?? . zIndex ?? 0 ) == zIndex
217
237
}
218
238
0 commit comments