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

Commit

Permalink
[ios] keep callout view open when panning
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni committed Nov 16, 2016
1 parent 7e6d8db commit 3511e71
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4539,13 +4539,6 @@ - (void)notifyMapChange:(mbgl::MapChange)change
case mbgl::MapChangeRegionWillChange:
case mbgl::MapChangeRegionWillChangeAnimated:
{
if ( ! _userLocationAnnotationIsSelected
|| self.userTrackingMode == MGLUserTrackingModeNone
|| self.userTrackingState != MGLUserTrackingStateChanged)
{
[self deselectAnnotation:self.selectedAnnotation animated:NO];
}

if ( ! [self isSuppressingChangeDelimiters] && [self.delegate respondsToSelector:@selector(mapView:regionWillChangeAnimated:)])
{
BOOL animated = change == mbgl::MapChangeRegionWillChangeAnimated;
Expand Down Expand Up @@ -4713,6 +4706,36 @@ - (void)updateAnnotationViews
if (annotationView)
{
annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self];
// Pin the callout view to the view annotation
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
if (calloutView && calloutView.representedObject == annotationContext.annotation) {
CGPoint point = annotationView.center;
point.y -= annotationView.bounds.size.height/2.0f;
if ( ! CGPointEqualToPoint(calloutView.center, point))
{
calloutView.center = point;
}
}
} else {
// Pin the callout view to the gl annotation
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
if (calloutView && calloutView.representedObject == annotationContext.annotation) {
NSObject<MGLAnnotation> *annotation = annotationContext.annotation;
BOOL implementsImageForAnnotation = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)];
if (implementsImageForAnnotation) {
MGLAnnotationImage *image = [self.delegate mapView:self imageForAnnotation:annotation];
if (!image)
{
image = [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName];
}
if (image)
{
CGPoint point = [self convertCoordinate:annotation.coordinate toPointToView:self];
point.y -= image.image.size.height/2.0f;
calloutView.center = point;
}
}
}
}
}

Expand Down

0 comments on commit 3511e71

Please sign in to comment.