views:

136

answers:

1

I have a UIScrollView backed by a CATiledLayer. The layer is pulling tiles from a server and displaying them in response to what is requested when drawLayer:inContext is called. Here's what it looks like:

-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
    ASIHTTPRequest *mapRequest;
    WMSServer *root = self.mapLayer.parentServer;
    while(root == nil){
        root = self.mapLayer.parentLayer.parentServer;
    }
    //Get where we're drawing
    CGRect clipBox = CGContextGetClipBoundingBox(ctx);
    double minX = CGRectGetMaxY(clipBox);
    double minY = CGRectGetMinX(clipBox);
    double maxX = CGRectGetMinY(clipBox);
    double maxY = CGRectGetMaxX(clipBox);

    //URL for the request made here using the min/max values from above
    NSURL *url = [[NSURL alloc] initWithString:path];
    mapRequest = [ASIHTTPRequest requestWithURL:url];
    [url release];
    [mapRequest startSynchronous];
    //Wait for it to come back...
    //Turn the Data into an image
    NSData *response = [mapRequest responseData];
    //Create the entire image
    CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)response);
    CGImageRef image = CGImageCreateWithPNGDataProvider(dataProvider, NULL, true, kCGRenderingIntentDefault);
    CGDataProviderRelease(dataProvider);
    //Now paint the PNG on the context
    CGContextDrawImage(ctx, clipBox, image);
}

The problem occurs when I zoom in. The size of the tiles (as indicated by the clipBox rectangle) shrinks down, and if it's at say, 32 by 32 pixels, the URL is properly formed for 32pixels, but what is displayed on the screen scaled up to the default tileSize (128 by 128 pixels in this case). Is there some way I can get the layer to properly draw these images.

A: 

Found it. Get the CGAffineTransform with CGContextGetCTM(CGContextRef), and use the value of the a (or b) property as the zoom. Get the image in a screen res that is the zoomed appropriately (multiply the height and width by the zoom). Then draw that image into the clip box.

paxswill