[ios] Fix dequeue view variable scope (#7423)

Fix a bug where an annotation view variable was incorrectly
re-declared which caused annotation views to not appear
in some cases. This also refactors the guard that spot
checks that annotation view are or are not visible.
This commit is contained in:
Jesse Bounds
2016-12-14 10:24:06 -08:00
committed by GitHub
parent 0eac5ea91e
commit afd14cbfe5

View File

@@ -4745,8 +4745,8 @@ public:
if (!annotationView)
{
// This will dequeue views if the delegate implements the dequeue call
MGLAnnotationView *annotationView = [self annotationViewForAnnotation:annotationContext.annotation];
annotationView = [self annotationViewForAnnotation:annotationContext.annotation];
if (annotationView)
{
annotationView.mapView = self;
@@ -4765,14 +4765,9 @@ public:
annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
}
}
CGPoint upperLeft = {_largestAnnotationViewSize.width,_largestAnnotationViewSize.height};
CGPoint lowerRight = {CGRectGetWidth(self.bounds) + _largestAnnotationViewSize.width,
CGRectGetHeight(self.bounds) + _largestAnnotationViewSize.height};
CLLocationCoordinate2D upperLeftCoordinate = [self convertPoint:upperLeft toCoordinateFromView:self];
CLLocationCoordinate2D lowerRightCoordinate = [self convertPoint:lowerRight toCoordinateFromView:self];
MGLCoordinateBounds coordinateBounds = [self convertRect:viewPort toCoordinateBoundsFromView:self];
// Enqueue (and move if required) offscreen annotation views
for (id<MGLAnnotation> annotation in offscreenAnnotations)
{
@@ -4795,17 +4790,16 @@ public:
// moved and the enqueue operation is avoided. This allows us to keep the performance benefit of
// using the mbgl query result. It also forces views that have just gone offscreen to be cleared
// fully from view.
if ((coordinate.latitude > upperLeftCoordinate.latitude || coordinate.latitude < lowerRightCoordinate.latitude) ||
(coordinate.longitude < upperLeftCoordinate.longitude || coordinate.longitude > lowerRightCoordinate.longitude))
if (MGLCoordinateInCoordinateBounds(coordinate, coordinateBounds))
{
CGRect adjustedFrame = annotationView.frame;
adjustedFrame.origin.x = -CGRectGetWidth(adjustedFrame) * 2.0;
annotationView.frame = adjustedFrame;
[self enqueueAnnotationViewForAnnotationContext:annotationContext];
annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
}
else
{
annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
CGRect adjustedFrame = annotationView.frame;
adjustedFrame.origin.x = CGRectGetWidth(annotationView.layer.presentationLayer.frame) * -2.0;
annotationView.frame = adjustedFrame;
[self enqueueAnnotationViewForAnnotationContext:annotationContext];
}
}
}