Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] Fix dequeue view variable scope #7423

Merged
merged 2 commits into from
Dec 14, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4745,8 +4745,8 @@ - (void)updateAnnotationViews
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;
Expand All @@ -4765,14 +4765,17 @@ - (void)updateAnnotationViews
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];


CGFloat largestHeight = _largestAnnotationViewSize.height;
CGFloat largestWidth = _largestAnnotationViewSize.width;
CGFloat viewHeight = CGRectGetHeight(self.frame);
CGFloat viewWidth = CGRectGetWidth(self.frame);
CLLocationCoordinate2D southwestCoordinate = [self convertPoint:{-largestWidth, viewHeight + largestHeight}
toCoordinateFromView:self];
CLLocationCoordinate2D northeastCoordinate = [self convertPoint:{viewWidth + largestWidth, -largestHeight}
toCoordinateFromView:self];
MGLCoordinateBounds coordinateBounds = {southwestCoordinate, northeastCoordinate};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code could use UIEdgeInsetsInsetRect() to apply a slop area around the map view’s bounds, then convert it using -convertRect:toCoordinateBoundsFromView:.


// Enqueue (and move if required) offscreen annotation views
for (id<MGLAnnotation> annotation in offscreenAnnotations)
{
Expand All @@ -4795,17 +4798,16 @@ - (void)updateAnnotationViews
// 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(adjustedFrame) * 10.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this formula?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the concern is that a view might have a layer that overshoots the official bounds of the view and would thus peek out from the top edge of the map view, you could perhaps move the view so that its layer.presentationLayer.frame lies outside the map view.

annotationView.frame = adjustedFrame;
[self enqueueAnnotationViewForAnnotationContext:annotationContext];
}
}
}
Expand Down