MKMapView does not update the overlay correctly after changing its boundingMapRect

The following is a very simple custom overlay object:

@interface Overlay : NSObject <MKOverlay> @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @property (nonatomic, assign) MKMapRect boundingMapRect; @end @implementation Overlay - (id)init { self = [super init]; if (self) { _coordinate = CLLocationCoordinate2DMake(37.78577, -122.40645); _boundingMapRect.origin = MKMapPointForCoordinate(_coordinate); _boundingMapRect.size = MKMapSizeMake(200, 200); } return self; } @end 

OverlayView is also very simple:

 @implementation OverlayView - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { Overlay* overlay = (Overlay*)[self overlay]; CGRect r = [self rectForMapRect:overlay.boundingMapRect]; CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]); CGContextSetLineWidth(context, 10); CGContextStrokeEllipseInRect(context, r); } @end 

And its boundingMapRect property is updated when a button is clicked:

 -(IBAction)onUpdateOverlayBtn:(id)sender { _overlay.boundingMapRect = MKMapRectInset(_overlay.boundingMapRect, -3000, -3000); [_overlayView setNeedsDisplayInMapRect:_overlay.boundingMapRect]; } 

The problem appears when MKMapView is enlarged (right):

screenshot

Check Xcode project on bitbucket

+4
source share

All Articles