[ios] keep callout view open when panning

This commit is contained in:
Fredrik Karlsson
2016-10-12 15:17:57 +03:00
parent 36d93b747e
commit 440e06c112
2 changed files with 49 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fixed an issue preventing MGLAnnotationView from animating when its coordinate changes. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215))
* Fixed an issue causing the wrong annotation view to be selected when tapping an annotation view with a center offset applied. ([#5931](https://github.com/mapbox/mapbox-gl-native/pull/5931))
* Fixed an issue that assigned annotation views to polyline and polygon annotations. ([#5770](https://github.com/mapbox/mapbox-gl-native/pull/5770))
* Fixed an issue causing the callout view to be dismissed when panning around. ([#6676](https://github.com/mapbox/mapbox-gl-native/pull/6676))
* Per documentation, the first and last coordinates in an MGLPolygon must be identical in order for the polygon to draw correctly. The same is true for an MGLPolygon’s interior polygon. ([#5514](https://github.com/mapbox/mapbox-gl-native/pull/5514))
* To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088))
* Deprecated `-[MGLMapViewDelegate mapView:alphaForShapeAnnotation:]` in favor of specifying an alpha component via `-[MGLMapViewDelegate mapView:strokeColorForShapeAnnotation:]` or `-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]`. ([#6706](https://github.com/mapbox/mapbox-gl-native/pull/6706))

View File

@@ -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;