summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyle.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLStyle.mm')
-rw-r--r--platform/darwin/src/MGLStyle.mm26
1 files changed, 23 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 56dc4ad8f7..99d6ca89b6 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -482,19 +482,39 @@ static NSURL *MGLStyleURL_emerald;
- (void)setImage:(MGLImage *)image forName:(NSString *)name
{
- NSAssert(image, @"image is null");
- NSAssert(name, @"name is null");
+ if (!image) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Cannot assign nil image to “%@”.", name];
+ }
+ if (!name) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Cannot assign image %@ to a nil name.", image];
+ }
self.mapView.mbglMap->addImage([name UTF8String], image.mgl_spriteImage);
}
- (void)removeImageForName:(NSString *)name
{
- NSAssert(name, @"name is null");
+ if (!name) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Cannot remove image with nil name."];
+ }
self.mapView.mbglMap->removeImage([name UTF8String]);
}
+- (MGLImage *)imageForName:(NSString *)name
+{
+ if (!name) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Cannot get image with nil name."];
+ }
+
+ auto spriteImage = self.mapView.mbglMap->getImage([name UTF8String]);
+ return spriteImage ? [[MGLImage alloc] initWithMGLSpriteImage:spriteImage] : nil;
+}
+
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p; name = %@, URL = %@>",