From 6a2ce352d1eec6dc166e351e06c6b10c633eb07c Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Wed, 21 Sep 2016 19:07:33 -0400 Subject: [PATCH] Better handling for undefined icon|text-rotation-alignment (#6253) * [core, ios, android] Use `auto` value for properties with calculated defaults * Fix render tests --- include/mbgl/style/types.hpp | 2 +- package.json | 4 ++-- .../mapboxsdk/style/layers/Property.java | 6 +++++ .../style/layers/PropertyFactory.java | 16 ++++++------- .../style/conversion/types_string_values.hpp | 3 +++ platform/darwin/src/MGLLineStyleLayer.h | 2 +- platform/darwin/src/MGLSymbolStyleLayer.h | 15 ++++++++---- .../darwin/test/MGLSymbolStyleLayerTests.m | 24 +++++++++---------- src/mbgl/style/layers/symbol_layer.cpp | 6 ++--- src/mbgl/style/layers/symbol_layer_impl.cpp | 24 +++++++++++++------ .../style/layers/symbol_layer_properties.hpp | 6 ++--- src/mbgl/style/types.cpp | 2 +- 12 files changed, 67 insertions(+), 43 deletions(-) diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 34e5642ec..1f2f5c310 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -58,7 +58,7 @@ enum class SymbolPlacementType : bool { enum class AlignmentType : uint8_t { Map, Viewport, - Undefined, + Auto, }; enum class TextJustifyType : uint8_t { diff --git a/package.json b/package.json index 992092866..6b2a9f6d1 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "ejs": "^2.4.1", "express": "^4.11.1", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#de2ab007455aa2587c552694c68583f94c9f2747", - "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#83b1a3e5837d785af582efd5ed1a212f2df6a4ae", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#5b2e5749e85ad4241b5b4e4e54d2fa98e8920f34", + "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#a6c95d33ff5ced2c0d7df995fd89eb557c0a353c", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#e05680a27f93d7284fce31b9b42a19c80df96b13", "mkdirp": "^0.5.1", "node-cmake": "^1.2.1", "request": "^2.72.0", diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index a31f1adb5..bae91313a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java @@ -62,10 +62,12 @@ public abstract class Property { //icon-rotation-alignment public static final String ICON_ROTATION_ALIGNMENT_MAP = "map"; public static final String ICON_ROTATION_ALIGNMENT_VIEWPORT = "viewport"; + public static final String ICON_ROTATION_ALIGNMENT_AUTO = "auto"; @StringDef({ ICON_ROTATION_ALIGNMENT_MAP, ICON_ROTATION_ALIGNMENT_VIEWPORT, + ICON_ROTATION_ALIGNMENT_AUTO, }) @Retention(RetentionPolicy.SOURCE) public @interface ICON_ROTATION_ALIGNMENT {} @@ -88,10 +90,12 @@ public abstract class Property { //text-pitch-alignment public static final String TEXT_PITCH_ALIGNMENT_MAP = "map"; public static final String TEXT_PITCH_ALIGNMENT_VIEWPORT = "viewport"; + public static final String TEXT_PITCH_ALIGNMENT_AUTO = "auto"; @StringDef({ TEXT_PITCH_ALIGNMENT_MAP, TEXT_PITCH_ALIGNMENT_VIEWPORT, + TEXT_PITCH_ALIGNMENT_AUTO, }) @Retention(RetentionPolicy.SOURCE) public @interface TEXT_PITCH_ALIGNMENT {} @@ -99,10 +103,12 @@ public abstract class Property { //text-rotation-alignment public static final String TEXT_ROTATION_ALIGNMENT_MAP = "map"; public static final String TEXT_ROTATION_ALIGNMENT_VIEWPORT = "viewport"; + public static final String TEXT_ROTATION_ALIGNMENT_AUTO = "auto"; @StringDef({ TEXT_ROTATION_ALIGNMENT_MAP, TEXT_ROTATION_ALIGNMENT_VIEWPORT, + TEXT_ROTATION_ALIGNMENT_AUTO, }) @Retention(RetentionPolicy.SOURCE) public @interface TEXT_ROTATION_ALIGNMENT {} 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 4d4a924da..e360831d0 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 @@ -322,7 +322,7 @@ public class PropertyFactory { } /** - * The line's offset perpendicular to its direction. Values may be positive or negative, where positive indicates "rightwards" (if you were moving in the direction of the line) and negative indicates "leftwards." + * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. * * @param value a Float value * @return property wrapper around Float @@ -332,7 +332,7 @@ public class PropertyFactory { } /** - * The line's offset perpendicular to its direction. Values may be positive or negative, where positive indicates "rightwards" (if you were moving in the direction of the line) and negative indicates "leftwards." + * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. * * @param function a wrapper function for Float * @return property wrapper around a Float function @@ -1282,7 +1282,7 @@ public class PropertyFactory { } /** - * Orientation of icon when map is rotated. + * Orientation of icon when map is rotated. Aligns icon to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Selecting `auto` defaults to `map` for line placement and `viewport` for symbol placement * * @param value a String value * @return property wrapper around String @@ -1292,7 +1292,7 @@ public class PropertyFactory { } /** - * Orientation of icon when map is rotated. + * Orientation of icon when map is rotated. Aligns icon to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Selecting `auto` defaults to `map` for line placement and `viewport` for symbol placement * * @param function a wrapper function for String * @return property wrapper around a String function @@ -1462,7 +1462,7 @@ public class PropertyFactory { } /** - * Aligns text to the plane of the `viewport` or the `map` when the map is pitched. Matches `text-rotation-alignment` if unspecified. + * Orientation of text when map is pitched. Aligns text to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Matches `text-rotation-alignment` if `auto`. * * @param value a String value * @return property wrapper around String @@ -1472,7 +1472,7 @@ public class PropertyFactory { } /** - * Aligns text to the plane of the `viewport` or the `map` when the map is pitched. Matches `text-rotation-alignment` if unspecified. + * Orientation of text when map is pitched. Aligns text to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Matches `text-rotation-alignment` if `auto`. * * @param function a wrapper function for String * @return property wrapper around a String function @@ -1482,7 +1482,7 @@ public class PropertyFactory { } /** - * Orientation of text when map is rotated. + * Orientation of text when map is rotated. Aligns text to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Selecting `auto` defaults to the plane of the `map` for line placement and the `viewport` for symbol placement. * * @param value a String value * @return property wrapper around String @@ -1492,7 +1492,7 @@ public class PropertyFactory { } /** - * Orientation of text when map is rotated. + * Orientation of text when map is rotated. Aligns text to the plane of the viewport when set to `viewport` or the plane of the map when set to `map`. Selecting `auto` defaults to the plane of the `map` for line placement and the `viewport` for symbol placement. * * @param function a wrapper function for String * @return property wrapper around a String function diff --git a/platform/android/src/style/conversion/types_string_values.hpp b/platform/android/src/style/conversion/types_string_values.hpp index 35cdb1cbc..d44de733d 100644 --- a/platform/android/src/style/conversion/types_string_values.hpp +++ b/platform/android/src/style/conversion/types_string_values.hpp @@ -81,6 +81,9 @@ namespace conversion { case mbgl::style::AlignmentType::Viewport: return "viewport"; break; + case mbgl::style::AlignmentType::Auto: + return "auto"; + break; default: throw std::runtime_error("Not implemented"); } diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 34f8e74df..ec338f65b 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -138,7 +138,7 @@ typedef NS_ENUM(NSUInteger, MGLLineStyleLayerLineTranslateAnchor) { @property (nonatomic, null_resettable) id lineGapWidth; /** - The line's offset perpendicular to its direction. Values may be positive or negative, where positive indicates "rightwards" (if you were moving in the direction of the line) and negative indicates "leftwards." + The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. This property is measured in points. diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index c900518b9..75fe2c121 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -14,6 +14,7 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerSymbolPlacement) { typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerIconRotationAlignment) { MGLSymbolStyleLayerIconRotationAlignmentMap, MGLSymbolStyleLayerIconRotationAlignmentViewport, + MGLSymbolStyleLayerIconRotationAlignmentAuto, }; typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerIconTextFit) { @@ -26,11 +27,13 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerIconTextFit) { typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextPitchAlignment) { MGLSymbolStyleLayerTextPitchAlignmentMap, MGLSymbolStyleLayerTextPitchAlignmentViewport, + MGLSymbolStyleLayerTextPitchAlignmentAuto, }; typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextRotationAlignment) { MGLSymbolStyleLayerTextRotationAlignmentMap, MGLSymbolStyleLayerTextRotationAlignmentViewport, + MGLSymbolStyleLayerTextRotationAlignmentAuto, }; typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextJustify) { @@ -137,9 +140,9 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) { @property (nonatomic, null_resettable) id iconOptional; /** - Orientation of icon when map is rotated. + Orientation of icon when map is rotated. Aligns icon to the plane of the viewport when set to `MGLSymbolStyleLayerIconRotationAlignmentViewport` or the plane of the map when set to `MGLSymbolStyleLayerIconRotationAlignmentMap`. Selecting `MGLSymbolStyleLayerIconRotationAlignmentAuto` defaults to `MGLSymbolStyleLayerIconRotationAlignmentMap` for line placement and `MGLSymbolStyleLayerIconRotationAlignmentViewport` for symbol placement - The default value of this property is an `NSValue` object containing `MGLSymbolStyleLayerIconRotationAlignmentViewport`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `NSValue` object containing `MGLSymbolStyleLayerIconRotationAlignmentAuto`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImage` is non-`nil`. Otherwise, it is ignored. */ @@ -220,16 +223,18 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) { @property (nonatomic, null_resettable) id iconOffset; /** - Aligns text to the plane of the `MGLSymbolStyleLayerTextPitchAlignmentViewport` or the `MGLSymbolStyleLayerTextPitchAlignmentMap` when the map is pitched. Matches `textRotationAlignment` if unspecified. + Orientation of text when map is pitched. Aligns text to the plane of the viewport when set to `MGLSymbolStyleLayerTextPitchAlignmentViewport` or the plane of the map when set to `MGLSymbolStyleLayerTextPitchAlignmentMap`. Matches `textRotationAlignment` if `MGLSymbolStyleLayerTextPitchAlignmentAuto`. + + The default value of this property is an `NSValue` object containing `MGLSymbolStyleLayerTextPitchAlignmentAuto`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ @property (nonatomic, null_resettable) id textPitchAlignment; /** - Orientation of text when map is rotated. + Orientation of text when map is rotated. Aligns text to the plane of the viewport when set to `MGLSymbolStyleLayerTextRotationAlignmentViewport` or the plane of the map when set to `MGLSymbolStyleLayerTextRotationAlignmentMap`. Selecting `MGLSymbolStyleLayerTextRotationAlignmentAuto` defaults to the plane of the `MGLSymbolStyleLayerTextRotationAlignmentMap` for line placement and the `MGLSymbolStyleLayerTextRotationAlignmentViewport` for symbol placement. - The default value of this property is an `NSValue` object containing `MGLSymbolStyleLayerTextRotationAlignmentViewport`. Set this property to `nil` to reset it to the default value. + The default value of this property is an `NSValue` object containing `MGLSymbolStyleLayerTextRotationAlignmentAuto`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `textField` is non-`nil`. Otherwise, it is ignored. */ diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m index dbd8f5048..deee9f47e 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.m @@ -22,7 +22,7 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie layer.iconAllowOverlap = [MGLRuntimeStylingHelper testBool]; layer.iconIgnorePlacement = [MGLRuntimeStylingHelper testBool]; layer.iconOptional = [MGLRuntimeStylingHelper testBool]; - layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]; + layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]; layer.iconSize = [MGLRuntimeStylingHelper testNumber]; layer.iconTextFit = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconTextFitHeight type:@encode(MGLSymbolStyleLayerIconTextFit)]; layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPadding]; @@ -31,8 +31,8 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie layer.iconPadding = [MGLRuntimeStylingHelper testNumber]; layer.iconKeepUpright = [MGLRuntimeStylingHelper testBool]; layer.iconOffset = [MGLRuntimeStylingHelper testOffset]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentViewport type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]; + layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentAuto type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]; + layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]; layer.textField = [MGLRuntimeStylingHelper testString]; layer.textFont = [MGLRuntimeStylingHelper testFont]; layer.textSize = [MGLRuntimeStylingHelper testNumber]; @@ -72,7 +72,7 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie XCTAssertEqualObjects(gLayer.iconAllowOverlap, [MGLRuntimeStylingHelper testBool]); XCTAssertEqualObjects(gLayer.iconIgnorePlacement, [MGLRuntimeStylingHelper testBool]); XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBool]); - XCTAssert([(NSValue *)gLayer.iconRotationAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]], @"%@ is not equal to %@", gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]); + XCTAssert([(NSValue *)gLayer.iconRotationAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]], @"%@ is not equal to %@", gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]); XCTAssertEqualObjects(gLayer.iconSize, [MGLRuntimeStylingHelper testNumber]); XCTAssert([(NSValue *)gLayer.iconTextFit isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconTextFitHeight type:@encode(MGLSymbolStyleLayerIconTextFit)]], @"%@ is not equal to %@", gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerIconTextFitHeight type:@encode(MGLSymbolStyleLayerIconTextFit)]); XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPadding]); @@ -81,8 +81,8 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumber]); XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBool]); XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([(NSValue *)gLayer.textPitchAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentViewport type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]], @"%@ is not equal to %@", gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentViewport type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]); - XCTAssert([(NSValue *)gLayer.textRotationAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]], @"%@ is not equal to %@", gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]); + XCTAssert([(NSValue *)gLayer.textPitchAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentAuto type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]], @"%@ is not equal to %@", gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextPitchAlignmentAuto type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]); + XCTAssert([(NSValue *)gLayer.textRotationAlignment isEqualToValue:[MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]], @"%@ is not equal to %@", gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLSymbolStyleLayerTextRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]); XCTAssertEqualObjects(gLayer.textField, [MGLRuntimeStylingHelper testString]); XCTAssertEqualObjects(gLayer.textFont, [MGLRuntimeStylingHelper testFont]); XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumber]); @@ -121,7 +121,7 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie layer.iconAllowOverlap = [MGLRuntimeStylingHelper testBoolFunction]; layer.iconIgnorePlacement = [MGLRuntimeStylingHelper testBoolFunction]; layer.iconOptional = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]; + layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]; layer.iconSize = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconTextFit = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconTextFitHeight type:@encode(MGLSymbolStyleLayerIconTextFit)]; layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPaddingFunction]; @@ -130,8 +130,8 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie layer.iconPadding = [MGLRuntimeStylingHelper testNumberFunction]; layer.iconKeepUpright = [MGLRuntimeStylingHelper testBoolFunction]; layer.iconOffset = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextPitchAlignmentViewport type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]; + layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextPitchAlignmentAuto type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]; + layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]; layer.textField = [MGLRuntimeStylingHelper testStringFunction]; layer.textFont = [MGLRuntimeStylingHelper testFontFunction]; layer.textSize = [MGLRuntimeStylingHelper testNumberFunction]; @@ -170,7 +170,7 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie XCTAssertEqualObjects(gLayer.iconAllowOverlap, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.iconIgnorePlacement, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]); + XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerIconRotationAlignment)]); XCTAssertEqualObjects(gLayer.iconSize, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerIconTextFitHeight type:@encode(MGLSymbolStyleLayerIconTextFit)]); XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPaddingFunction]); @@ -179,8 +179,8 @@ MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifie XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumberFunction]); XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]); XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextPitchAlignmentViewport type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]); - XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextRotationAlignmentViewport type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]); + XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextPitchAlignmentAuto type:@encode(MGLSymbolStyleLayerTextPitchAlignment)]); + XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolStyleLayerTextRotationAlignmentAuto type:@encode(MGLSymbolStyleLayerTextRotationAlignment)]); XCTAssertEqualObjects(gLayer.textField, [MGLRuntimeStylingHelper testStringFunction]); XCTAssertEqualObjects(gLayer.textFont, [MGLRuntimeStylingHelper testFontFunction]); XCTAssertEqualObjects(gLayer.textSize, [MGLRuntimeStylingHelper testNumberFunction]); diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index c9fd2c098..6b4d7400d 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -144,7 +144,7 @@ void SymbolLayer::setIconOptional(PropertyValue value) { impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconRotationAlignment() { - return { AlignmentType::Viewport }; + return { AlignmentType::Auto }; } PropertyValue SymbolLayer::getIconRotationAlignment() const { @@ -270,7 +270,7 @@ void SymbolLayer::setIconOffset(PropertyValue> value) { impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextPitchAlignment() { - return { AlignmentType::Undefined }; + return { AlignmentType::Auto }; } PropertyValue SymbolLayer::getTextPitchAlignment() const { @@ -284,7 +284,7 @@ void SymbolLayer::setTextPitchAlignment(PropertyValue value) { impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextRotationAlignment() { - return { AlignmentType::Viewport }; + return { AlignmentType::Auto }; } PropertyValue SymbolLayer::getTextRotationAlignment() const { diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 1039951f5..e85f3a90f 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -35,19 +35,29 @@ std::unique_ptr SymbolLayer::Impl::createLayout(BucketParameters& SymbolLayoutProperties layoutProperties = layout; CalculationParameters p(parameters.tileID.overscaledZ); - layoutProperties.symbolPlacement.calculate(p); - if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) { - layoutProperties.iconRotationAlignment.value = AlignmentType::Map; - layoutProperties.textRotationAlignment.value = AlignmentType::Map; + layoutProperties.recalculate(p); + + if (layoutProperties.iconRotationAlignment.value == AlignmentType::Auto) { + if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) { + layoutProperties.iconRotationAlignment.value = AlignmentType::Map; + } else { + layoutProperties.iconRotationAlignment.value = AlignmentType::Viewport; + } + } + + if (layoutProperties.textRotationAlignment.value == AlignmentType::Auto) { + if (layoutProperties.symbolPlacement.value == SymbolPlacementType::Line) { + layoutProperties.textRotationAlignment.value = AlignmentType::Map; + } else { + layoutProperties.textRotationAlignment.value = AlignmentType::Viewport; + } } // If unspecified `text-pitch-alignment` inherits `text-rotation-alignment` - if (layoutProperties.textPitchAlignment.value == AlignmentType::Undefined) { + if (layoutProperties.textPitchAlignment.value == AlignmentType::Auto) { layoutProperties.textPitchAlignment.value = layoutProperties.textRotationAlignment.value; } - layoutProperties.recalculate(p); - layoutProperties.textSize.calculate(CalculationParameters(18)); float textMaxSize = layoutProperties.textSize; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index e4560ab48..fefa0ae05 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -22,7 +22,7 @@ public: LayoutProperty iconAllowOverlap { false }; LayoutProperty iconIgnorePlacement { false }; LayoutProperty iconOptional { false }; - LayoutProperty iconRotationAlignment { AlignmentType::Viewport }; + LayoutProperty iconRotationAlignment { AlignmentType::Auto }; LayoutProperty iconSize { 1 }; LayoutProperty iconTextFit { IconTextFitType::None }; LayoutProperty> iconTextFitPadding { {{ 0, 0, 0, 0 }} }; @@ -31,8 +31,8 @@ public: LayoutProperty iconPadding { 2 }; LayoutProperty iconKeepUpright { false }; LayoutProperty> iconOffset { {{ 0, 0 }} }; - LayoutProperty textPitchAlignment { AlignmentType::Undefined }; - LayoutProperty textRotationAlignment { AlignmentType::Viewport }; + LayoutProperty textPitchAlignment { AlignmentType::Auto }; + LayoutProperty textRotationAlignment { AlignmentType::Auto }; LayoutProperty textField { "" }; LayoutProperty> textFont { { "Open Sans Regular", "Arial Unicode MS Regular" } }; LayoutProperty textSize { 16 }; diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp index be0b21713..bf2ba8a79 100644 --- a/src/mbgl/style/types.cpp +++ b/src/mbgl/style/types.cpp @@ -79,7 +79,7 @@ MBGL_DEFINE_ENUM(TextTransformType, { MBGL_DEFINE_ENUM(AlignmentType, { { AlignmentType::Map, "map" }, { AlignmentType::Viewport, "viewport" }, - { AlignmentType::Undefined, "undefined" }, + { AlignmentType::Auto, "auto" }, }); MBGL_DEFINE_ENUM(IconTextFitType, {