summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-06 00:27:41 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-12-06 16:20:14 -0800
commit88f91a48ae1b237aa285038feecf5060013baad2 (patch)
tree7f547eb06f8eb25321e97e87bf24fe8f70be1d73
parente6d51c384d0015f4dfbabb1d3f15d84a0502b9ae (diff)
downloadqtlocation-mapboxgl-88f91a48ae1b237aa285038feecf5060013baad2.tar.gz
[ios, macos] Template images as style images
Convert template images to SDF icons and back when storing them as style images.
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.mm12
-rw-r--r--platform/macos/app/MapDocument.m16
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.mm4
3 files changed, 29 insertions, 3 deletions
diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm
index 4507fb6c41..e4d072e136 100644
--- a/platform/ios/src/UIImage+MGLAdditions.mm
+++ b/platform/ios/src/UIImage+MGLAdditions.mm
@@ -6,7 +6,14 @@
{
std::string png = encodePNG(spriteImage->image);
NSData *data = [[NSData alloc] initWithBytes:png.data() length:png.size()];
- return [self initWithData:data scale:spriteImage->pixelRatio];
+ if (self = [self initWithData:data scale:spriteImage->pixelRatio])
+ {
+ if (spriteImage->sdf)
+ {
+ self = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
+ }
+ }
+ return self;
}
- (std::unique_ptr<mbgl::SpriteImage>)mgl_spriteImage
@@ -28,7 +35,8 @@
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
- return std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage), float(self.scale));
+ BOOL isTemplate = self.renderingMode == UIImageRenderingModeAlwaysTemplate;
+ return std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage), float(self.scale), isTemplate);
}
@end
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index d2e6a0f810..ed33d7f089 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -675,6 +675,22 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
fillLayer.fillColor = [MGLStyleValue<NSColor *> valueWithRawValue:[NSColor greenColor]];
fillLayer.predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"type", @"park"];
[self.mapView.style addLayer:fillLayer];
+
+ NSImage *image = [NSImage imageNamed:NSImageNameIChatTheaterTemplate];
+ [self.mapView.style setImage:image forName:NSImageNameIChatTheaterTemplate];
+
+ MGLSource *streetsSource = [self.mapView.style sourceWithIdentifier:@"composite"];
+ MGLSymbolStyleLayer *theaterLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"theaters" source:streetsSource];
+ theaterLayer.sourceLayerIdentifier = @"poi_label";
+ theaterLayer.predicate = [NSPredicate predicateWithFormat:@"maki == 'theatre'"];
+ theaterLayer.iconImageName = [MGLStyleValue valueWithRawValue:NSImageNameIChatTheaterTemplate];
+ theaterLayer.iconSize = [MGLStyleValue valueWithRawValue:@2];
+ theaterLayer.iconColor = [MGLStyleValue valueWithStops:@{
+ @16.0: [MGLStyleValue valueWithRawValue:[NSColor redColor]],
+ @18.0: [MGLStyleValue valueWithRawValue:[NSColor yellowColor]],
+ @20.0: [MGLStyleValue valueWithRawValue:[NSColor blackColor]],
+ }];
+ [self.mapView.style addLayer:theaterLayer];
}
- (IBAction)dropPin:(NSMenuItem *)sender {
diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm
index dd132d0e87..9036ab24ae 100644
--- a/platform/macos/src/NSImage+MGLAdditions.mm
+++ b/platform/macos/src/NSImage+MGLAdditions.mm
@@ -8,6 +8,7 @@
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:data];
if ([self initWithSize:NSMakeSize(spriteImage->getWidth(), spriteImage->getHeight())]) {
[self addRepresentation:rep];
+ [self setTemplate:spriteImage->sdf];
}
return self;
}
@@ -23,7 +24,8 @@
mbgl::PremultipliedImage cPremultipliedImage(rep.pixelsWide, rep.pixelsHigh);
std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.size(), cPremultipliedImage.data.get());
return std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage),
- (float)(rep.pixelsWide / self.size.width));
+ (float)(rep.pixelsWide / self.size.width),
+ [self isTemplate]);
}
@end