Search code examples
iosmkmapviewmkoverlay

MKMap not requesting more than 3 longitudinal tiles from OverlayRenderer


I used apples breadcrumb sample, adapted it and got to a weird effect in my code.

- (void)drawMapRect:(MKMapRect)mapRect
      zoomScale:(MKZoomScale)zoomScale
      inContext:(CGContextRef)context

is called with as many tiles as necessary to cover north to south, but it never requests more than 3 tiles east to west. So it never covers wide overlays.

Everything inside the tiles is drawn correctly etc. its the map that is simply not calling any more requests even with

- (BOOL)intersectsMapRect:(MKMapRect)mapRect {
    return YES;
}

Center coordinate is smack in the middle of the bounds.

    // init of   CrumbPath : NSObject <MKOverlay>
    upper = CLLocationCoordinate2DMake(49.0, 10.0);
    lower = CLLocationCoordinate2DMake(48.0, 5.0);

    _coordinate = CLLocationCoordinate2DMake(48.5, 7.5);

    MKMapPoint upperLeft = MKMapPointForCoordinate(upper);
    MKMapPoint lowerRight = MKMapPointForCoordinate(lower);

    _boundingMapRect = MKMapRectMake(upperLeft.x,
                                      upperLeft.y,
                                      lowerRight.x - upperLeft.x,
                                      lowerRight.y - upperLeft.y);

screenshot at https://i.sstatic.net/jgHIW.jpg


Solution

  • MapKit can NOT handle MKMapRect with negative sizes. All calculations from and to CGRects and drawing WORK but the map itself will not request the right MapRects if the size is negative as it sees them as size 0.

    So with 'abs' it will work

    _boundingMapRect = MKMapRectMake(upperLeft.x,
                                      upperLeft.y,
                                      fabs(lowerRight.x - upperLeft.x),
                                      fabs(lowerRight.y - upperLeft.y));