diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 85ebc536b64..b4354d7d16c 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -367,13 +367,7 @@ class MGLStyleValueTransformer { }]; mbgl::style::CategoricalStops categoricalStops = {stops}; mbgl::style::SourceFunction sourceFunction = {sourceStyleFunction.attributeName.UTF8String, categoricalStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } @@ -387,13 +381,7 @@ class MGLStyleValueTransformer { }]; mbgl::style::ExponentialStops exponentialStops = {stops, (float)sourceStyleFunction.interpolationBase}; mbgl::style::SourceFunction sourceFunction = {sourceStyleFunction.attributeName.UTF8String, exponentialStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } @@ -407,22 +395,27 @@ class MGLStyleValueTransformer { }]; mbgl::style::IntervalStops intervalStops = {stops}; mbgl::style::SourceFunction sourceFunction = {sourceStyleFunction.attributeName.UTF8String, intervalStops}; - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLStyleConstantValue *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } mbgl::style::SourceFunction toMBGLIdentitySourceFunction(MGLSourceStyleFunction *sourceStyleFunction) { mbgl::style::IdentityStops identityStops; mbgl::style::SourceFunction sourceFunction = {sourceStyleFunction.attributeName.UTF8String, identityStops}; + setDefaultMBGLValue(sourceStyleFunction, sourceFunction); return sourceFunction; } + void setDefaultMBGLValue(MGLSourceStyleFunction *sourceStyleFunction, mbgl::style::SourceFunction &sourceFunction) { + if (sourceStyleFunction.defaultValue) { + NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant"); + MBGLType mbglValue; + id mglValue = [(MGLStyleConstantValue *)sourceStyleFunction.defaultValue rawValue]; + getMBGLValue(mglValue, mbglValue); + sourceFunction.defaultValue = mbglValue; + } + } + // Bool void getMBGLValue(NSNumber *rawValue, bool &mbglValue) { mbglValue = !!rawValue.boolValue; @@ -638,9 +631,13 @@ class MGLStyleValueTransformer { } id operator()(const mbgl::style::IdentityStops &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 &mbglFunction; diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index 28ff2ec86e0..066232329fd 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(rawValue: .green)] ) circleStyleLayer.circleColor = expectedSourceIdentityValue XCTAssertEqual(circleStyleLayer.circleColor, expectedSourceIdentityValue)