From 9bdd765a02de75851a00ab85223d5d582a104757 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 31 Jul 2018 14:21:47 -0700 Subject: [core] Merge DataDrivenPropertyValue into PropertyValue (#12513) --- platform/darwin/src/MGLStyleValue_Private.h | 47 +++++++++++------------------ 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'platform/darwin/src/MGLStyleValue_Private.h') diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index d6e2edf3eb..75e422fb45 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -10,14 +10,10 @@ #import "MGLConversion.h" #include #include -#include #include #import #import - -#include - #include #if TARGET_OS_IPHONE @@ -39,20 +35,13 @@ id MGLJSONObjectFromMBGLExpression(const mbgl::style::expression::Expression &mb template class MGLStyleValueTransformer { public: - + /// Convert an mbgl property value into an mgl style value NSExpression *toExpression(const mbgl::style::PropertyValue &mbglValue) { PropertyExpressionEvaluator evaluator; return mbglValue.evaluate(evaluator); } - - /// Convert an mbgl data driven property value into an mgl style value - template - NSExpression *toExpression(const mbgl::style::DataDrivenPropertyValue &mbglValue) { - PropertyExpressionEvaluator evaluator; - return mbglValue.evaluate(evaluator); - } - + // Convert an mbgl heatmap color property value into an mgl style value NSExpression *toExpression(const mbgl::style::ColorRampPropertyValue &mbglValue) { if (mbglValue.isUndefined()) { @@ -66,11 +55,11 @@ public: */ template typename std::enable_if_t::value, - MBGLValue> toPropertyValue(NSExpression *expression) { + MBGLValue> toPropertyValue(NSExpression *expression, bool allowDataExpressions) { if (!expression) { return {}; } - + if (expression.expressionType == NSConstantValueExpressionType) { MBGLType mbglValue; getMBGLValue(expression.constantValue, mbglValue); @@ -81,21 +70,21 @@ public: getMBGLValue(expression.collection, mbglValue); return mbglValue; } - + NSArray *jsonExpression = expression.mgl_jsonExpressionObject; - + mbgl::style::conversion::Error valueError; auto value = mbgl::style::conversion::convert( - mbgl::style::conversion::makeConvertible(jsonExpression), valueError, false); + mbgl::style::conversion::makeConvertible(jsonExpression), valueError, allowDataExpressions, false); if (!value) { [NSException raise:NSInvalidArgumentException format:@"Invalid property value: %@", @(valueError.message.c_str())]; return {}; } - + return *value; } - + /** Converts an NSExpression to an mbgl property value. */ @@ -105,9 +94,9 @@ public: if (!expression) { return {}; } - + NSArray *jsonExpression = expression.mgl_jsonExpressionObject; - + mbgl::style::conversion::Error valueError; auto value = mbgl::style::conversion::convert( mbgl::style::conversion::makeConvertible(jsonExpression), valueError); @@ -116,12 +105,12 @@ public: format:@"Invalid property value: %@", @(valueError.message.c_str())]; return {}; } - + return *value; } private: // Private utilities for converting from mgl to mbgl values - + /** As hack to allow converting enum => string values, we accept a second, dummy parameter in the toRawStyleSpecValue() methods for converting 'atomic' (non-style-function) values. @@ -143,7 +132,7 @@ private: // Private utilities for converting from mgl to mbgl values // noop pass-through plain NSObject-based items return rawMGLValue; } - + template ::value>::type, typename MGLEnum = ObjCEnum, @@ -153,7 +142,7 @@ private: // Private utilities for converting from mgl to mbgl values [rawValue getValue:&mglEnum]; return @(mbgl::Enum::toString(mglEnum)); } - + NSObject* toRawStyleSpecValue(MGLColor *color, MBGLType &mbglValue) { return @(color.mgl_color.stringify().c_str()); } @@ -216,7 +205,7 @@ private: // Private utilities for converting from mgl to mbgl values mbglValue.push_back(mbglElement); } } - + void getMBGLValue(NSValue *rawValue, mbgl::style::Position &mbglValue) { auto spherical = rawValue.mgl_lightPositionArrayValue; mbgl::style::Position position(spherical); @@ -284,7 +273,7 @@ private: // Private utilities for converting from mbgl to mgl values } return array; } - + static NSValue *toMGLRawStyleValue(const mbgl::style::Position &mbglStopValue) { std::array spherical = mbglStopValue.getSpherical(); MGLSphericalPosition position = MGLSphericalPositionMake(spherical[0], spherical[1], spherical[2]); @@ -322,7 +311,7 @@ private: // Private utilities for converting from mbgl to mgl values } return [NSExpression expressionForConstantValue:constantValue]; } - + template ::value>::type, typename MGLEnum = ObjCEnum, -- cgit v1.2.1