diff --git a/include/mbgl/style/conversion/make_property_setters.hpp b/include/mbgl/style/conversion/make_property_setters.hpp index 2f26fe75c45..78c2fabebcb 100644 --- a/include/mbgl/style/conversion/make_property_setters.hpp +++ b/include/mbgl/style/conversion/make_property_setters.hpp @@ -56,7 +56,7 @@ auto makeLayoutPropertySetters() { result["text-justify"] = &setLayoutProperty, &SymbolLayer::setTextJustify>; result["text-anchor"] = &setLayoutProperty, &SymbolLayer::setTextAnchor>; result["text-max-angle"] = &setLayoutProperty, &SymbolLayer::setTextMaxAngle>; - result["text-rotate"] = &setLayoutProperty, &SymbolLayer::setTextRotate>; + result["text-rotate"] = &setLayoutProperty, &SymbolLayer::setTextRotate>; result["text-padding"] = &setLayoutProperty, &SymbolLayer::setTextPadding>; result["text-keep-upright"] = &setLayoutProperty, &SymbolLayer::setTextKeepUpright>; result["text-transform"] = &setLayoutProperty, &SymbolLayer::setTextTransform>; diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index b507c992f56..23bdf303b6d 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -135,9 +135,9 @@ class SymbolLayer : public Layer { PropertyValue getTextMaxAngle() const; void setTextMaxAngle(PropertyValue); - static PropertyValue getDefaultTextRotate(); - PropertyValue getTextRotate() const; - void setTextRotate(PropertyValue); + static DataDrivenPropertyValue getDefaultTextRotate(); + DataDrivenPropertyValue getTextRotate() const; + void setTextRotate(DataDrivenPropertyValue); static PropertyValue getDefaultTextPadding(); PropertyValue getTextPadding() const; diff --git a/mapbox-gl-js b/mapbox-gl-js index c34b6e9bc4a..3b49df25c80 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit c34b6e9bc4a2672c1046267408f1055271484b27 +Subproject commit 3b49df25c80f9ee505115bf3a36c820b85b9fc52 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 ef0bd38b568..7be8e245976 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 @@ -1963,11 +1963,11 @@ public static PropertyValue textRotate(Float value) { /** * Rotates the text clockwise. * - * @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> textRotate(CameraFunction function) { + public static PropertyValue> textRotate(Function function) { return new LayoutPropertyValue<>("text-rotate", 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 cac950dfc4e..dcb0690a199 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 @@ -1263,6 +1263,114 @@ public void testTextRotateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); } + @Test + public void testTextRotateAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + textRotate(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + } + + @Test + public void testTextRotateAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + textRotate( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, textRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + } + + @Test + public void testTextRotateAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + textRotate( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, textRotate(0.3f)) + ) + ).withDefaultValue(textRotate(0.3f)) + ) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextRotate().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + assertNotNull(((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue()); + assertNotNull(((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue().getValue()); + assertEquals(0.3f, ((SourceFunction) layer.getTextRotate().getFunction()).getDefaultValue().getValue()); + } + + @Test + public void testTextRotateAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); + + // Set + layer.setProperties( + textRotate( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, textRotate(0.9f)) + ).withBase(0.5f) + ).withDefaultValue(textRotate(0.3f)) + ) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(CompositeFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getTextRotate().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); + + ExponentialStops, Float> stops = + (ExponentialStops, Float>) layer.getTextRotate().getFunction().getStops(); + Stop, Float> stop = stops.iterator().next(); + assertEquals(0f, stop.in.zoom, 0.001); + assertEquals(0.3f, stop.in.value, 0.001f); + assertEquals(0.9f, stop.out, 0.001f); + } + @Test public void testTextPaddingAsConstant() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index 11dc67b458a..6d2cb18f50d 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -1150,6 +1150,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 *textRotation; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 6e35bf5dd23..b5179095742 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -831,7 +831,7 @@ - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { - (void)setTextRotation:(MGLStyleValue *)textRotation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer().toInterpolatablePropertyValue(textRotation); + auto mbglValue = MGLStyleValueTransformer().toDataDrivenPropertyValue(textRotation); self.rawLayer->setTextRotate(mbglValue); } @@ -840,9 +840,9 @@ - (void)setTextRotation:(MGLStyleValue *)textRotation { auto propertyValue = self.rawLayer->getTextRotate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer().toStyleValue(self.rawLayer->getDefaultTextRotate()); + return MGLStyleValueTransformer().toDataDrivenStyleValue(self.rawLayer->getDefaultTextRotate()); } - return MGLStyleValueTransformer().toStyleValue(propertyValue); + return MGLStyleValueTransformer().toDataDrivenStyleValue(propertyValue); } - (void)setTextRotate:(MGLStyleValue *)textRotate { diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index 18dfa1366fd..c967be611d6 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -1332,7 +1332,7 @@ - (void)testProperties { MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; layer.textRotation = constantStyleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, @"Setting textRotation to a constant value should update text-rotate."); XCTAssertEqualObjects(layer.textRotation, constantStyleValue, @@ -1349,6 +1349,29 @@ - (void)testProperties { XCTAssertEqualObjects(layer.textRotation, functionStyleValue, @"textRotation should round-trip camera functions."); + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.textRotation = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, + @"Setting textRotation to a source function should update text-rotate."); + XCTAssertEqualObjects(layer.textRotation, functionStyleValue, + @"textRotation should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.textRotation = functionStyleValue; + + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + + XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, + @"Setting textRotation to a composite function should update text-rotate."); + XCTAssertEqualObjects(layer.textRotation, functionStyleValue, + @"textRotation should round-trip composite functions."); layer.textRotation = nil; @@ -1356,11 +1379,6 @@ - (void)testProperties { @"Unsetting textRotation should return text-rotate to the default value."); XCTAssertEqualObjects(layer.textRotation, defaultStyleValue, @"textRotation should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textRotation = 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.textRotation = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // text-rotation-alignment diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 02e1e364f1c..3a896d4c933 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -427,15 +427,15 @@ void SymbolLayer::setTextMaxAngle(PropertyValue value) { impl->layout.unevaluated.get() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-angle"); } -PropertyValue SymbolLayer::getDefaultTextRotate() { +DataDrivenPropertyValue SymbolLayer::getDefaultTextRotate() { return TextRotate::defaultValue(); } -PropertyValue SymbolLayer::getTextRotate() const { +DataDrivenPropertyValue SymbolLayer::getTextRotate() const { return impl->layout.unevaluated.get(); } -void SymbolLayer::setTextRotate(PropertyValue value) { +void SymbolLayer::setTextRotate(DataDrivenPropertyValue value) { if (value == getTextRotate()) return; impl->layout.unevaluated.get() = value; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index e7cfb8d4550..4e4c64eec9e 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -140,7 +140,7 @@ struct TextMaxAngle : LayoutProperty { static float defaultValue() { return 45; } }; -struct TextRotate : LayoutProperty { +struct TextRotate : DataDrivenLayoutProperty { static constexpr const char * key = "text-rotate"; static float defaultValue() { return 0; } };