@@ -4364,56 +4364,37 @@ - (void)updateAnnotationViews
4364
4364
return;
4365
4365
}
4366
4366
4367
- // Update all visible annotation views
4368
- std::set<MGLAnnotationTag> visibleTags;
4369
- std::vector<MGLAnnotationTag> annotationTags = [self annotationTagsInRect:CGRectInset(self.bounds, -_largestAnnotationViewSize.width - MGLAnnotationUpdateViewportOutset.width, -_largestAnnotationViewSize.height - MGLAnnotationUpdateViewportOutset.width)];
4370
-
4371
- for(auto const& annotationTag: annotationTags)
4367
+ for (auto &pair : _annotationContextsByAnnotationTag)
4372
4368
{
4373
- auto &annotationContext = _annotationContextsByAnnotationTag[annotationTag];
4374
- id<MGLAnnotation> annotation = annotationContext.annotation;
4369
+ CGRect viewPort = CGRectInset(self.bounds, -_largestAnnotationViewSize.width - MGLAnnotationUpdateViewportOutset.width, -_largestAnnotationViewSize.height - MGLAnnotationUpdateViewportOutset.width);
4375
4370
4371
+ MGLAnnotationContext &annotationContext = pair.second;
4372
+ MGLAnnotationView *annotationView = annotationContext.annotationView;
4376
4373
4377
- // If there is no annotation view at this point, it means the context's view was reused by some
4378
- // other context so we need to reuse or make a new view.
4379
- if (!annotationContext.annotationView)
4374
+ if (!annotationView)
4380
4375
{
4381
- MGLAnnotationView *annotationView = [self annotationViewForAnnotation:annotation];
4382
-
4376
+ MGLAnnotationView *annotationView = [self annotationViewForAnnotation:annotationContext.annotation];
4383
4377
if (annotationView)
4384
4378
{
4385
4379
// If the annotation view has no superview it means it was never used before so add it
4386
4380
if (!annotationView.superview)
4387
4381
{
4388
4382
[self.glView addSubview:annotationView];
4389
4383
}
4390
-
4384
+ annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
4391
4385
annotationContext.annotationView = annotationView;
4392
4386
}
4393
4387
}
4394
4388
4395
- annotationContext.annotationView.center = [self convertCoordinate:annotation.coordinate toPointToView:self];;
4396
- visibleTags.insert(annotationTag);
4397
- }
4398
-
4399
- // Hide and add offscreen annotation views to reuse queue
4400
- for (auto &pair : _annotationContextsByAnnotationTag)
4401
- {
4402
- MGLAnnotationTag annotationTag = pair.first;
4403
- MGLAnnotationContext &annotationContext = pair.second;
4404
- MGLAnnotationView *annotationView = annotationContext.annotationView;
4405
- const bool tagIsNotVisible = visibleTags.find(annotationTag) == visibleTags.end();
4406
-
4407
- // The call to `annotationTagsInRect:` (above) does not return the correct result when the
4408
- // map is tilted and the user is scrolling quickly. So, some annotation views get stuck in
4409
- // a limbo state where they are onscreen and put on the reuse queue. Hiding the views hides
4410
- // the bug until we fix the result of `annotationTagsInRect:`.
4411
- annotationView.hidden = tagIsNotVisible;
4412
-
4413
- if (annotationView && annotationView.reuseIdentifier && tagIsNotVisible)
4389
+ bool annotationViewIsVisible = CGRectContainsRect(viewPort, annotationView.frame);
4390
+ if (!annotationViewIsVisible)
4414
4391
{
4415
4392
[self enqueueAnnotationViewForAnnotationContext:annotationContext];
4416
4393
}
4394
+ else
4395
+ {
4396
+ annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];;
4397
+ }
4417
4398
}
4418
4399
}
4419
4400
0 commit comments