summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLAnnotationView.mm
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2016-08-25 17:23:15 -0700
committerJustin R. Miller <incanus@codesorcery.net>2016-08-26 14:29:31 -0700
commit2501b2cc7baaf0d2f62aa19298301d066dfab0ea (patch)
tree1f04b51897d62eab8c05dfab12663d70e452971b /platform/ios/src/MGLAnnotationView.mm
parentf07f59207825206172ac8aa46a74ea797d287ce7 (diff)
downloadqtlocation-mapboxgl-2501b2cc7baaf0d2f62aa19298301d066dfab0ea.tar.gz
[ios] preserve annotation transforms during perspective scaling
Diffstat (limited to 'platform/ios/src/MGLAnnotationView.mm')
-rw-r--r--platform/ios/src/MGLAnnotationView.mm34
1 files changed, 16 insertions, 18 deletions
diff --git a/platform/ios/src/MGLAnnotationView.mm b/platform/ios/src/MGLAnnotationView.mm
index 705e55e658..c37adc5566 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, nullable) id <MGLAnnotation> annotation;
+@property (nonatomic, readwrite) CATransform3D lastAppliedScaleTransform;
@property (nonatomic, weak) UIPanGestureRecognizer *panGestureRecognizer;
@property (nonatomic, weak) UILongPressGestureRecognizer *longPressRecognizer;
@property (nonatomic, weak) MGLMapView *mapView;
@@ -24,6 +25,7 @@
self = [self initWithFrame:CGRectZero];
if (self)
{
+ _lastAppliedScaleTransform = CATransform3DIdentity;
_reuseIdentifier = [reuseIdentifier copy];
_scalesWithViewingDistance = YES;
_enabled = YES;
@@ -68,7 +70,7 @@
center.y += _centerOffset.dy;
super.center = center;
- [self updateTransform];
+ [self updateScaleTransformForViewingDistance];
}
- (void)setScalesWithViewingDistance:(BOOL)scalesWithViewingDistance
@@ -76,24 +78,14 @@
if (_scalesWithViewingDistance != scalesWithViewingDistance)
{
_scalesWithViewingDistance = scalesWithViewingDistance;
- [self updateTransform];
+ [self updateScaleTransformForViewingDistance];
}
}
-- (void)updateTransform
+- (void)updateScaleTransformForViewingDistance
{
- // Omit applying a new transformation while the view is being dragged.
- if (self.dragState == MGLAnnotationViewDragStateDragging)
- {
- return;
- }
-
- self.layer.transform = CATransform3DIdentity;
- if ( ! self.scalesWithViewingDistance)
- {
- return;
- }
-
+ if (self.scalesWithViewingDistance == NO || self.dragState == MGLAnnotationViewDragStateDragging) return;
+
CGFloat superviewHeight = CGRectGetHeight(self.superview.frame);
if (superviewHeight > 0.0) {
// Find the maximum amount of scale reduction to apply as the view's center moves from the top
@@ -115,9 +107,15 @@
// map view is 50% pitched then the annotation view should be reduced by 37.5% (.75 * .5). The
// reduction is then normalized for a scale of 1.0.
CGFloat pitchAdjustedScale = 1.0 - maxScaleReduction * pitchIntensity;
-
- CATransform3D transform = CATransform3DIdentity;
- self.layer.transform = CATransform3DScale(transform, pitchAdjustedScale, pitchAdjustedScale, 1);
+
+ // We keep track of each viewing distance scale transform that we apply. Each iteration,
+ // we can account for it so that we don't get cumulative scaling every time we move.
+ // We also avoid clobbering any existing transform passed in by the client, too.
+ CATransform3D undoOfLastScaleTransform = CATransform3DInvert(_lastAppliedScaleTransform);
+ CATransform3D newScaleTransform = CATransform3DMakeScale(pitchAdjustedScale, pitchAdjustedScale, 1);
+ CATransform3D effectiveTransform = CATransform3DConcat(undoOfLastScaleTransform, newScaleTransform);
+ self.layer.transform = CATransform3DConcat(self.layer.transform, effectiveTransform);
+ _lastAppliedScaleTransform = newScaleTransform;
}
}