Add anchorPoint
to ViewMapAnnotation
#53
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This builds on #48, since I also needed those attributes to help control how my markers cluster. If #48 gets merged first, this PR will be slightly easier to review.
I originally tried just adding
anchorPoint
toViewMapAnnotation
and passing it through to theMKMapAnnotationView
(usingUIView
'sanchorPoint
if available, otherwise falling back oncenterOffset
), but the anchor point wasn't applying correctly.I borrowed from @allenhumphreys PR #40 to get the frame and the anchor point to apply correctly. I wasn't sure if that PR was ever going to get merged; I took the minimum changes necessary to get anchor point working in hopes of getting this PR merged.
I also looked at ideas in #38, which seems somewhat related. This could potentially fix #14 as well; I've noticed that my pins have a much more consistent location now during zoom/pan and seem to be anchored properly in the correct location.
My first pass made anchorPoint a
CGPoint
, but I decided it would be better to useUnitPoint
as that's more SwiftUI-y. I can change it back toCGPoint
if you prefer.FWIW, I'm using this branch successfully in an iOS app, and I have pin-style markers. Setting
anchorPoint: .bottom
(the bottom middle of the marker) keeps the pins in the correct location as the user moves the map around in my app.