Skip to content

Commit

Permalink
Merge branch 'pr/47'
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisThein committed Jan 25, 2024
2 parents 9f96365 + c796ce8 commit 34c5e7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions ios/Classes/Annotations/AnnotationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
7 changes: 0 additions & 7 deletions ios/Classes/MapView/AppleMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ public class AppleMapController: NSObject, FlutterPlatformView {
}
}

deinit {
self.removeAllAnnotations()
self.removeAllCircles()
self.removeAllPolygons()
self.removeAllPolylines()
}

public func view() -> UIView {
return mapView
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 34c5e7d

Please sign in to comment.