From 5ab58deb44de2361bf7ed943c561cb4f68fac317 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Mon, 6 Jul 2015 18:08:16 -0700 Subject: Cocoa custom marker imagery API --- ios/app/MBXViewController.mm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'ios/app') diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index 00245828ed..995ae9d448 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -340,6 +340,39 @@ mbgl::Settings_NSUserDefaults *settings = nullptr; #pragma mark - MGLMapViewDelegate +- (MGLAnnotationImage *)mapView:(MGLMapView * __nonnull)mapView imageForAnnotation:(id __nonnull)annotation +{ + if ([[((MGLPointAnnotation *)annotation) title] hasSuffix:@"7"]) + { + NSLog(@"iOS: %p annotation title ends in '7'; using default sprite", annotation); + + return nil; + } + + static NSString *identifier = @"red_square"; + + MGLAnnotationImage *image = [mapView dequeueReusableAnnotationImageWithIdentifier:identifier]; + + if ( ! image) + { + NSLog(@"iOS: creating sprite for %p / %@", annotation, identifier); + + CGRect rect = CGRectMake(0, 0, 20, 20); + UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]); + CGContextRef ctx = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(ctx, [[[UIColor redColor] colorWithAlphaComponent:0.25] CGColor]); + CGContextFillEllipseInRect(ctx, rect); + image = [MGLAnnotationImage annotationImageWithImage:UIGraphicsGetImageFromCurrentImageContext() reuseIdentifier:identifier]; + UIGraphicsEndImageContext(); + } + else + { + NSLog(@"iOS: reusing sprite for %p / %@", annotation, identifier); + } + + return image; +} + - (BOOL)mapView:(__unused MGLMapView *)mapView annotationCanShowCallout:(__unused id )annotation { return YES; -- cgit v1.2.1