Skip to content

Instantly share code, notes, and snippets.

@irpainel-zz
Created July 12, 2016 20:42
Show Gist options
  • Save irpainel-zz/7c0f804e7782ac2145bfb9ce17246b6e to your computer and use it in GitHub Desktop.
Save irpainel-zz/7c0f804e7782ac2145bfb9ce17246b6e to your computer and use it in GitHub Desktop.
Customize Maps on iOS
#import "ColorBlendTileOverlayRenderer.h"
#import "Colors.h"
@implementation ColorBlendTileOverlayRenderer
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
CGRect rect = [self rectForMapRect:mapRect];
CGContextSetBlendMode(context,kCGBlendModeColor);
CGContextSetFillColorWithColor(context, [CGColor blackColor].CGColor);
CGContextFillRect(context, rect);
CGContextSetBlendMode(context,kCGBlendModeSoftLight);
CGContextSetFillColorWithColor(context, [CGColor brownColor].CGColor);
CGContextFillRect(context, rect);
}
@end
#import <MapKit/MapKit.h>
@interface CustomMapView : MKMapView <MKMapViewDelegate>
@property (strong, nonatomic) MKTileOverlay *tileOverlay;
@end
#import "CustomMapView.h"
#import "ColorBlendTileOverlayRenderer.h"
@implementation CustomMapView
-(instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.delegate = self;
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
return self;
}
-(void)awakeFromNib {
[super awakeFromNib];
[self reloadTileOverlay];
}
#pragma mark - TileOverlay
-(void)reloadTileOverlay {
// remove existing map tile overlay
if(self.tileOverlay) {
[self removeOverlay:self.tileOverlay];
}
NSString *urlTemplate = nil;
urlTemplate = @"http://mt0.google.com/vt/x={x}&y={y}&z={z}";
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:urlTemplate];
self.tileOverlay.canReplaceMapContent=YES;
[self addOverlay:self.tileOverlay];
}
@end
#import <MapKit/MapKit.h>
#import <Foundation/Foundation.h>
@interface MapRendererHelper : NSObject
+(MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay;
@end
#import "MapRendererHelper.h"
#import "ColorBlendTileOverlayRenderer.h"
@implementation MapRendererHelper
+(MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
MKTileOverlay *tileOverlay = (MKTileOverlay *)overlay;
MKTileOverlayRenderer *renderer = nil;
renderer = [[ColorBlendTileOverlayRenderer alloc] initWithTileOverlay:tileOverlay];
return renderer;
} else {
return nil;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment