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

Implement property functions for line-join, text-justify, text-anchor #9583

Merged
merged 7 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ auto makeLayoutPropertySetters() {


result["line-cap"] = &setProperty<V, LineLayer, PropertyValue<LineCapType>, &LineLayer::setLineCap>;
result["line-join"] = &setProperty<V, LineLayer, PropertyValue<LineJoinType>, &LineLayer::setLineJoin>;
result["line-join"] = &setProperty<V, LineLayer, DataDrivenPropertyValue<LineJoinType>, &LineLayer::setLineJoin>;
result["line-miter-limit"] = &setProperty<V, LineLayer, PropertyValue<float>, &LineLayer::setLineMiterLimit>;
result["line-round-limit"] = &setProperty<V, LineLayer, PropertyValue<float>, &LineLayer::setLineRoundLimit>;

Expand Down Expand Up @@ -54,8 +54,8 @@ auto makeLayoutPropertySetters() {
result["text-max-width"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextMaxWidth>;
result["text-line-height"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextLineHeight>;
result["text-letter-spacing"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextLetterSpacing>;
result["text-justify"] = &setProperty<V, SymbolLayer, PropertyValue<TextJustifyType>, &SymbolLayer::setTextJustify>;
result["text-anchor"] = &setProperty<V, SymbolLayer, PropertyValue<TextAnchorType>, &SymbolLayer::setTextAnchor>;
result["text-justify"] = &setProperty<V, SymbolLayer, DataDrivenPropertyValue<TextJustifyType>, &SymbolLayer::setTextJustify>;
result["text-anchor"] = &setProperty<V, SymbolLayer, DataDrivenPropertyValue<TextAnchorType>, &SymbolLayer::setTextAnchor>;
result["text-max-angle"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextMaxAngle>;
result["text-rotate"] = &setProperty<V, SymbolLayer, DataDrivenPropertyValue<float>, &SymbolLayer::setTextRotate>;
result["text-padding"] = &setProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextPadding>;
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/layers/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class LineLayer : public Layer {
PropertyValue<LineCapType> getLineCap() const;
void setLineCap(PropertyValue<LineCapType>);

static PropertyValue<LineJoinType> getDefaultLineJoin();
PropertyValue<LineJoinType> getLineJoin() const;
void setLineJoin(PropertyValue<LineJoinType>);
static DataDrivenPropertyValue<LineJoinType> getDefaultLineJoin();
DataDrivenPropertyValue<LineJoinType> getLineJoin() const;
void setLineJoin(DataDrivenPropertyValue<LineJoinType>);

static PropertyValue<float> getDefaultLineMiterLimit();
PropertyValue<float> getLineMiterLimit() const;
Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ class SymbolLayer : public Layer {
PropertyValue<float> getTextLetterSpacing() const;
void setTextLetterSpacing(PropertyValue<float>);

static PropertyValue<TextJustifyType> getDefaultTextJustify();
PropertyValue<TextJustifyType> getTextJustify() const;
void setTextJustify(PropertyValue<TextJustifyType>);
static DataDrivenPropertyValue<TextJustifyType> getDefaultTextJustify();
DataDrivenPropertyValue<TextJustifyType> getTextJustify() const;
void setTextJustify(DataDrivenPropertyValue<TextJustifyType>);

static PropertyValue<TextAnchorType> getDefaultTextAnchor();
PropertyValue<TextAnchorType> getTextAnchor() const;
void setTextAnchor(PropertyValue<TextAnchorType>);
static DataDrivenPropertyValue<TextAnchorType> getDefaultTextAnchor();
DataDrivenPropertyValue<TextAnchorType> getTextAnchor() const;
void setTextAnchor(DataDrivenPropertyValue<TextAnchorType>);

static PropertyValue<float> getDefaultTextMaxAngle();
PropertyValue<float> getTextMaxAngle() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,11 @@ public static PropertyValue<String> lineJoin(@Property.LINE_JOIN String value) {
/**
* The display of lines when joining.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for String
* @param <T> the function input type
* @param function a wrapper function for String
* @return property wrapper around a String function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> lineJoin(CameraFunction<Z, String> function) {
public static <T> PropertyValue<Function<T, String>> lineJoin(Function<T, String> function) {
return new LayoutPropertyValue<>("line-join", function);
}

Expand Down Expand Up @@ -2103,11 +2103,11 @@ public static PropertyValue<String> textJustify(@Property.TEXT_JUSTIFY String va
/**
* Text justification options.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for String
* @param <T> the function input type
* @param function a wrapper function for String
* @return property wrapper around a String function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textJustify(CameraFunction<Z, String> function) {
public static <T> PropertyValue<Function<T, String>> textJustify(Function<T, String> function) {
return new LayoutPropertyValue<>("text-justify", function);
}

Expand All @@ -2126,11 +2126,11 @@ public static PropertyValue<String> textAnchor(@Property.TEXT_ANCHOR String valu
/**
* Part of the text placed closest to the anchor.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for String
* @param <T> the function input type
* @param function a wrapper function for String
* @return property wrapper around a String function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textAnchor(CameraFunction<Z, String> function) {
public static <T> PropertyValue<Function<T, String>> textAnchor(Function<T, String> function) {
return new LayoutPropertyValue<>("text-anchor", function);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>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();
Expand Down Expand Up @@ -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.<String>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();
Expand Down
14 changes: 12 additions & 2 deletions platform/darwin/src/MGLLineStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSValue *> *lineJoin;

Expand Down
6 changes: 3 additions & 3 deletions platform/darwin/src/MGLLineStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (void)setLineCap:(MGLStyleValue<NSValue *> *)lineCap {
- (void)setLineJoin:(MGLStyleValue<NSValue *> *)lineJoin {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumPropertyValue(lineJoin);
auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenPropertyValue(lineJoin);
self.rawLayer->setLineJoin(mbglValue);
}

Expand All @@ -118,9 +118,9 @@ - (void)setLineJoin:(MGLStyleValue<NSValue *> *)lineJoin {

auto propertyValue = self.rawLayer->getLineJoin();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumStyleValue(self.rawLayer->getDefaultLineJoin());
return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineJoin());
}
return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenStyleValue(propertyValue);
}

- (void)setLineMiterLimit:(MGLStyleValue<NSNumber *> *)lineMiterLimit {
Expand Down
28 changes: 24 additions & 4 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSValue *> *textAnchor;

Expand Down Expand Up @@ -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<NSValue *> *textJustification;

Expand Down
Loading