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

Commit

Permalink
[android][ios][macos] Add generated platform-specific code for DDS li…
Browse files Browse the repository at this point in the history
…ne-join, text-anchor, text-justify
  • Loading branch information
Lauren Budorick committed Jul 21, 2017
1 parent 1bb1389 commit 8797e54
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 42 deletions.
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
12 changes: 6 additions & 6 deletions platform/darwin/src/MGLSymbolStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ - (void)setTextAllowOverlap:(MGLStyleValue<NSNumber *> *)textAllowOverlap {
- (void)setTextAnchor:(MGLStyleValue<NSValue *> *)textAnchor {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toEnumPropertyValue(textAnchor);
auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toDataDrivenPropertyValue(textAnchor);
self.rawLayer->setTextAnchor(mbglValue);
}

Expand All @@ -595,9 +595,9 @@ - (void)setTextAnchor:(MGLStyleValue<NSValue *> *)textAnchor {

auto propertyValue = self.rawLayer->getTextAnchor();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toEnumStyleValue(self.rawLayer->getDefaultTextAnchor());
return MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextAnchor());
}
return MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toEnumStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::TextAnchorType, NSValue *, mbgl::style::TextAnchorType, MGLTextAnchor>().toDataDrivenStyleValue(propertyValue);
}

- (void)setTextFontNames:(MGLStyleValue<NSArray<NSString *> *> *)textFontNames {
Expand Down Expand Up @@ -675,7 +675,7 @@ - (void)setTextIgnorePlacement:(MGLStyleValue<NSNumber *> *)textIgnorePlacement
- (void)setTextJustification:(MGLStyleValue<NSValue *> *)textJustification {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toEnumPropertyValue(textJustification);
auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenPropertyValue(textJustification);
self.rawLayer->setTextJustify(mbglValue);
}

Expand All @@ -684,9 +684,9 @@ - (void)setTextJustification:(MGLStyleValue<NSValue *> *)textJustification {

auto propertyValue = self.rawLayer->getTextJustify();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toEnumStyleValue(self.rawLayer->getDefaultTextJustify());
return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextJustify());
}
return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toEnumStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenStyleValue(propertyValue);
}

- (void)setTextJustify:(MGLStyleValue<NSValue *> *)textJustify {
Expand Down
7 changes: 1 addition & 6 deletions platform/darwin/test/MGLLineStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (void)testProperties {

MGLStyleValue<NSValue *> *constantStyleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinMiter]];
layer.lineJoin = constantStyleValue;
mbgl::style::PropertyValue<mbgl::style::LineJoinType> propertyValue = { mbgl::style::LineJoinType::Miter };
mbgl::style::DataDrivenPropertyValue<mbgl::style::LineJoinType> propertyValue = { mbgl::style::LineJoinType::Miter };
XCTAssertEqual(rawLayer->getLineJoin(), propertyValue,
@"Setting lineJoin to a constant value should update line-join.");
XCTAssertEqualObjects(layer.lineJoin, constantStyleValue,
Expand All @@ -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<NSValue *> 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<NSValue *> 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
Expand Down
Loading

0 comments on commit 8797e54

Please sign in to comment.