Skip to content

Commit 34c5e7d

Browse files
committed
Merge branch 'pr/47'
2 parents 9f96365 + c796ce8 commit 34c5e7d

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
## 1.2.1
33
* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated
44

5+
## 1.3.0
6+
7+
* Animate marker position changes instead of removing and re-adding
58
## 1.2.0
69

710
* Added a `markerAnnotationWithHue()` and `pinAnnotationWithHue()` method to allow custom marker/pin colors

ios/Classes/Annotations/AnnotationController.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

ios/Classes/MapView/AppleMapController.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ public class AppleMapController: NSObject, FlutterPlatformView {
4848
}
4949
}
5050

51-
deinit {
52-
self.removeAllAnnotations()
53-
self.removeAllCircles()
54-
self.removeAllPolygons()
55-
self.removeAllPolylines()
56-
}
57-
5851
public func view() -> UIView {
5952
return mapView
6053
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: apple_maps_flutter
22
description: This plugin uses the Flutter platform view to display an Apple Maps widget.
3-
version: 1.2.1
3+
version: 1.3.0
44
homepage: https://luisthein.de
55
repository: https://github.com/LuisThein/apple_maps_flutter
66
issue_tracker: https://github.com/LuisThein/apple_maps_flutter/issues

0 commit comments

Comments
 (0)