diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-02 20:41:18 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2017-02-03 09:41:28 -0800 |
commit | e5c9db47931174911f0403a1f640a5ae33814b60 (patch) | |
tree | 4bde5b32540bc6cce9f360e3bfbdf781aa50b62b | |
parent | 4867db5168a11d641c27d95b2d8c242d04ece114 (diff) | |
download | qtlocation-mapboxgl-e5c9db47931174911f0403a1f640a5ae33814b60.tar.gz |
[ios, macos] Implement default value for identity functions
-rw-r--r-- | platform/darwin/src/MGLStyleValue_Private.h | 45 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleValueTests.swift | 2 |
2 files changed, 22 insertions, 25 deletions
diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 85ebc536b6..b4354d7d16 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -367,13 +367,7 @@ private: // Private utilities for converting from mgl to mbgl values }]; mbgl::style::CategoricalStops<MBGLType> categoricalStops = {stops}; mbgl::style::SourceFunction<MBGLType> sourceFunction = {sourceStyleFunction.attributeName.UTF8String, categoricalStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } @@ -387,13 +381,7 @@ private: // Private utilities for converting from mgl to mbgl values }]; mbgl::style::ExponentialStops<MBGLType> exponentialStops = {stops, (float)sourceStyleFunction.interpolationBase}; mbgl::style::SourceFunction<MBGLType> sourceFunction = {sourceStyleFunction.attributeName.UTF8String, exponentialStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } @@ -407,22 +395,27 @@ private: // Private utilities for converting from mgl to mbgl values }]; mbgl::style::IntervalStops<MBGLType> intervalStops = {stops}; mbgl::style::SourceFunction<MBGLType> sourceFunction = {sourceStyleFunction.attributeName.UTF8String, intervalStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } mbgl::style::SourceFunction<MBGLType> toMBGLIdentitySourceFunction(MGLSourceStyleFunction<ObjCType> *sourceStyleFunction) { mbgl::style::IdentityStops<MBGLType> identityStops; mbgl::style::SourceFunction<MBGLType> sourceFunction = {sourceStyleFunction.attributeName.UTF8String, identityStops}; + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } + void setDefaultMBGLValue(MGLSourceStyleFunction<ObjCType> *sourceStyleFunction, mbgl::style::SourceFunction<MBGLType> &sourceFunction) { + if (sourceStyleFunction.defaultValue) { + NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); + MBGLType mbglValue; + id mglValue = [(MGLStyleConstantValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue]; + getMBGLValue(mglValue, mbglValue); + sourceFunction.defaultValue = mbglValue; + } + } + // Bool void getMBGLValue(NSNumber *rawValue, bool &mbglValue) { mbglValue = !!rawValue.boolValue; @@ -638,9 +631,13 @@ private: // Private utilities for converting from mbgl to mgl values } id operator()(const mbgl::style::IdentityStops<MBGLType> &mbglStops) { - return [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeIdentity - stops:nil - attributeName:@(mbglFunction.property.c_str()) options:nil]; + MGLSourceStyleFunction *sourceFunction = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeIdentity + stops:nil + attributeName:@(mbglFunction.property.c_str()) options:nil]; + if (mbglFunction.defaultValue) { + sourceFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; + } + return sourceFunction; } const mbgl::style::SourceFunction<MBGLType> &mbglFunction; diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index 28ff2ec86e..066232329f 100644 --- a/platform/darwin/test/MGLStyleValueTests.swift +++ b/platform/darwin/test/MGLStyleValueTests.swift @@ -164,7 +164,7 @@ extension MGLStyleValueTests { interpolationMode: .identity, sourceStops: nil, attributeName: "size", - options: nil + options: [.defaultValue: MGLStyleValue<UIColor>(rawValue: .green)] ) circleStyleLayer.circleColor = expectedSourceIdentityValue XCTAssertEqual(circleStyleLayer.circleColor, expectedSourceIdentityValue) |