From e1431f9085153f7afb33ee169289ff46d38fe209 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Wed, 24 May 2017 12:20:58 -0400 Subject: [ios, macos] Fix MGLLight.achor to accept style functions --- platform/darwin/src/MGLLight.h | 4 ++-- platform/darwin/src/MGLLight.mm | 8 ++------ platform/darwin/test/MGLLightTest.mm | 12 +++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index d9a22d60fa..ef9811bd33 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -60,7 +60,7 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-anchor">anchor light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLLightAnchor anchor; +@property (nonatomic) MGLStyleValue *anchor; /** Values describing animated transitions to `anchor` property. @@ -75,7 +75,7 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-position">position light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue * position; +@property (nonatomic) MGLStyleValue *position; /** Values describing animated transitions to `position` property. diff --git a/platform/darwin/src/MGLLight.mm b/platform/darwin/src/MGLLight.mm index 02d55e76ed..262fad3b07 100644 --- a/platform/darwin/src/MGLLight.mm +++ b/platform/darwin/src/MGLLight.mm @@ -48,9 +48,7 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(anchor); } - NSAssert([anchorStyleValue isKindOfClass:[MGLConstantStyleValue class]], @"Anchor isn’t a constant."); - NSValue *anchorValue = ((MGLConstantStyleValue *)anchorStyleValue).rawValue; - _anchor = [anchorValue MGLLightAnchorValue]; + _anchor = anchorStyleValue; _anchorTransition = MGLTransitionFromOptions(mbglLight->getAnchorTransition()); @@ -89,11 +87,9 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition { mbgl::style::Light mbglLight; - MGLStyleValue *anchorType = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:self.anchor]]; - auto anchor = MGLStyleValueTransformer().toEnumPropertyValue(anchorType); + auto anchor = MGLStyleValueTransformer().toEnumPropertyValue(self.anchor); mbglLight.setAnchor(anchor); - mbglLight.setAnchorTransition(MGLOptionsFromTransition(self.anchorTransition)); auto position = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.position); diff --git a/platform/darwin/test/MGLLightTest.mm b/platform/darwin/test/MGLLightTest.mm index 4639b13cde..2c3d1c7bd1 100644 --- a/platform/darwin/test/MGLLightTest.mm +++ b/platform/darwin/test/MGLLightTest.mm @@ -25,7 +25,10 @@ { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssertEqual(mglLight.anchor, MGLLightAnchorViewport); + + NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay); XCTAssertEqual(mglLight.anchorTransition.duration, defaultTransition.duration); @@ -36,10 +39,13 @@ XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - mglLight.anchor = MGLLightAnchorMap; + MGLStyleValue *anchorStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; + mglLight.anchor = anchorStyleValue; mglLight.anchorTransition = transition; + NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(mglLight.anchor, MGLLightAnchorMap); + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay); XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration); -- cgit v1.2.1