-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make annotation view rotation alignment configurable #8308
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ @interface MGLAnnotationView () <UIGestureRecognizerDelegate> | |
|
||
@property (nonatomic, readwrite, nullable) NSString *reuseIdentifier; | ||
@property (nonatomic, readwrite) CATransform3D lastAppliedScaleTransform; | ||
@property (nonatomic, readwrite) CATransform3D lastAppliedRotateTransform; | ||
@property (nonatomic, weak) UIPanGestureRecognizer *panGestureRecognizer; | ||
@property (nonatomic, weak) UILongPressGestureRecognizer *longPressRecognizer; | ||
@property (nonatomic, weak) MGLMapView *mapView; | ||
|
@@ -25,8 +26,10 @@ - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier | |
if (self) | ||
{ | ||
_lastAppliedScaleTransform = CATransform3DIdentity; | ||
_lastAppliedRotateTransform = CATransform3DIdentity; | ||
_reuseIdentifier = [reuseIdentifier copy]; | ||
_scalesWithViewingDistance = YES; | ||
_rotatesToMatchCamera = NO; | ||
_enabled = YES; | ||
} | ||
return self; | ||
|
@@ -42,6 +45,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { | |
_annotation = [decoder decodeObjectOfClass:[NSObject class] forKey:@"annotation"]; | ||
_centerOffset = [decoder decodeCGVectorForKey:@"centerOffset"]; | ||
_scalesWithViewingDistance = [decoder decodeBoolForKey:@"scalesWithViewingDistance"]; | ||
_rotatesToMatchCamera = [decoder decodeBoolForKey:@"rotatesToMatchCamera"]; | ||
_selected = [decoder decodeBoolForKey:@"selected"]; | ||
_enabled = [decoder decodeBoolForKey:@"enabled"]; | ||
self.draggable = [decoder decodeBoolForKey:@"draggable"]; | ||
|
@@ -55,6 +59,7 @@ - (void)encodeWithCoder:(NSCoder *)coder { | |
[coder encodeObject:_annotation forKey:@"annotation"]; | ||
[coder encodeCGVector:_centerOffset forKey:@"centerOffset"]; | ||
[coder encodeBool:_scalesWithViewingDistance forKey:@"scalesWithViewingDistance"]; | ||
[coder encodeBool:_rotatesToMatchCamera forKey:@"rotatesToMatchCamera"]; | ||
[coder encodeBool:_selected forKey:@"selected"]; | ||
[coder encodeBool:_enabled forKey:@"enabled"]; | ||
[coder encodeBool:_draggable forKey:@"draggable"]; | ||
|
@@ -98,6 +103,7 @@ - (void)setCenter:(CGPoint)center | |
|
||
super.center = center; | ||
[self updateScaleTransformForViewingDistance]; | ||
[self updateRotateTransform]; | ||
} | ||
|
||
- (void)setScalesWithViewingDistance:(BOOL)scalesWithViewingDistance | ||
|
@@ -146,6 +152,29 @@ - (void)updateScaleTransformForViewingDistance | |
} | ||
} | ||
|
||
- (void)setRotatesToMatchCamera:(BOOL)rotatesToMatchCamera | ||
{ | ||
if (_rotatesToMatchCamera != rotatesToMatchCamera) | ||
{ | ||
_rotatesToMatchCamera = rotatesToMatchCamera; | ||
[self updateRotateTransform]; | ||
} | ||
} | ||
|
||
- (void)updateRotateTransform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, this method only gets called when There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
if (self.rotatesToMatchCamera == NO) return; | ||
|
||
CATransform3D undoOfLastRotateTransform = CATransform3DInvert(_lastAppliedRotateTransform); | ||
|
||
CGFloat directionRad = self.mapView.direction * M_PI / 180.0; | ||
CATransform3D newRotateTransform = CATransform3DMakeRotation(-directionRad, 0, 0, 1); | ||
CATransform3D effectiveTransform = CATransform3DConcat(undoOfLastRotateTransform, newRotateTransform); | ||
|
||
self.layer.transform = CATransform3DConcat(self.layer.transform, effectiveTransform); | ||
_lastAppliedRotateTransform = newRotateTransform; | ||
} | ||
|
||
#pragma mark - Draggable | ||
|
||
- (void)setDraggable:(BOOL)draggable | ||
|
There was a problem hiding this comment.
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 arotationAlignment
property of typeMGLIconRotationAlignment
, for consistency with MGLSymbolStyleLayer. But I think a BooleanrotatesToMatchCamera
will end up being more intuitive for developers, since we have no need to support an “auto” value here.