Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:23:38+00:00 2026-06-13T12:23:38+00:00

I’m using a custom MKOverlay/MKOverlayView to completely cover the Google basemap with my own

  • 0

I’m using a custom MKOverlay/MKOverlayView to completely cover the Google basemap with my own tiles, which are loaded asynchronously. I follow the pattern of requesting unloaded tiles when I receive a canDrawMapRect:zoomScale: call to my overlay view (and returning FALSE in that case), then calling setNeedsDisplayInMapRect:zoomScale: once the tile is available.

This all generally works, and appears to work perfectly in the simulator.

However, on the device I sometimes get a ‘hole’ in the overlay – a missing tile.

I can see that the tile is requested, and that the request completes. I can see that I call setNeedsDisplayInMapRect:zoomScale:, and that I am passing the original MKMapRect and MKZoomScale which were provided in canDrawMapRect:zoomScale:. But I can also see that the overlay is never asked to redraw that tile (neither canDrawMapRect:zoomScale: nor drawMapRect:zoomScale:inContext: is ever again called for that tile).

I need to understand why this is happening and how to correct it.

Here’s the relevant code from my MKOverlayView subclass:

- (BOOL) canDrawMapRect: (MKMapRect) mapRect zoomScale: (MKZoomScale) zoomScale 
{
    NSUInteger zoomLevel = [self zoomLevelForZoomScale:zoomScale];
    CGPoint mercatorPoint = [self mercatorTileOriginForMapRect:mapRect];
    NSUInteger tilex = floor(mercatorPoint.x * [self worldTileWidthForZoomLevel:zoomLevel]);
    NSUInteger tiley = floor(mercatorPoint.y * [self worldTileWidthForZoomLevel:zoomLevel]);

    NSURL* tileUrl = [self tileURLForZoomLevel: zoomLevel tileX: tilex tileY: tiley];

    ASIHTTPRequest* tileRequest = [ASIHTTPRequest requestWithURL: tileUrl];
    tileRequest.downloadCache = [ASIDownloadCache sharedCache];
    [tileRequest setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

    if ( NO == [[ASIDownloadCache sharedCache] isCachedDataCurrentForRequest: tileRequest] )
    {
        [tileRequest setCachePolicy: ASIAskServerIfModifiedWhenStaleCachePolicy];
        tileRequest.delegate = self;
        tileRequest.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSValue value: &mapRect withObjCType: @encode( MKMapRect )],       @"mapRect",
                                [NSValue value: &zoomScale withObjCType: @encode( MKZoomScale )],   @"zoomScale",
                                [NSNumber numberWithInt: tilex], @"tilex",
                                [NSNumber numberWithInt: tiley], @"tiley",
                                nil];

        [_tileRequestStack addOperation: tileRequest];

        NSLog( @"canDrawMapRect: %d, %d - REQUESTING", tilex, tiley );

        return NO;
    }

    NSLog( @"canDrawMapRect: %d, %d - READY", tilex, tiley );

    return YES;
}

- (void) drawMapRect: (MKMapRect) mapRect zoomScale: (MKZoomScale) zoomScale inContext: (CGContextRef) context 
{
    NSUInteger zoomLevel = [self zoomLevelForZoomScale:zoomScale];

    CGPoint mercatorPoint = [self mercatorTileOriginForMapRect:mapRect];

    NSUInteger tilex = floor(mercatorPoint.x * [self worldTileWidthForZoomLevel:zoomLevel]);
    NSUInteger tiley = floor(mercatorPoint.y * [self worldTileWidthForZoomLevel:zoomLevel]);

    NSLog( @"drawMapRect:  %d, %d", tilex, tiley );

    NSURL* tileUrl = [self tileURLForZoomLevel: zoomLevel tileX: tilex tileY: tiley];
    NSData* tileData = [[ASIDownloadCache sharedCache] cachedResponseDataForURL: tileUrl];

    UIGraphicsPushContext(context);

    if ( tileData != nil )
    {
        UIImage* img = [UIImage imageWithData: tileData];

        if ( img != nil )
        {
            [img drawInRect: [self rectForMapRect: mapRect] blendMode: kCGBlendModeNormal alpha: 1.0 ];
        }
        else 
        {
            NSLog( @"oops - no image" );
        }

        CGSize s = CGContextConvertSizeToUserSpace( context, CGSizeMake( 40, 1 ));

        UIFont* f = [UIFont systemFontOfSize: s.width];

        [[UIColor blackColor] setFill];

        [[NSString stringWithFormat: @"%d,%d", tilex, tiley] drawInRect: [self rectForMapRect: mapRect] withFont: f];
    }

    UIGraphicsPopContext();
}


- (void) requestFinished: (ASIHTTPRequest *) tileRequest
{
    NSValue* mapRectValue =  [tileRequest.userInfo objectForKey: @"mapRect"];
    MKMapRect mapRect;  [mapRectValue getValue: &mapRect];

    NSValue *zoomScaleValue = [tileRequest.userInfo objectForKey:@"zoomScale"];
    MKZoomScale zoomScale; [zoomScaleValue getValue: &zoomScale];

    NSLog( @"requestFinished: %d, %d, %lf", 
          [[tileRequest.userInfo objectForKey:@"tilex"] intValue], 
          [[tileRequest.userInfo objectForKey:@"tiley"] intValue], 
          zoomScale  );

    [self setNeedsDisplayInMapRect: mapRect zoomScale: zoomScale];
}

EDIT: I’m guessing that this is likely the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:23:39+00:00Added an answer on June 13, 2026 at 12:23 pm

    I had an issue very similar to the one described here. In my case I couldn’t reproduce the desired behaviour (described in http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html#//apple_ref/occ/instm/MKOverlayView/setNeedsDisplayInMapRect:zoomScale🙂 even having the most simple code possible:

    - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
        NSLog(@"This should trace forever");
    
        [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
        return NO;
    }
    

    or closer to my original code:

    - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
        NSLog(@"This should trace forever");
    
        [SomeAsynchronousRequestWithCompletionHandler:^{
            [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
        }];
        return NO;
    }
    

    In both cases setNeedsDisplayInMapRect:zoomScale: has never been called even once.

    The situation changed, when I began running setNeedsDisplayInMapRect:zoomScale: inside a dispatch_async dispatched to the same queue that canDrawMapRect runs on, like:

    - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    
        dispatch_queue_t queue = dispatch_get_current_queue();
    
        NSLog(@"This should trace forever");
    
        dispatch_async(queue, ^{
            [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
        });
    
        return NO;
    }
    

    or with asynchronous job included:

    - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
        NSLog(@"This should trace forever");
    
        dispatch_queue_t queue = dispatch_get_current_queue();
    
        [SomeAsynchronousRequestWithCompletionHandler:^{
            dispatch_async(queue, ^{
                [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
            });
        }];
        return NO;
    }
    

    Using dispatch_async – I can see “This should trace forever” string being traced endlessly. My original problem is also disappeared completely.

    LATER UPDATE: Currently, I use dispatch_get_main_queue() to call setNeedsDisplayInMapRect:zoomScale: like

    - (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
        NSLog(@"This should trace forever");
    
        [SomeAsynchronousRequestWithCompletionHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
            });
        }];
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.