summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-07-07 09:09:11 -0700
committerKonstantin Käfer <mail@kkaefer.com>2015-07-08 19:46:04 +0200
commita1c2529e33a1cade763cd7ae91ecbc1fad2262ad (patch)
tree584a2bfd0e27d0467949cb7d9de4cbaa92ed1c1b /ios
parente0384a98f7aeb3eff501a738da363eba90bb9ac8 (diff)
downloadqtlocation-mapboxgl-a1c2529e33a1cade763cd7ae91ecbc1fad2262ad.tar.gz
runtime imagery based on annotation title
Diffstat (limited to 'ios')
-rw-r--r--ios/app/MBXViewController.mm40
1 files changed, 26 insertions, 14 deletions
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index 38b49454c5..054f576d6e 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -342,32 +342,44 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
- (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;
- }
+ NSString *title = [(MGLPointAnnotation *)annotation title];
+ NSString *lastTwoCharacters = [title substringFromIndex:title.length - 2];
- static NSString *identifier = @"red_square";
-
- MGLAnnotationImage *image = [mapView dequeueReusableAnnotationImageWithIdentifier:identifier];
+ MGLAnnotationImage *image = [mapView dequeueReusableAnnotationImageWithIdentifier:lastTwoCharacters];
if ( ! image)
{
- NSLog(@"iOS: creating sprite for %p / %@", annotation, identifier);
+ NSLog(@"iOS: creating sprite for %p / '%@'", annotation, lastTwoCharacters);
+
+ CGRect rect = CGRectMake(0, 0, 20, 15);
- 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]);
+
+ CGContextSetFillColorWithColor(ctx, [[[UIColor redColor] colorWithAlphaComponent:0.75] CGColor]);
CGContextFillRect(ctx, rect);
- image = [MGLAnnotationImage annotationImageWithImage:UIGraphicsGetImageFromCurrentImageContext() reuseIdentifier:identifier];
+
+ CGContextSetStrokeColorWithColor(ctx, [[UIColor blackColor] CGColor]);
+ CGContextStrokeRectWithWidth(ctx, rect, 2);
+
+ NSAttributedString *drawString = [[NSAttributedString alloc] initWithString:lastTwoCharacters attributes:@{
+ NSFontAttributeName: [UIFont fontWithName:@"Arial-BoldMT" size:12],
+ NSForegroundColorAttributeName: [UIColor whiteColor] }];
+ CGSize stringSize = drawString.size;
+ CGRect stringRect = CGRectMake((rect.size.width - stringSize.width) / 2,
+ (rect.size.height - stringSize.height) / 2,
+ stringSize.width,
+ stringSize.height);
+ [drawString drawInRect:stringRect];
+
+ image = [MGLAnnotationImage annotationImageWithImage:UIGraphicsGetImageFromCurrentImageContext() reuseIdentifier:lastTwoCharacters];
+
UIGraphicsEndImageContext();
}
else
{
- NSLog(@"iOS: reusing sprite for %p / %@", annotation, identifier);
+ NSLog(@"iOS: reusing sprite for %p / '%@'", annotation, lastTwoCharacters);
}
return image;