From b9be66f287ade7275ecc18f21a456998e4163318 Mon Sep 17 00:00:00 2001 From: Benedikt Huss Date: Fri, 10 Feb 2017 20:45:08 +0100 Subject: [ios] Do not deselect annotations any longer when map is zoomed/panned or annotation is moved out of the visible bounds --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 87b2b8c05f..c81ae31e2c 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -41,6 +41,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 diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index cc86ed1e53..77fd810e16 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3259,6 +3259,11 @@ public: 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); @@ -4710,30 +4715,10 @@ public: && 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:)]) -- cgit v1.2.1