From 901c806916deb30affa7a8a2884069cd28dba4ca Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Sun, 8 Jan 2017 12:53:23 -0800 Subject: [PATCH] [ios] Only use non nil presentationLayers to adjust annotation views (#7626) Views that are added outside of the viewport do not always have an instantiated presentationLayer. Attempting to use a nil presentationLayer to move a view offscreen resulted in the view being pinned to the left side of the view port (at x == 0). --- platform/ios/src/MGLMapView.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index b01ab09fb..6b59ad846 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4797,7 +4797,12 @@ public: else { CGRect adjustedFrame = annotationView.frame; - adjustedFrame.origin.x = CGRectGetWidth(annotationView.layer.presentationLayer.frame) * -2.0; + if (annotationView.layer.presentationLayer) { + adjustedFrame.origin.x = -CGRectGetWidth(annotationView.layer.presentationLayer.frame) * 10.0; + } else { + // views that are added off screen do not have a presentationLayer + adjustedFrame.origin.x = -CGRectGetWidth(adjustedFrame) * 10.0; + } annotationView.frame = adjustedFrame; [self enqueueAnnotationViewForAnnotationContext:annotationContext]; }