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 1c68878772b..ef89c6809ef 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 @@ -1482,11 +1482,11 @@ public static PropertyValue lineJoin(@Property.LINE_JOIN String value) { /** * The display of lines when joining. * - * @param the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String + * @param the function input type + * @param function a wrapper function for String * @return property wrapper around a String function */ - public static PropertyValue> lineJoin(CameraFunction function) { + public static PropertyValue> lineJoin(Function function) { return new LayoutPropertyValue<>("line-join", function); } @@ -2103,11 +2103,11 @@ public static PropertyValue textJustify(@Property.TEXT_JUSTIFY String va /** * Text justification options. * - * @param the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String + * @param the function input type + * @param function a wrapper function for String * @return property wrapper around a String function */ - public static PropertyValue> textJustify(CameraFunction function) { + public static PropertyValue> textJustify(Function function) { return new LayoutPropertyValue<>("text-justify", function); } @@ -2126,11 +2126,11 @@ public static PropertyValue textAnchor(@Property.TEXT_ANCHOR String valu /** * Part of the text placed closest to the anchor. * - * @param the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String + * @param the function input type + * @param function a wrapper function for String * @return property wrapper around a String function */ - public static PropertyValue> textAnchor(CameraFunction function) { + public static PropertyValue> textAnchor(Function function) { return new LayoutPropertyValue<>("text-anchor", function); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java index 7bdf47aff43..8123d24be81 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java @@ -203,6 +203,63 @@ public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { }); } + @Test + public void testLineJoinAsIdentitySourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("line-join"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + lineJoin(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineJoin()); + assertNotNull(layer.getLineJoin().getFunction()); + assertEquals(SourceFunction.class, layer.getLineJoin().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineJoin().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineJoin().getFunction().getStops().getClass()); + } + }); + } + + @Test + public void testLineJoinAsIntervalSourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("line-join"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + lineJoin( + property( + "FeaturePropertyA", + interval( + stop(1, lineJoin(LINE_JOIN_BEVEL)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineJoin()); + assertNotNull(layer.getLineJoin().getFunction()); + assertEquals(SourceFunction.class, layer.getLineJoin().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineJoin().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getLineJoin().getFunction().getStops().getClass()); + } + }); + } + @Test public void testLineMiterLimitAsConstant() { validateTestSetup(); 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 fc8c4320a51..e2694af3485 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 @@ -1887,6 +1887,63 @@ public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { }); } + @Test + public void testTextJustifyAsIdentitySourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("text-justify"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + textJustify(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getTextJustify()); + assertNotNull(layer.getTextJustify().getFunction()); + assertEquals(SourceFunction.class, layer.getTextJustify().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextJustify().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextJustify().getFunction().getStops().getClass()); + } + }); + } + + @Test + public void testTextJustifyAsIntervalSourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("text-justify"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + textJustify( + property( + "FeaturePropertyA", + interval( + stop(1, textJustify(TEXT_JUSTIFY_LEFT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextJustify()); + assertNotNull(layer.getTextJustify().getFunction()); + assertEquals(SourceFunction.class, layer.getTextJustify().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextJustify().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextJustify().getFunction().getStops().getClass()); + } + }); + } + @Test public void testTextAnchorAsConstant() { validateTestSetup(); @@ -1935,6 +1992,63 @@ public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { }); } + @Test + public void testTextAnchorAsIdentitySourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("text-anchor"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + textAnchor(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getTextAnchor()); + assertNotNull(layer.getTextAnchor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextAnchor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextAnchor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); + } + }); + } + + @Test + public void testTextAnchorAsIntervalSourceFunction() { + validateTestSetup(); + setupLayer(); + Timber.i("text-anchor"); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + assertNotNull(layer); + + // Set + layer.setProperties( + textAnchor( + property( + "FeaturePropertyA", + interval( + stop(1, textAnchor(TEXT_ANCHOR_CENTER)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextAnchor()); + assertNotNull(layer.getTextAnchor().getFunction()); + assertEquals(SourceFunction.class, layer.getTextAnchor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextAnchor().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); + } + }); + } + @Test public void testTextMaxAngleAsConstant() { validateTestSetup(); diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 4a96b11abf7..46025ddbf00 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -149,8 +149,18 @@ MGL_EXPORT You can set this property to an instance of: * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * `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 *lineJoin; diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 9be1667722d..5b2652cdeb0 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -109,7 +109,7 @@ - (void)setLineCap:(MGLStyleValue *)lineCap { - (void)setLineJoin:(MGLStyleValue *)lineJoin { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); + auto mbglValue = MGLStyleValueTransformer().toDataDrivenPropertyValue(lineJoin); self.rawLayer->setLineJoin(mbglValue); } @@ -118,9 +118,9 @@ - (void)setLineJoin:(MGLStyleValue *)lineJoin { auto propertyValue = self.rawLayer->getLineJoin(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer().toEnumStyleValue(self.rawLayer->getDefaultLineJoin()); + return MGLStyleValueTransformer().toDataDrivenStyleValue(self.rawLayer->getDefaultLineJoin()); } - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer().toDataDrivenStyleValue(propertyValue); } - (void)setLineMiterLimit:(MGLStyleValue *)lineMiterLimit { diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index f8df073efe6..d8dded7dbd2 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -924,8 +924,18 @@ MGL_EXPORT You can set this property to an instance of: * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * `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 *textAnchor; @@ -1043,8 +1053,18 @@ MGL_EXPORT You can set this property to an instance of: * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * `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 *textJustification; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index dd43ebd73c5..2541e6b0a4f 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -586,7 +586,7 @@ - (void)setTextAllowOverlap:(MGLStyleValue *)textAllowOverlap { - (void)setTextAnchor:(MGLStyleValue *)textAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); + auto mbglValue = MGLStyleValueTransformer().toDataDrivenPropertyValue(textAnchor); self.rawLayer->setTextAnchor(mbglValue); } @@ -595,9 +595,9 @@ - (void)setTextAnchor:(MGLStyleValue *)textAnchor { auto propertyValue = self.rawLayer->getTextAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer().toEnumStyleValue(self.rawLayer->getDefaultTextAnchor()); + return MGLStyleValueTransformer().toDataDrivenStyleValue(self.rawLayer->getDefaultTextAnchor()); } - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer().toDataDrivenStyleValue(propertyValue); } - (void)setTextFontNames:(MGLStyleValue *> *)textFontNames { @@ -675,7 +675,7 @@ - (void)setTextIgnorePlacement:(MGLStyleValue *)textIgnorePlacement - (void)setTextJustification:(MGLStyleValue *)textJustification { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustification); + auto mbglValue = MGLStyleValueTransformer().toDataDrivenPropertyValue(textJustification); self.rawLayer->setTextJustify(mbglValue); } @@ -684,9 +684,9 @@ - (void)setTextJustification:(MGLStyleValue *)textJustification { auto propertyValue = self.rawLayer->getTextJustify(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer().toEnumStyleValue(self.rawLayer->getDefaultTextJustify()); + return MGLStyleValueTransformer().toDataDrivenStyleValue(self.rawLayer->getDefaultTextJustify()); } - return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer().toDataDrivenStyleValue(propertyValue); } - (void)setTextJustify:(MGLStyleValue *)textJustify { diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm index be7d9a6754e..7e7926e22e2 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -95,7 +95,7 @@ - (void)testProperties { MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinMiter]]; layer.lineJoin = constantStyleValue; - mbgl::style::PropertyValue propertyValue = { mbgl::style::LineJoinType::Miter }; + mbgl::style::DataDrivenPropertyValue propertyValue = { mbgl::style::LineJoinType::Miter }; XCTAssertEqual(rawLayer->getLineJoin(), propertyValue, @"Setting lineJoin to a constant value should update line-join."); XCTAssertEqualObjects(layer.lineJoin, constantStyleValue, @@ -119,11 +119,6 @@ - (void)testProperties { @"Unsetting lineJoin should return line-join to the default value."); XCTAssertEqualObjects(layer.lineJoin, defaultStyleValue, @"lineJoin should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.lineJoin = 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.lineJoin = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // line-miter-limit diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index 5e969e27ca0..6b0b20354b9 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -931,7 +931,7 @@ - (void)testProperties { MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomRight]]; layer.textAnchor = constantStyleValue; - mbgl::style::PropertyValue propertyValue = { mbgl::style::TextAnchorType::BottomRight }; + mbgl::style::DataDrivenPropertyValue propertyValue = { mbgl::style::TextAnchorType::BottomRight }; XCTAssertEqual(rawLayer->getTextAnchor(), propertyValue, @"Setting textAnchor to a constant value should update text-anchor."); XCTAssertEqualObjects(layer.textAnchor, constantStyleValue, @@ -955,11 +955,6 @@ - (void)testProperties { @"Unsetting textAnchor should return text-anchor to the default value."); XCTAssertEqualObjects(layer.textAnchor, defaultStyleValue, @"textAnchor should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textAnchor = 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.textAnchor = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // text-font @@ -1105,7 +1100,7 @@ - (void)testProperties { MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLTextJustification:MGLTextJustificationRight]]; layer.textJustification = constantStyleValue; - mbgl::style::PropertyValue propertyValue = { mbgl::style::TextJustifyType::Right }; + mbgl::style::DataDrivenPropertyValue propertyValue = { mbgl::style::TextJustifyType::Right }; XCTAssertEqual(rawLayer->getTextJustify(), propertyValue, @"Setting textJustification to a constant value should update text-justify."); XCTAssertEqualObjects(layer.textJustification, constantStyleValue, @@ -1129,11 +1124,6 @@ - (void)testProperties { @"Unsetting textJustification should return text-justify to the default value."); XCTAssertEqualObjects(layer.textJustification, defaultStyleValue, @"textJustification should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textJustification = 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.textJustification = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // text-letter-spacing