Skip to content

Commit d0e8f4c

Browse files
authored
Merge branch 'master' into master
2 parents 150065e + 34c5e7d commit d0e8f4c

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22

3-
## 1.2.1
3+
## 1.3.0
44

5+
* Animate marker position changes instead of removing and re-adding
6+
* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated
57
* Fixed an issue where onCameraMove was not invoked by double-tapping
68
* Added insetsLayoutMarginsFromSafeArea
79

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: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ public class AppleMapController: NSObject, FlutterPlatformView {
5454
}
5555
}
5656

57-
deinit {
58-
self.removeAllAnnotations()
59-
self.removeAllCircles()
60-
self.removeAllPolygons()
61-
self.removeAllPolylines()
62-
}
63-
6457
public func view() -> UIView {
6558
return contentView
6659
}
@@ -328,15 +321,22 @@ extension AppleMapController {
328321
snapShot?.cancel()
329322

330323
if #available(iOS 10.0, *) {
331-
snapShot?.start { [unowned self] snapshot, error in
324+
snapShot?.start { [weak self] snapshot, error in
325+
guard let self = self else {
326+
return
327+
}
328+
332329
guard let snapshot = snapshot, error == nil else {
333330
onCompletion(nil, error)
334331
return
335332
}
336-
337-
let image = UIGraphicsImageRenderer(size: self.snapShotOptions.size).image { context in
333+
334+
let image = UIGraphicsImageRenderer(size: self.snapShotOptions.size).image { [weak self] context in
335+
guard let self = self else {
336+
return
337+
}
338338
snapshot.image.draw(at: .zero)
339-
let rect = snapShotOptions.mapRect
339+
let rect = self.snapShotOptions.mapRect
340340
if options.showAnnotations {
341341
for annotation in self.mapView.getMapViewAnnotations() {
342342
self.drawAnnotations(annotation: annotation, point: snapshot.point(for: annotation!.coordinate))

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)