summaryrefslogtreecommitdiff
path: root/ios/app
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-07-06 18:08:16 -0700
committerKonstantin Käfer <mail@kkaefer.com>2015-07-08 19:46:03 +0200
commit5ab58deb44de2361bf7ed943c561cb4f68fac317 (patch)
tree7f7bab297646905093908aa46ef35791e417a539 /ios/app
parent1f4b5e773634f12c00b6d6c846defc908ec79604 (diff)
downloadqtlocation-mapboxgl-5ab58deb44de2361bf7ed943c561cb4f68fac317.tar.gz
Cocoa custom marker imagery API
Diffstat (limited to 'ios/app')
-rw-r--r--ios/app/MBXViewController.mm33
1 files changed, 33 insertions, 0 deletions
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 <MGLAnnotation> __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 <MGLAnnotation>)annotation
{
return YES;