Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Add DDS support for text-rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Mar 30, 2017
1 parent cc7e007 commit 1e2728c
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ auto makeLayoutPropertySetters() {
result["text-justify"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<TextJustifyType>, &SymbolLayer::setTextJustify>;
result["text-anchor"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<TextAnchorType>, &SymbolLayer::setTextAnchor>;
result["text-max-angle"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextMaxAngle>;
result["text-rotate"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextRotate>;
result["text-rotate"] = &setLayoutProperty<V, SymbolLayer, DataDrivenPropertyValue<float>, &SymbolLayer::setTextRotate>;
result["text-padding"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextPadding>;
result["text-keep-upright"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setTextKeepUpright>;
result["text-transform"] = &setLayoutProperty<V, SymbolLayer, DataDrivenPropertyValue<TextTransformType>, &SymbolLayer::setTextTransform>;
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class SymbolLayer : public Layer {
PropertyValue<float> getTextMaxAngle() const;
void setTextMaxAngle(PropertyValue<float>);

static PropertyValue<float> getDefaultTextRotate();
PropertyValue<float> getTextRotate() const;
void setTextRotate(PropertyValue<float>);
static DataDrivenPropertyValue<float> getDefaultTextRotate();
DataDrivenPropertyValue<float> getTextRotate() const;
void setTextRotate(DataDrivenPropertyValue<float>);

static PropertyValue<float> getDefaultTextPadding();
PropertyValue<float> getTextPadding() const;
Expand Down
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 50 files
+1 −1 .flowconfig
+8 −0 .topissuesrc
+2 −2 circle.yml
+0 −1 docs/_posts/examples/.eslintrc
+15 −22 docs/_posts/examples/3400-01-04-center-on-symbol.html
+7 −14 docs/_posts/examples/3400-01-04-hover-styles.html
+16 −22 docs/_posts/examples/3400-01-06-polygon-popup-on-click.html
+16 −25 docs/_posts/examples/3400-01-06-popup-on-click.html
+18 −21 docs/_posts/examples/3400-01-06-popup-on-hover.html
+9 −14 docs/_posts/examples/3400-01-14-filter-features-within-map-view.html
+14 −21 docs/_posts/examples/3400-01-24-drag-a-point.html
+12 −17 docs/_posts/examples/3400-01-24-query-similar-features.html
+59 −0 docs/_posts/examples/3400-01-31-add-image-generated.html
+47 −0 docs/_posts/examples/3400-01-31-add-image.html
+3 −3 package.json
+10 −2 src/data/bucket/symbol_bucket.js
+9 −10 src/render/draw_fill_extrusion.js
+2 −3 src/shaders/extrusion_texture.fragment.glsl
+4 −5 src/shaders/extrusion_texture.vertex.glsl
+3 −0 src/shaders/fill_extrusion.vertex.glsl
+3 −0 src/shaders/fill_extrusion_pattern.vertex.glsl
+10 −7 src/style-spec/function/index.js
+4 −1 src/style-spec/reference/v8.json
+196 −54 src/symbol/quads.js
+46 −7 src/ui/camera.js
+8 −1 src/ui/handler/drag_rotate.js
+149 −0 src/ui/map.js
+ test/integration/render-tests/text-rotate/anchor-bottom/expected.png
+14 −37 test/integration/render-tests/text-rotate/anchor-bottom/style.json
+ test/integration/render-tests/text-rotate/anchor-left/expected.png
+14 −37 test/integration/render-tests/text-rotate/anchor-left/style.json
+ test/integration/render-tests/text-rotate/anchor-right/expected.png
+14 −37 test/integration/render-tests/text-rotate/anchor-right/style.json
+ test/integration/render-tests/text-rotate/anchor-top/expected.png
+14 −37 test/integration/render-tests/text-rotate/anchor-top/style.json
+ test/integration/render-tests/text-rotate/function/expected.png
+19 −38 test/integration/render-tests/text-rotate/function/style.json
+ test/integration/render-tests/text-rotate/literal/expected.png
+15 −36 test/integration/render-tests/text-rotate/literal/style.json
+ test/integration/render-tests/text-rotate/property-function/expected.png
+64 −0 test/integration/render-tests/text-rotate/property-function/style.json
+8 −0 test/node_modules/mapbox-gl-js-test/simulate_interaction.js
+5 −5 test/suite_implementation.js
+41 −0 test/unit/style-spec/function.test.js
+3 −3 test/unit/style/style.test.js
+21 −1 test/unit/ui/camera.test.js
+9 −3 test/unit/ui/map.test.js
+466 −0 test/unit/ui/map_events.test.js
+6 −6 test/unit/ui/popup.test.js
+49 −26 yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1963,11 +1963,11 @@ public static PropertyValue<Float> textRotate(Float value) {
/**
* Rotates the text clockwise.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for Float
* @param <T> the function input type
* @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> textRotate(CameraFunction<Z, Float> function) {
public static <T> PropertyValue<Function<T, Float>> textRotate(Function<T, Float> function) {
return new LayoutPropertyValue<>("text-rotate", function);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Float>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<Stop.CompositeValue<Float, Float>, Float> stops =
(ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getTextRotate().getFunction().getStops();
Stop<Stop.CompositeValue<Float, Float>, 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);
Expand Down
9 changes: 9 additions & 0 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *> *textRotation;

Expand Down
6 changes: 3 additions & 3 deletions platform/darwin/src/MGLSymbolStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ - (void)setTextPitchAlignment:(MGLStyleValue<NSValue *> *)textPitchAlignment {
- (void)setTextRotation:(MGLStyleValue<NSNumber *> *)textRotation {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(textRotation);
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textRotation);
self.rawLayer->setTextRotate(mbglValue);
}

Expand All @@ -840,9 +840,9 @@ - (void)setTextRotation:(MGLStyleValue<NSNumber *> *)textRotation {

auto propertyValue = self.rawLayer->getTextRotate();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextRotate());
return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextRotate());
}
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue);
}

- (void)setTextRotate:(MGLStyleValue<NSNumber *> *)textRotate {
Expand Down
30 changes: 24 additions & 6 deletions platform/darwin/test/MGLSymbolStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ - (void)testProperties {

MGLStyleValue<NSNumber *> *constantStyleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff];
layer.textRotation = constantStyleValue;
mbgl::style::PropertyValue<float> propertyValue = { 0xff };
mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff };
XCTAssertEqual(rawLayer->getTextRotate(), propertyValue,
@"Setting textRotation to a constant value should update text-rotate.");
XCTAssertEqualObjects(layer.textRotation, constantStyleValue,
Expand All @@ -1349,18 +1349,36 @@ - (void)testProperties {
XCTAssertEqualObjects(layer.textRotation, functionStyleValue,
@"textRotation should round-trip camera functions.");

functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil];
layer.textRotation = functionStyleValue;

mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 };
propertyValue = mbgl::style::SourceFunction<float> { "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<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.textRotation = functionStyleValue;

std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };

propertyValue = mbgl::style::CompositeFunction<float> { "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;
XCTAssertTrue(rawLayer->getTextRotate().isUndefined(),
@"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<NSNumber *> 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<NSNumber *> 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
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/style/layers/symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ void SymbolLayer::setTextMaxAngle(PropertyValue<float> value) {
impl->layout.unevaluated.get<TextMaxAngle>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-angle");
}
PropertyValue<float> SymbolLayer::getDefaultTextRotate() {
DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextRotate() {
return TextRotate::defaultValue();
}

PropertyValue<float> SymbolLayer::getTextRotate() const {
DataDrivenPropertyValue<float> SymbolLayer::getTextRotate() const {
return impl->layout.unevaluated.get<TextRotate>();
}

void SymbolLayer::setTextRotate(PropertyValue<float> value) {
void SymbolLayer::setTextRotate(DataDrivenPropertyValue<float> value) {
if (value == getTextRotate())
return;
impl->layout.unevaluated.get<TextRotate>() = value;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/layers/symbol_layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct TextMaxAngle : LayoutProperty<float> {
static float defaultValue() { return 45; }
};

struct TextRotate : LayoutProperty<float> {
struct TextRotate : DataDrivenLayoutProperty<float> {
static constexpr const char * key = "text-rotate";
static float defaultValue() { return 0; }
};
Expand Down

0 comments on commit 1e2728c

Please sign in to comment.