Closed alex-reilly-pronto closed 2 years ago
Hey @alex-reilly-pronto ! Thank you for your contribution!
Unfortunately, there are still some things to improve on, so here is a first feedback from my side:
MKPointAnnotation
conforms to MKAnnotation
, so you can simply use these initializers with your annotations and you are good to go. Please also do not remove the existing annotation types.Binding
, if it would actually be a two-way binding. If not, we can use a closure that gets called, whenever the camera changes or something like that. I would also propose to propagate this with the use of the environment rather than setting individual properties on the struct.Thank you once again for your contribution. Please let me know, what you think about this and whether you want to continue working on this pull request 😊
It might make sense to back up and reassess what it is I want here. I think the ideal setup would let me do something like
func truckAnnotation(annotation: TruckAnnotationModel) -> MapAnnotation {
return ViewMapAnnotation(coordinate: annotation.location.coordinate) {
ZStack {
Circle()
.foregroundColor(.indigo)
Image(systemName: "location.north.fill")
.foregroundColor(.white)
.frame(width: 20, height: 20)
}
.frame(width: 35, height: 35)
.background(Color.red)
.rotation(Angle(degrees: annotation.annotationHeading) // <- important part
}
}
But this doesn't work because the view is created exactly once when it first shows up on screen. Maybe that restriction is unnecessary and can be worked around.
Closing this out for now.
Hi! Thanks for maintaining this library. It's been a pleasure to use. I've got some annotations where I want to maintain their orientation relative to the map and move them over time, so I'm exposing the camera along with a closure that gives the user direct access to modified annotations and annotation views.
The suggested method online for changing annotation location is to use a
MKPointAnnotation
rather than anMKAnnotation
, and to alter thecoordinate
field and for changing annotation orientation is to do aCGAffineTransform
on the view itself. I'm doing both, but I'm open to something else if you've got a suggestion. It does feel like this requires developers to touch UIKit more than you'd probably like.Here's a snippet of it in action.
Here we've got the camera bound to a field in my view's state, which is being used to calculate
annotationHeading
behind the scenes.Prior to this, if an annotation was modified it wouldn't be updated because
Map.Coordinator
was only checking for inserted or removedid
s. Because of that, annotations are now required to beEquatable
so that the coordinator can check for modified annotations in addition to inserted and removed annotations.If we naively remove and then insert modified annotations, then that causes the annotation to flicker.
Breaking Changes
Equatable