summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-02-10 17:44:06 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-02-18 14:42:16 -0800
commit8669f933fdaf957253d7ec6b7453b95e93adc1b1 (patch)
tree21d0e024a384a6fb110d500129394b52c1460b53 /platform/darwin/src/NSExpression+MGLAdditions.mm
parent65b42949c77b4e86db7bf51055e09e160d5a58a1 (diff)
downloadqtlocation-mapboxgl-8669f933fdaf957253d7ec6b7453b95e93adc1b1.tar.gz
[ios, macos] Convert NSColor/UIColor expressions to CSS color string values
When converting a constant NSExpression to an mbgl::Value, turn an NSColor or UIColor into an std::string containing a CSS color string. This allows developers to set an attribute of an MGLFeature to an NSColor or UIColor (rather than a CSS color string, which would be foreign), then use it in an MGLStyleFunction with identity interpolation.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm10
1 files changed, 10 insertions, 0 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index c54102b8c9..a7759cda9d 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1,5 +1,12 @@
#import "NSExpression+MGLAdditions.h"
+#import "MGLTypes.h"
+#if TARGET_OS_IPHONE
+ #import "UIColor+MGLAdditions.h"
+#else
+ #import "NSColor+MGLAdditions.h"
+#endif
+
@implementation NSExpression (MGLAdditions)
- (std::vector<mbgl::Value>)mgl_aggregateMBGLValue {
@@ -56,6 +63,9 @@
// We use long long here to avoid any truncation.
return { (int64_t)number.longLongValue };
}
+ } else if ([value isKindOfClass:[MGLColor class]]) {
+ auto hexString = [(MGLColor *)value mgl_color].stringify();
+ return { hexString };
} else if (value && value != [NSNull null]) {
[NSException raise:NSInvalidArgumentException
format:@"Can’t convert %s:%@ to mbgl::Value", [value objCType], value];