Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Make annotation view rotation alignment configurable #8308

Closed
wants to merge 4 commits into from
Closed

Make annotation view rotation alignment configurable #8308

wants to merge 4 commits into from

Conversation

eimantas
Copy link
Contributor

@eimantas eimantas commented Mar 8, 2017

This PR adds rotatesWithMap property to MGLAnnotationView. This
property, when set to YES fixes the annotation to a map such that view
follows map's rotation angle. This is useful when user wants to display
rotation-dependent annotations (e.g. sector lights).

Defaults to NO. Encoded.

This commit adds `rotatesWithMap` property on `MGLAnnotationView`. This
property, when set to `YES` fixes the annotation to a map such that view
follows map's rotation angle. This is useful when user wants to display
rotation-dependent annotations (e.g. sector lights).

Defaults to `NO`. Encoded.
@mention-bot
Copy link

@eimantas, thanks for your PR! By analyzing this pull request, we identified @1ec5, @boundsj and @incanus to be potential reviewers.

@eimantas eimantas changed the title Implement rotatesWithMap [iOS, macOS] Implement rotatesWithMap Mar 8, 2017
@eimantas eimantas changed the title [iOS, macOS] Implement rotatesWithMap [ios, macos] Implement rotatesWithMap Mar 8, 2017
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to #5245. Synchronizing the rotation on its own, as this PR does, is a more manageable slice of the problem. However, the visual effect when the map is tilted is still poor unless we expose a usable transform matrix to SDK code. Perhaps that shouldn't block this feature, since we've had no movement on the grander feature in #5245 for some time.

The default value of this property is `NO`. Set this property to `YES` if the
view’s rotation is important.
*/
@property (nonatomic, assign) BOOL rotatesWithMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5245 at one point called this property rotatesToMatchCamera, which I think would do a better job of describing exactly what it does. (After all, technically you could rotate the MGLMapView itself in 3D space! 😂)

@eimantas
Copy link
Contributor Author

eimantas commented Mar 8, 2017

I actually spent some time trying to match the tilting too, but didn't manage to get the transform matrix calculations right so just came with this simple implementation since that was enough for the project I was working on (no tilting was enabled on the map).

The exposed transform from core to sdk would definitely make things easier.

@1ec5 1ec5 added annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS labels Mar 8, 2017
@1ec5 1ec5 changed the title [ios, macos] Implement rotatesWithMap Make annotation view rotation alignment configurable Mar 8, 2017
@@ -141,6 +141,19 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) {
*/
@property (nonatomic, assign) BOOL scalesWithViewingDistance;

/**
A Boolean value that determines whether the annotation view rotates together
with the mapview.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: replace “mapview” with “map”, since the direction property reflects the rotation of the content within the map view, not the map view itself.

}
}

- (void)updateRotateTransform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this method only gets called when rotatesToMatchCamera is set explicitly by application code. But the annotation view’s transform matrix is always overridden whenever the map viewport changes. -updateScaleTransformForViewingDistance gets called by -setCenter:, which coincidentally happens to be the method that -[MGLMapView update AnnotationViews] calls to clobber reposition the annotation view to match the map. We could merge this method and -updateScaleTransformForViewingDistance into an -updateTransform method that comes up with the canonical transform to apply.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I was copy-pasting the code from my private repository that was used with the project. Forgot to add the call to [self updateRotateTransform]; from setCenter.

The default value of this property is `NO`. Set this property to `YES` if the
view’s rotation is important.
*/
@property (nonatomic, assign) BOOL rotatesToMatchCamera;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change. FYI, I was torn between suggesting rotatesToMatchCamera and suggesting a rotationAlignment property of type MGLIconRotationAlignment, for consistency with MGLSymbolStyleLayer. But I think a Boolean rotatesToMatchCamera will end up being more intuitive for developers, since we have no need to support an “auto” value here.

@eimantas
Copy link
Contributor Author

I guess this won't make it to 3.5.0?

@1ec5
Copy link
Contributor

1ec5 commented Mar 14, 2017

Unfortunately, we’re unable to take additional features for v3.5.0 due to the condensed schedule for that release, but I put this PR on the v3.6.0 milestone to make sure it doesn’t fall off our radar.

@1ec5 1ec5 added this to the ios-v3.6.0 milestone Mar 14, 2017
@boundsj boundsj added this to iOS-v3.6.0 Backlog in iOS SDK v3.6.0 tracking Mar 28, 2017
@boundsj boundsj moved this from iOS-v3.6.0 Backlog to iOS-v3.6.0 In Progress in iOS SDK v3.6.0 tracking Mar 28, 2017
@boundsj boundsj moved this from iOS-v3.6.0 In Progress to In Review in iOS SDK v3.6.0 tracking May 10, 2017
@boundsj
Copy link
Contributor

boundsj commented May 27, 2017

@eimantas @1ec5

This PR is in a strange state where GitHub seems to think the fork has been deleted (see from unknown repository above) but I don't think that is actually the case.

I just rebased on top of the release-ios-v3.6.0-android-v5.1.0 branch and added 10c4acb to fix an issue I was seeing where, after the transform was applied, the view frame became <MBXAnnotationView: 0x7fe22cc6e380; frame = (-8.98847e+307 -8.98847e+307; 1.79769e+308 1.79769e+308); -- this caused a crash when the map view tried to move the annotation view when a user panned the map.

After my commit (10c4acb), the behavior looks like the gif below which I think is what we want.

rotating_annotations

I'd like to get another round of review on this and merge it next week. However, with the PR in the state it is in now, I think I may need to redo all of these changes in a new PR or @eimantas might need to resubmit the PR from a new fork.

@boundsj
Copy link
Contributor

boundsj commented May 30, 2017

Continuing in #9147

@boundsj boundsj closed this May 30, 2017
@boundsj boundsj removed this from In Review in iOS SDK v3.6.0 tracking May 30, 2017
@boundsj boundsj removed this from the ios-v3.6.0 milestone Jun 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants