Skip to content

Instantly share code, notes, and snippets.

@Rich86man
Created May 9, 2012 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rich86man/2641246 to your computer and use it in GitHub Desktop.
Save Rich86man/2641246 to your computer and use it in GitHub Desktop.
MKOverlayView Fucntions
- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
NSURL* fileURL = [(HeatMap*)self.overlay localUrlForStyle:@"classic" withMapRect:mapRect andZoomScale:zoomScale];
if([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]])
return YES;
[(HeatMap*)self.overlay fetchFileForStyle:@"classic" withMapRect:mapRect zoomScale:zoomScale completion:^{
[self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
}];
return NO;
}
/**
* If the above method returns YES, this method performs the actual screen render
* of a particular tile.
*
* You should never perform long processing (HTTP requests, etc.) from this method
* or else your application UI will become blocked. You should make sure that
* canDrawMapRect ONLY EVER returns YES if you are positive the tile is ready
* to be rendered.
*/
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
NSURL* fileURL = [(HeatMap*)self.overlay localUrlForStyle:@"classic" withMapRect:mapRect andZoomScale:zoomScale];
NSData *imageData = [NSData dataWithContentsOfURL:fileURL ];
if (imageData != nil) {
UIImage *img = [UIImage imageWithData:imageData];
// Perform the image render on the current UI context
UIGraphicsPushContext(context);
[img drawInRect:[self rectForMapRect:mapRect] blendMode:kCGBlendModeNormal alpha:1.0];
UIGraphicsPopContext();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment