Created
May 9, 2012 02:14
-
-
Save Rich86man/2641246 to your computer and use it in GitHub Desktop.
MKOverlayView Fucntions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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