From 47c1e42ac1073ef02093b59336588f389f287227 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Mon, 27 Mar 2017 17:30:58 -0700 Subject: [core] implement dds for text-offset --- .../mapboxsdk/style/layers/PropertyFactory.java | 6 +-- .../mapboxsdk/testapp/style/SymbolLayerTest.java | 45 ++++++++++++++++++++++ platform/darwin/src/MGLSymbolStyleLayer.h | 18 +++++++++ platform/darwin/src/MGLSymbolStyleLayer.mm | 6 +-- platform/darwin/test/MGLSymbolStyleLayerTests.mm | 30 ++++++++++++--- 5 files changed, 93 insertions(+), 12 deletions(-) (limited to 'platform') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index bfbbf1e77b..ef0bd38b56 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -2055,11 +2055,11 @@ public class PropertyFactory { /** * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. * - * @param the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] + * @param the function input type + * @param function a wrapper function for Float[] * @return property wrapper around a Float[] function */ - public static PropertyValue> textOffset(CameraFunction function) { + public static PropertyValue> textOffset(Function function) { return new LayoutPropertyValue<>("text-offset", function); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index c90af339b1..cac950dfc4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -1454,6 +1454,51 @@ public class SymbolLayerTest extends BaseStyleTest { assertEquals(1, ((ExponentialStops) layer.getTextOffset().getFunction().getStops()).size()); } + @Test + public void testTextOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOffset(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + } + + @Test + public void testTextOffsetAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOffset( + property( + "FeaturePropertyA", + interval( + stop(1, textOffset(new Float[]{0f,0f})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + } + @Test public void testTextAllowOverlapAsConstant() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index c76efe2de7..11dc67b458 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -1026,6 +1026,15 @@ MGL_EXPORT * `MGLCameraStyleFunction` with an interpolation mode of: * `MGLInterpolationModeExponential` * `MGLInterpolationModeInterval` + * `MGLSourceStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` + * `MGLInterpolationModeIdentity` + * `MGLCompositeStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` */ @property (nonatomic, null_resettable) MGLStyleValue *textOffset; #else @@ -1047,6 +1056,15 @@ MGL_EXPORT * `MGLCameraStyleFunction` with an interpolation mode of: * `MGLInterpolationModeExponential` * `MGLInterpolationModeInterval` + * `MGLSourceStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` + * `MGLInterpolationModeIdentity` + * `MGLCompositeStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` */ @property (nonatomic, null_resettable) MGLStyleValue *textOffset; #endif diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 8441931685..6e35bf5dd2 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -763,7 +763,7 @@ namespace mbgl { - (void)setTextOffset:(MGLStyleValue *)textOffset { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer, NSValue *>().toInterpolatablePropertyValue(textOffset); + auto mbglValue = MGLStyleValueTransformer, NSValue *>().toDataDrivenPropertyValue(textOffset); self.rawLayer->setTextOffset(mbglValue); } @@ -772,9 +772,9 @@ namespace mbgl { auto propertyValue = self.rawLayer->getTextOffset(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer, NSValue *>().toStyleValue(self.rawLayer->getDefaultTextOffset()); + return MGLStyleValueTransformer, NSValue *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextOffset()); } - return MGLStyleValueTransformer, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer, NSValue *>().toDataDrivenStyleValue(propertyValue); } - (void)setTextOptional:(MGLStyleValue *)textOptional { diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index e3e473ef78..18dfa1366f 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -1158,7 +1158,7 @@ #endif ]; layer.textOffset = constantStyleValue; - mbgl::style::PropertyValue> propertyValue = { { 1, 1 } }; + mbgl::style::DataDrivenPropertyValue> propertyValue = { { 1, 1 } }; XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, @"Setting textOffset to a constant value should update text-offset."); XCTAssertEqualObjects(layer.textOffset, constantStyleValue, @@ -1175,6 +1175,29 @@ XCTAssertEqualObjects(layer.textOffset, functionStyleValue, @"textOffset should round-trip camera functions."); + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.textOffset = functionStyleValue; + + mbgl::style::ExponentialStops> exponentialStops = { {{18, { 1, 1 }}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction> { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a source function should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, functionStyleValue, + @"textOffset should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.textOffset = functionStyleValue; + + std::map> innerStops { {18, { 1, 1 }} }; + mbgl::style::CompositeExponentialStops> compositeStops { { {10.0, innerStops} }, 1.0 }; + + propertyValue = mbgl::style::CompositeFunction> { "keyName", compositeStops }; + + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a composite function should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, functionStyleValue, + @"textOffset should round-trip composite functions."); layer.textOffset = nil; @@ -1182,11 +1205,6 @@ @"Unsetting textOffset should return text-offset to the default value."); XCTAssertEqualObjects(layer.textOffset, defaultStyleValue, @"textOffset should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textOffset = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textOffset = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // text-optional -- cgit v1.2.1