[darwin] Support for variable text placement API
This commit is contained in:
@@ -307,10 +307,8 @@ private: // Private utilities for converting from mbgl to mgl values
|
||||
|
||||
// Enumerations
|
||||
template <typename MBGLEnum = MBGLType, typename MGLEnum = ObjCEnum>
|
||||
static NSValue *toMGLRawStyleValue(const MBGLEnum &value) {
|
||||
auto str = mbgl::Enum<MBGLEnum>::toString(value);
|
||||
MGLEnum mglType = *mbgl::Enum<MGLEnum>::toEnum(str);
|
||||
return [NSValue value:&mglType withObjCType:@encode(MGLEnum)];
|
||||
static NSString *toMGLRawStyleValue(const MBGLEnum &value) {
|
||||
return @(mbgl::Enum<MBGLEnum>::toString(value));
|
||||
}
|
||||
|
||||
/// Converts all types of mbgl property values into an equivalent NSExpression.
|
||||
@@ -320,15 +318,6 @@ private: // Private utilities for converting from mbgl to mgl values
|
||||
return nil;
|
||||
}
|
||||
|
||||
/**
|
||||
As hack to allow converting enum => string values, we accept a second, dummy parameter in
|
||||
the toRawStyleSpecValue() methods for converting 'atomic' (non-style-function) values.
|
||||
This allows us to use `std::enable_if` to test (at compile time) whether or not MBGLType is an Enum.
|
||||
*/
|
||||
template <typename MBGLEnum = MBGLType,
|
||||
class = typename std::enable_if<!std::is_enum<MBGLEnum>::value>::type,
|
||||
typename MGLEnum = ObjCEnum,
|
||||
class = typename std::enable_if<!std::is_enum<MGLEnum>::value>::type>
|
||||
NSExpression *operator()(const MBGLType &value) const {
|
||||
id constantValue = toMGLRawStyleValue(value);
|
||||
if ([constantValue isKindOfClass:[NSArray class]]) {
|
||||
@@ -337,15 +326,6 @@ private: // Private utilities for converting from mbgl to mgl values
|
||||
return [NSExpression expressionForConstantValue:constantValue];
|
||||
}
|
||||
|
||||
template <typename MBGLEnum = MBGLType,
|
||||
class = typename std::enable_if<std::is_enum<MBGLEnum>::value>::type,
|
||||
typename MGLEnum = ObjCEnum,
|
||||
class = typename std::enable_if<std::is_enum<MGLEnum>::value>::type>
|
||||
NSExpression *operator()(const MBGLEnum &value) const {
|
||||
NSString *constantValue = @(mbgl::Enum<MBGLEnum>::toString(value));
|
||||
return [NSExpression expressionForConstantValue:constantValue];
|
||||
}
|
||||
|
||||
NSExpression *operator()(const mbgl::style::PropertyExpression<MBGLType> &mbglValue) const {
|
||||
return [NSExpression expressionWithMGLJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())];
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ typedef NS_ENUM(NSUInteger, MGLTextAnchor) {
|
||||
property.
|
||||
*/
|
||||
typedef NS_ENUM(NSUInteger, MGLTextJustification) {
|
||||
/**
|
||||
The text is aligned towards the anchor position.
|
||||
*/
|
||||
MGLTextJustificationAuto,
|
||||
/**
|
||||
The text is aligned to the left.
|
||||
*/
|
||||
@@ -1279,6 +1283,7 @@ MGL_EXPORT
|
||||
|
||||
* Constant `MGLTextJustification` values
|
||||
* Any of the following constant string values:
|
||||
* `auto`: The text is aligned towards the anchor position.
|
||||
* `left`: The text is aligned to the left.
|
||||
* `center`: The text is centered.
|
||||
* `right`: The text is aligned to the right.
|
||||
@@ -1349,8 +1354,8 @@ MGL_EXPORT
|
||||
`NSValue` object containing a `CGVector` struct set to 0 ems rightward and 0
|
||||
ems downward. 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`. Otherwise,
|
||||
it is ignored.
|
||||
This property is only applied to the style if `text` is non-`nil`, and
|
||||
`textRadialOffset` is set to `nil`. Otherwise, it is ignored.
|
||||
|
||||
You can set this property to an expression containing any of the following:
|
||||
|
||||
@@ -1372,8 +1377,8 @@ MGL_EXPORT
|
||||
`NSValue` object containing a `CGVector` struct set to 0 ems rightward and 0
|
||||
ems upward. 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`. Otherwise,
|
||||
it is ignored.
|
||||
This property is only applied to the style if `text` is non-`nil`, and
|
||||
`textRadialOffset` is set to `nil`. Otherwise, it is ignored.
|
||||
|
||||
You can set this property to an expression containing any of the following:
|
||||
|
||||
@@ -1463,6 +1468,27 @@ MGL_EXPORT
|
||||
*/
|
||||
@property (nonatomic, null_resettable) NSExpression *textPitchAlignment;
|
||||
|
||||
/**
|
||||
Radial offset of text, in the direction of the symbol's anchor. Useful in
|
||||
combination with `textVariableAnchor`, which doesn't support the
|
||||
two-dimensional `textOffset`.
|
||||
|
||||
This property is measured in ems.
|
||||
|
||||
This property is only applied to the style if `textOffset` is set to `nil`.
|
||||
Otherwise, it is ignored.
|
||||
|
||||
You can set this property to an expression containing any of the following:
|
||||
|
||||
* Constant numeric values
|
||||
* Predefined functions, including mathematical and string operators
|
||||
* Conditional expressions
|
||||
* Variable assignments and references to assigned variables
|
||||
* Interpolation and step functions applied to the `$zoomLevel` variable and/or
|
||||
feature attributes
|
||||
*/
|
||||
@property (nonatomic, null_resettable) NSExpression *textRadialOffset;
|
||||
|
||||
/**
|
||||
Rotates the text clockwise.
|
||||
|
||||
@@ -1549,6 +1575,32 @@ MGL_EXPORT
|
||||
*/
|
||||
@property (nonatomic, null_resettable) NSExpression *textTransform;
|
||||
|
||||
/**
|
||||
To increase the chance of placing high-priority labels on the map, you can
|
||||
provide an array of `textAnchor` locations: the render will attempt to place
|
||||
the label at each location, in order, before moving onto the next label. Use
|
||||
`textJustify: auto` to choose justification based on anchor position. To apply
|
||||
an offset, use the `textRadialOffset` instead of the two-dimensional
|
||||
`textOffset`.
|
||||
|
||||
This property is only applied to the style if `textAnchor` is set to `nil`, and
|
||||
`textOffset` is set to `nil`, and `symbolPlacement` is set to an expression
|
||||
that evaluates to or `MGLSymbolPlacementPoint`. Otherwise, it is ignored.
|
||||
|
||||
You can set this property to an expression containing any of the following:
|
||||
|
||||
* Constant array values
|
||||
* Predefined functions, including mathematical and string operators
|
||||
* Conditional expressions
|
||||
* Variable assignments and references to assigned variables
|
||||
* Step functions applied to the `$zoomLevel` variable
|
||||
|
||||
This property does not support applying interpolation functions to the
|
||||
`$zoomLevel` variable or applying interpolation or step functions to feature
|
||||
attributes.
|
||||
*/
|
||||
@property (nonatomic, null_resettable) NSExpression *textVariableAnchor;
|
||||
|
||||
#pragma mark - Accessing the Paint Attributes
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace mbgl {
|
||||
});
|
||||
|
||||
MBGL_DEFINE_ENUM(MGLTextJustification, {
|
||||
{ MGLTextJustificationAuto, "auto" },
|
||||
{ MGLTextJustificationLeft, "left" },
|
||||
{ MGLTextJustificationCenter, "center" },
|
||||
{ MGLTextJustificationRight, "right" },
|
||||
@@ -906,6 +907,24 @@ namespace mbgl {
|
||||
return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toExpression(propertyValue);
|
||||
}
|
||||
|
||||
- (void)setTextRadialOffset:(NSExpression *)textRadialOffset {
|
||||
MGLAssertStyleLayerIsValid();
|
||||
MGLLogDebug(@"Setting textRadialOffset: %@", textRadialOffset);
|
||||
|
||||
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(textRadialOffset, true);
|
||||
self.rawLayer->setTextRadialOffset(mbglValue);
|
||||
}
|
||||
|
||||
- (NSExpression *)textRadialOffset {
|
||||
MGLAssertStyleLayerIsValid();
|
||||
|
||||
auto propertyValue = self.rawLayer->getTextRadialOffset();
|
||||
if (propertyValue.isUndefined()) {
|
||||
propertyValue = self.rawLayer->getDefaultTextRadialOffset();
|
||||
}
|
||||
return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue);
|
||||
}
|
||||
|
||||
- (void)setTextRotation:(NSExpression *)textRotation {
|
||||
MGLAssertStyleLayerIsValid();
|
||||
MGLLogDebug(@"Setting textRotation: %@", textRotation);
|
||||
@@ -967,6 +986,24 @@ namespace mbgl {
|
||||
return MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toExpression(propertyValue);
|
||||
}
|
||||
|
||||
- (void)setTextVariableAnchor:(NSExpression *)textVariableAnchor {
|
||||
MGLAssertStyleLayerIsValid();
|
||||
MGLLogDebug(@"Setting textVariableAnchor: %@", textVariableAnchor);
|
||||
|
||||
auto mbglValue = MGLStyleValueTransformer<std::vector<mbgl::style::SymbolAnchorType>, NSArray<NSValue *> *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toPropertyValue<mbgl::style::PropertyValue<std::vector<mbgl::style::SymbolAnchorType>>>(textVariableAnchor, false);
|
||||
self.rawLayer->setTextVariableAnchor(mbglValue);
|
||||
}
|
||||
|
||||
- (NSExpression *)textVariableAnchor {
|
||||
MGLAssertStyleLayerIsValid();
|
||||
|
||||
auto propertyValue = self.rawLayer->getTextVariableAnchor();
|
||||
if (propertyValue.isUndefined()) {
|
||||
propertyValue = self.rawLayer->getDefaultTextVariableAnchor();
|
||||
}
|
||||
return MGLStyleValueTransformer<std::vector<mbgl::style::SymbolAnchorType>, NSArray<NSValue *> *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toExpression(propertyValue);
|
||||
}
|
||||
|
||||
#pragma mark - Accessing the Paint Attributes
|
||||
|
||||
- (void)setIconColor:(NSExpression *)iconColor {
|
||||
|
||||
Reference in New Issue
Block a user