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

Commit

Permalink
[ios] Do not deselect annotations any longer when map is zoomed/panne…
Browse files Browse the repository at this point in the history
…d or annotation is moved out of the visible bounds
  • Loading branch information
Ben305 committed Feb 11, 2017
1 parent b1e6232 commit a78b784
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
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

0 comments on commit a78b784

Please sign in to comment.