diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-10-12 15:17:57 +0300 |
---|---|---|
committer | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-12-05 11:42:31 +0100 |
commit | 440e06c1123170a9c231b4bf6c6d0160b41e0dc0 (patch) | |
tree | 3696d4be88825156ad3c35fbbae5fd1d10274b89 /platform/ios/src/MGLMapView.mm | |
parent | 36d93b747e9046da92fdf5dcf8a9d526c6d996d5 (diff) | |
download | qtlocation-mapboxgl-440e06c1123170a9c231b4bf6c6d0160b41e0dc0.tar.gz |
[ios] keep callout view open when panning
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 5c365ad87b..e6fed8639c 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4554,7 +4554,23 @@ public: || self.userTrackingMode == MGLUserTrackingModeNone || self.userTrackingState != MGLUserTrackingStateChanged) { - [self deselectAnnotation:self.selectedAnnotation animated:NO]; + // 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:)]) @@ -4653,6 +4669,7 @@ public: [self.style didChangeValueForKey:@"layers"]; } [self updateAnnotationViews]; + [self updateCalloutView]; if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { [self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:(change == mbgl::MapChangeDidFinishRenderingFrameFullyRendered)]; @@ -4788,6 +4805,36 @@ public: [CATransaction commit]; } +- (void)updateCalloutView +{ + [CATransaction begin]; + + UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation; + id <MGLAnnotation> annotation = calloutView.representedObject; + + if (calloutView && annotation) + { + MGLAnnotationTag tag = [self annotationTagForAnnotation:annotation]; + MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(tag); + MGLAnnotationView *annotationView = annotationContext.annotationView; + + CGRect rect = [self positioningRectForCalloutForAnnotationWithTag:tag]; + + if (annotationView) + { + rect = annotationView.frame; + } + + CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); + + if ( ! CGPointEqualToPoint(calloutView.center, point)) { + calloutView.center = point; + } + } + + [CATransaction commit]; +} + - (void)enqueueAnnotationViewForAnnotationContext:(MGLAnnotationContext &)annotationContext { MGLAnnotationView *annotationView = annotationContext.annotationView; |