Created
July 12, 2016 20:42
-
-
Save irpainel-zz/7c0f804e7782ac2145bfb9ce17246b6e to your computer and use it in GitHub Desktop.
Customize Maps on iOS
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
#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 |
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
#import <MapKit/MapKit.h> | |
@interface CustomMapView : MKMapView <MKMapViewDelegate> | |
@property (strong, nonatomic) MKTileOverlay *tileOverlay; | |
@end |
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
#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 |
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
#import <MapKit/MapKit.h> | |
#import <Foundation/Foundation.h> | |
@interface MapRendererHelper : NSObject | |
+(MKOverlayRenderer *)rendererForOverlay:(id<MKOverlay>)overlay; | |
@end |
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
#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