summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2017-06-01 10:53:02 -0700
committerGitHub <noreply@github.com>2017-06-01 10:53:02 -0700
commit012e88cc9b069f62824d9072ca3ede6a3c37d04b (patch)
tree98a42c744598ca3930dcaee8f01dfdab410544d3 /platform/ios/src
parentb2f277ac620cc41883dad8e06bb45458c18ffe72 (diff)
downloadqtlocation-mapboxgl-012e88cc9b069f62824d9072ca3ede6a3c37d04b.tar.gz
[ios] Make annotation view rotation alignment configurable (#9147)
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).
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLAnnotationView.h13
-rw-r--r--platform/ios/src/MGLAnnotationView.mm24
2 files changed, 37 insertions, 0 deletions
diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h
index 9b17f05a6e..2802d31b05 100644
--- a/platform/ios/src/MGLAnnotationView.h
+++ b/platform/ios/src/MGLAnnotationView.h
@@ -171,6 +171,19 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationViewDragState) {
*/
@property (nonatomic, assign) BOOL scalesWithViewingDistance;
+/**
+ A Boolean value that determines whether the annotation view rotates together
+ with the map.
+
+ When the value of this property is `YES` and the map is rotated, the annotation
+ view rotates. This is also the behavior of `MGLAnnotationImage` objects. When the
+ value of this property is `NO` the annotation has its rotation angle fixed.
+
+ 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;
+
#pragma mark Managing the Selection State
/**
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
index 78e38f10cb..94d0649413 100644
--- a/platform/ios/src/MGLAnnotationView.mm
+++ b/platform/ios/src/MGLAnnotationView.mm
@@ -11,6 +11,7 @@
@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;
@@ -53,6 +54,7 @@
_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"];
@@ -66,6 +68,7 @@
[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"];
@@ -109,6 +112,7 @@
super.center = center;
[self updateScaleTransformForViewingDistance];
+ [self updateRotateTransform];
}
- (void)setScalesWithViewingDistance:(BOOL)scalesWithViewingDistance
@@ -157,6 +161,26 @@
}
}
+- (void)setRotatesToMatchCamera:(BOOL)rotatesToMatchCamera
+{
+ if (_rotatesToMatchCamera != rotatesToMatchCamera)
+ {
+ _rotatesToMatchCamera = rotatesToMatchCamera;
+ [self updateRotateTransform];
+ }
+}
+
+- (void)updateRotateTransform
+{
+ if (self.rotatesToMatchCamera == NO) return;
+
+ CGFloat directionRad = self.mapView.direction * M_PI / 180.0;
+ CATransform3D newRotateTransform = CATransform3DMakeRotation(-directionRad, 0, 0, 1);
+ self.layer.transform = CATransform3DConcat(CATransform3DIdentity, newRotateTransform);
+
+ _lastAppliedRotateTransform = newRotateTransform;
+}
+
#pragma mark - Draggable
- (void)setDraggable:(BOOL)draggable