summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-07-20 13:06:01 -0700
committerChris Loer <chris.loer@mapbox.com>2018-07-23 13:33:27 -0700
commit0b2221cb74ab79a0610ac44cee2a053da41a3dff (patch)
tree372e3e3215d70676c4625476889b4d9dbb6cd434
parentf9b36f9f5b4cf09e08c2ff0181b339b53e8d0014 (diff)
downloadqtlocation-mapboxgl-0b2221cb74ab79a0610ac44cee2a053da41a3dff.tar.gz
[android, ios, macos] Generate symbol-placement: line-center wrappers
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java13
-rwxr-xr-xplatform/android/scripts/generate-style-code.js9
-rw-r--r--platform/android/src/style/conversion/types_string_values.hpp3
-rwxr-xr-xplatform/darwin/scripts/generate-style-code.js11
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h54
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.mm1
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.mm9
7 files changed, 68 insertions, 32 deletions
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 c264d773c5..ba3619567d 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
@@ -92,6 +92,10 @@ public final class Property {
* The label is placed along the line of the geometry. Can only be used on LineString and Polygon geometries.
*/
public static final String SYMBOL_PLACEMENT_LINE = "line";
+ /**
+ * The label is placed at the center of the line of the geometry. Can only be used on LineString and Polygon geometries. Note that a single feature in a vector tile may contain multiple line geometries.
+ */
+ public static final String SYMBOL_PLACEMENT_LINE_CENTER = "line-center";
/**
* Label placement relative to its geometry.
@@ -99,6 +103,7 @@ public final class Property {
@StringDef({
SYMBOL_PLACEMENT_POINT,
SYMBOL_PLACEMENT_LINE,
+ SYMBOL_PLACEMENT_LINE_CENTER,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SYMBOL_PLACEMENT {}
@@ -106,7 +111,7 @@ public final class Property {
// ICON_ROTATION_ALIGNMENT: In combination with `symbol-placement`, determines the rotation behavior of icons.
/**
- * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns icons east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns icon x-axes with the line.
+ * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns icons east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE} or {@link Property#SYMBOL_PLACEMENT_LINE_CENTER}, aligns icon x-axes with the line.
*/
public static final String ICON_ROTATION_ALIGNMENT_MAP = "map";
/**
@@ -114,7 +119,7 @@ public final class Property {
*/
public static final String ICON_ROTATION_ALIGNMENT_VIEWPORT = "viewport";
/**
- * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_MAP}.
+ * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE} or {@link Property#SYMBOL_PLACEMENT_LINE_CENTER}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_MAP}.
*/
public static final String ICON_ROTATION_ALIGNMENT_AUTO = "auto";
@@ -271,7 +276,7 @@ public final class Property {
// TEXT_ROTATION_ALIGNMENT: In combination with `symbol-placement`, determines the rotation behavior of the individual glyphs forming the text.
/**
- * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns text east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns text x-axes with the line.
+ * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns text east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE} or {@link Property#SYMBOL_PLACEMENT_LINE_CENTER}, aligns text x-axes with the line.
*/
public static final String TEXT_ROTATION_ALIGNMENT_MAP = "map";
/**
@@ -279,7 +284,7 @@ public final class Property {
*/
public static final String TEXT_ROTATION_ALIGNMENT_VIEWPORT = "viewport";
/**
- * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_MAP}.
+ * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE} or {@link Property#SYMBOL_PLACEMENT_LINE_CENTER}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_MAP}.
*/
public static final String TEXT_ROTATION_ALIGNMENT_AUTO = "auto";
diff --git a/platform/android/scripts/generate-style-code.js b/platform/android/scripts/generate-style-code.js
index 05ca957974..b435351df5 100755
--- a/platform/android/scripts/generate-style-code.js
+++ b/platform/android/scripts/generate-style-code.js
@@ -235,10 +235,15 @@ global.propertyValueDoc = function (property, value) {
// Match references to other property names & values.
// Requires the format 'When `foo` is set to `bar`,'.
- let doc = property.values[value].doc.replace(/When `(.+?)` is set to `(.+?)`,/g, function (m, peerPropertyName, propertyValue, offset, str) {
+ let doc = property.values[value].doc.replace(/When `(.+?)` is set to `(.+?)`(?: or `([^`]+?)`)?,/g, function (m, peerPropertyName, propertyValue, secondPropertyValue, offset, str) {
let otherProperty = snakeCaseUpper(peerPropertyName);
let otherValue = snakeCaseUpper(peerPropertyName) + '_' + snakeCaseUpper(propertyValue);
- return 'When {@link ' + `${otherProperty}` + '} is set to {@link Property#' + `${otherValue}` + '},';
+ const firstPropertyValue = 'When {@link ' + `${otherProperty}` + '} is set to {@link Property#' + `${otherValue}` + '}';
+ if (secondPropertyValue) {
+ return firstPropertyValue + ` or {@link Property#${snakeCaseUpper(peerPropertyName) + '_' + snakeCaseUpper(secondPropertyValue)}},`;
+ } else {
+ return firstPropertyValue + ',';
+ }
});
// Match references to our own property values.
diff --git a/platform/android/src/style/conversion/types_string_values.hpp b/platform/android/src/style/conversion/types_string_values.hpp
index ff79fa4f1c..9f6696d181 100644
--- a/platform/android/src/style/conversion/types_string_values.hpp
+++ b/platform/android/src/style/conversion/types_string_values.hpp
@@ -67,6 +67,9 @@ namespace conversion {
case mbgl::style::SymbolPlacementType::Line:
return "line";
break;
+ case mbgl::style::SymbolPlacementType::LineCenter:
+ return "line-center";
+ break;
default:
throw std::runtime_error("Not implemented");
}
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 3809e9c636..0e5bf89fd4 100755
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -248,13 +248,20 @@ global.testHelperMessage = function (property, layerType, isFunction) {
global.propertyDoc = function (propertyName, property, layerType, kind) {
// Match references to other property names & values.
// Requires the format 'When `foo` is set to `bar`,'.
- let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) {
+ let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`(?: or `([^`]+?)`)?/g, function (m, peerPropertyName, propertyValue, secondPropertyValue, offset, str) {
let otherProperty = camelizeWithLeadingLowercase(peerPropertyName);
let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue);
if (property.type == 'array' && kind == 'light') {
otherValue = propertyValue;
}
- return '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`';
+ const firstPropertyValue = '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`';
+ if (secondPropertyValue) {
+ return firstPropertyValue + ' or `' +
+ objCType(layerType, peerPropertyName) + camelize(secondPropertyValue) +
+ '`';
+ } else {
+ return firstPropertyValue;
+ }
});
// Match references to our own property values.
// Requires the format 'is equivalent to `bar`'.
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index 2c899fe76f..afaea9a74f 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -83,8 +83,8 @@ typedef NS_ENUM(NSUInteger, MGLIconPitchAlignment) {
typedef NS_ENUM(NSUInteger, MGLIconRotationAlignment) {
/**
When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns icons
- east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`,
- aligns icon x-axes with the line.
+ east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine` or
+ `MGLSymbolPlacementLineCenter`, aligns icon x-axes with the line.
*/
MGLIconRotationAlignmentMap,
/**
@@ -95,8 +95,8 @@ typedef NS_ENUM(NSUInteger, MGLIconRotationAlignment) {
/**
When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is
equivalent to `MGLIconRotationAlignmentViewport`. When `symbolPlacement` is
- set to `MGLSymbolPlacementLine`, this is equivalent to
- `MGLIconRotationAlignmentMap`.
+ set to `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`, this is
+ equivalent to `MGLIconRotationAlignmentMap`.
*/
MGLIconRotationAlignmentAuto,
};
@@ -142,6 +142,12 @@ typedef NS_ENUM(NSUInteger, MGLSymbolPlacement) {
`LineString` and `Polygon` geometries.
*/
MGLSymbolPlacementLine,
+ /**
+ The label is placed at the center of the line of the geometry. Can only be
+ used on `LineString` and `Polygon` geometries. Note that a single feature
+ in a vector tile may contain multiple line geometries.
+ */
+ MGLSymbolPlacementLineCenter,
};
/**
@@ -242,8 +248,8 @@ typedef NS_ENUM(NSUInteger, MGLTextPitchAlignment) {
typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) {
/**
When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, aligns text
- east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine`,
- aligns text x-axes with the line.
+ east-west. When `symbolPlacement` is set to `MGLSymbolPlacementLine` or
+ `MGLSymbolPlacementLineCenter`, aligns text x-axes with the line.
*/
MGLTextRotationAlignmentMap,
/**
@@ -254,8 +260,8 @@ typedef NS_ENUM(NSUInteger, MGLTextRotationAlignment) {
/**
When `symbolPlacement` is set to `MGLSymbolPlacementPoint`, this is
equivalent to `MGLTextRotationAlignmentViewport`. When `symbolPlacement` is
- set to `MGLSymbolPlacementLine`, this is equivalent to
- `MGLTextRotationAlignmentMap`.
+ set to `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`, this is
+ equivalent to `MGLTextRotationAlignmentMap`.
*/
MGLTextRotationAlignmentAuto,
};
@@ -653,12 +659,13 @@ MGL_EXPORT
* Constant `MGLIconRotationAlignment` values
* Any of the following constant string values:
* `map`: When `symbol-placement` is set to `point`, aligns icons east-west.
- When `symbol-placement` is set to `line`, aligns icon x-axes with the line.
+ When `symbol-placement` is set to `line` or `line-center`, aligns icon x-axes
+ with the line.
* `viewport`: Produces icons whose x-axes are aligned with the x-axis of the
viewport, regardless of the value of `symbol-placement`.
* `auto`: When `symbol-placement` is set to `point`, this is equivalent to
- `viewport`. When `symbol-placement` is set to `line`, this is equivalent to
- `map`.
+ `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is
+ equivalent to `map`.
* Predefined functions, including mathematical and string operators
* Conditional expressions
* Variable assignments and references to assigned variables
@@ -795,8 +802,9 @@ MGL_EXPORT
This property is only applied to the style if `iconImageName` is non-`nil`, and
`iconRotationAlignment` is set to an expression that evaluates to `map`, and
- `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise,
- it is ignored.
+ `symbolPlacement` is set to an expression that evaluates to either
+ `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is
+ ignored.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-keep-upright"><code>icon-keep-upright</code></a>
@@ -828,8 +836,9 @@ MGL_EXPORT
This property is only applied to the style if `text` is non-`nil`, and
`textRotationAlignment` is set to an expression that evaluates to `map`, and
- `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise,
- it is ignored.
+ `symbolPlacement` is set to an expression that evaluates to either
+ `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is
+ ignored.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-keep-upright"><code>text-keep-upright</code></a>
@@ -861,8 +870,9 @@ MGL_EXPORT
`45`. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `text` is non-`nil`, and
- `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise,
- it is ignored.
+ `symbolPlacement` is set to an expression that evaluates to either
+ `MGLSymbolPlacementLine` or `MGLSymbolPlacementLineCenter`. Otherwise, it is
+ ignored.
This attribute corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-max-angle"><code>text-max-angle</code></a>
@@ -956,6 +966,9 @@ MGL_EXPORT
* `point`: The label is placed at the point where the geometry is located.
* `line`: The label is placed along the line of the geometry. Can only be
used on `LineString` and `Polygon` geometries.
+ * `line-center`: The label is placed at the center of the line of the
+ geometry. Can only be used on `LineString` and `Polygon` geometries. Note that
+ a single feature in a vector tile may contain multiple line geometries.
* Predefined functions, including mathematical and string operators
* Conditional expressions
* Variable assignments and references to assigned variables
@@ -1427,12 +1440,13 @@ MGL_EXPORT
* Constant `MGLTextRotationAlignment` values
* Any of the following constant string values:
* `map`: When `symbol-placement` is set to `point`, aligns text east-west.
- When `symbol-placement` is set to `line`, aligns text x-axes with the line.
+ When `symbol-placement` is set to `line` or `line-center`, aligns text x-axes
+ with the line.
* `viewport`: Produces glyphs whose x-axes are aligned with the x-axis of the
viewport, regardless of the value of `symbol-placement`.
* `auto`: When `symbol-placement` is set to `point`, this is equivalent to
- `viewport`. When `symbol-placement` is set to `line`, this is equivalent to
- `map`.
+ `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is
+ equivalent to `map`.
* Predefined functions, including mathematical and string operators
* Conditional expressions
* Variable assignments and references to assigned variables
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm
index f5522b800d..791bb5f894 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.mm
+++ b/platform/darwin/src/MGLSymbolStyleLayer.mm
@@ -47,6 +47,7 @@ namespace mbgl {
MBGL_DEFINE_ENUM(MGLSymbolPlacement, {
{ MGLSymbolPlacementPoint, "point" },
{ MGLSymbolPlacementLine, "line" },
+ { MGLSymbolPlacementLineCenter, "line-center" },
});
MBGL_DEFINE_ENUM(MGLTextAnchor, {
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
index 8643e8388b..9d772b6bd9 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
@@ -962,22 +962,22 @@
@"symbol-placement should be unset initially.");
NSExpression *defaultExpression = layer.symbolPlacement;
- NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'line'"];
+ NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'line-center'"];
layer.symbolPlacement = constantExpression;
- mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType> propertyValue = { mbgl::style::SymbolPlacementType::Line };
+ mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType> propertyValue = { mbgl::style::SymbolPlacementType::LineCenter };
XCTAssertEqual(rawLayer->getSymbolPlacement(), propertyValue,
@"Setting symbolPlacement to a constant value expression should update symbol-placement.");
XCTAssertEqualObjects(layer.symbolPlacement, constantExpression,
@"symbolPlacement should round-trip constant value expressions.");
- constantExpression = [NSExpression expressionWithFormat:@"'line'"];
+ constantExpression = [NSExpression expressionWithFormat:@"'line-center'"];
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
layer.symbolPlacement = functionExpression;
{
using namespace mbgl::style::expression::dsl;
propertyValue = mbgl::style::PropertyExpression<mbgl::style::SymbolPlacementType>(
- step(zoom(), literal("line"), 18.0, literal("line"))
+ step(zoom(), literal("line-center"), 18.0, literal("line-center"))
);
}
@@ -2883,6 +2883,7 @@
XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitBoth].MGLIconTextFitValue, MGLIconTextFitBoth);
XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementPoint].MGLSymbolPlacementValue, MGLSymbolPlacementPoint);
XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLine].MGLSymbolPlacementValue, MGLSymbolPlacementLine);
+ XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLineCenter].MGLSymbolPlacementValue, MGLSymbolPlacementLineCenter);
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorCenter].MGLTextAnchorValue, MGLTextAnchorCenter);
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorLeft].MGLTextAnchorValue, MGLTextAnchorLeft);
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorRight].MGLTextAnchorValue, MGLTextAnchorRight);