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

Don't deselect annotations on pan/zoom, even if the annotation moves out of the visible bounds #8022

Merged
merged 1 commit into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574))
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
* Added a method to MGLMapViewDelegate, `-mapView:shouldChangeFromCamera:toCamera:`, that you can implement to restrict which parts the user can navigate to using gestures. ([#5584](https://github.com/mapbox/mapbox-gl-native/pull/5584))
* Annotations are no longer deselected when the map is panned or zoomed, even if the annotation moves out of the visible bounds. ([#8022](https://github.com/mapbox/mapbox-gl-native/pull/8022))

## 3.4.1 - January 25, 2017

Expand Down
27 changes: 6 additions & 21 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,11 @@ - (MGLAnnotationView *)annotationViewForAnnotation:(id<MGLAnnotation>)annotation

if (annotationView)
{
// Make sure that the annotation views are selected/deselected correctly because
// annotations are not dismissed when they move out of the visible bounds
BOOL isViewForSelectedAnnotation = self.selectedAnnotation == annotation;
[annotationView setSelected:isViewForSelectedAnnotation];

annotationView.annotation = annotation;
annotationView.mapView = self;
CGRect bounds = UIEdgeInsetsInsetRect({ CGPointZero, annotationView.frame.size }, annotationView.alignmentRectInsets);
Expand Down Expand Up @@ -4710,30 +4715,10 @@ - (void)notifyMapChange:(mbgl::MapChange)change
&& calloutView.dismissesAutomatically);
// dismissesAutomatically is an optional property and we want to dismiss
// the callout view if it's unimplemented.
if (dismissesAutomatically || ![calloutView respondsToSelector:@selector(dismissesAutomatically)])
if (dismissesAutomatically || (calloutView && ![calloutView respondsToSelector:@selector(dismissesAutomatically)]))
{
[self deselectAnnotation:self.selectedAnnotation animated:NO];
}
else
{
// Deselect annotation if it lies outside the viewport
if (self.selectedAnnotation) {
MGLAnnotationTag tag = [self annotationTagForAnnotation:self.selectedAnnotation];
MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(tag);
MGLAnnotationView *annotationView = annotationContext.annotationView;

CGRect rect = [self positioningRectForCalloutForAnnotationWithTag:tag];

if (annotationView)
{
rect = annotationView.frame;
}

if ( ! CGRectIntersectsRect(rect, self.frame)) {
[self deselectAnnotation:self.selectedAnnotation animated:NO];
}
}
}
}

if ( ! [self isSuppressingChangeDelimiters] && [self.delegate respondsToSelector:@selector(mapView:regionWillChangeAnimated:)])
Expand Down