[core] Enable text-variable-anchor property

This commit is contained in:
Mikhail Pozdnyakov
2019-03-07 18:34:45 +02:00
parent 4adfc5d323
commit a6d8742e63
19 changed files with 152 additions and 4 deletions

View File

@@ -49,6 +49,27 @@ optional<T> Converter<T, typename std::enable_if_t<std::is_enum<T>::value>>::ope
return *result;
}
template <class T>
auto Converter<std::vector<T>, typename std::enable_if_t<std::is_enum<T>::value>>::operator()(const Convertible& value, Error& error) const -> optional<std::vector<T>> {
if (!isArray(value)) {
error.message = "value must be an array";
return nullopt;
}
std::vector<T> result;
result.reserve(arrayLength(value));
for (std::size_t i = 0; i < arrayLength(value); ++i) {
optional<T> enumItem = Converter<T>{}(arrayMember(value, i), error);
if (!enumItem) {
return nullopt;
}
result.push_back(*enumItem);
}
return result;
}
template optional<AlignmentType> Converter<AlignmentType>::operator()(const Convertible&, Error&) const;
template optional<CirclePitchScaleType> Converter<CirclePitchScaleType>::operator()(const Convertible&, Error&) const;
template optional<HillshadeIlluminationAnchorType> Converter<HillshadeIlluminationAnchorType>::operator()(const Convertible&, Error&) const;
@@ -64,6 +85,7 @@ template optional<TextJustifyType> Converter<TextJustifyType>::operator()(const
template optional<TextTransformType> Converter<TextTransformType>::operator()(const Convertible&, Error&) const;
template optional<TranslateAnchorType> Converter<TranslateAnchorType>::operator()(const Convertible&, Error&) const;
template optional<VisibilityType> Converter<VisibilityType>::operator()(const Convertible&, Error&) const;
template optional<std::vector<TextVariableAnchorType>> Converter<std::vector<TextVariableAnchorType>>::operator()(const Convertible&, Error&) const;
optional<Color> Converter<Color>::operator()(const Convertible& value, Error& error) const {
optional<std::string> string = toString(value);
@@ -125,6 +147,11 @@ optional<std::vector<float>> Converter<std::vector<float>>::operator()(const Con
return result;
}
namespace {
} // namespace
optional<std::vector<std::string>> Converter<std::vector<std::string>>::operator()(const Convertible& value, Error& error) const {
if (!isArray(value)) {
error.message = "value must be an array";

View File

@@ -136,6 +136,8 @@ template optional<PropertyExpression<std::vector<std::string>>>
convertFunctionToExpression<std::vector<std::string>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolAnchorType>>
convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<std::vector<TextVariableAnchorType>>>
convertFunctionToExpression<std::vector<TextVariableAnchorType>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolPlacementType>>
convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolZOrderType>>

View File

@@ -73,6 +73,7 @@ template optional<PropertyValue<LineJoinType>> Converter<PropertyValue<LineJoinT
template optional<PropertyValue<Position>> Converter<PropertyValue<Position>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<RasterResamplingType>> Converter<PropertyValue<RasterResamplingType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<SymbolAnchorType>> Converter<PropertyValue<SymbolAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<std::vector<TextVariableAnchorType>>> Converter<PropertyValue<std::vector<TextVariableAnchorType>>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<SymbolPlacementType>> Converter<PropertyValue<SymbolPlacementType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<SymbolZOrderType>> Converter<PropertyValue<SymbolZOrderType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TextJustifyType>> Converter<PropertyValue<TextJustifyType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;

View File

@@ -329,6 +329,9 @@ template struct ValueConverter<std::vector<float>>;
template type::Type valueTypeToExpressionType<std::vector<std::string>>();
template struct ValueConverter<std::vector<std::string>>;
template type::Type valueTypeToExpressionType<std::vector<TextVariableAnchorType>>();
template struct ValueConverter<std::vector<TextVariableAnchorType>>;
template type::Type valueTypeToExpressionType<AlignmentType>();
template struct ValueConverter<AlignmentType>;

View File

@@ -492,6 +492,22 @@ void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) {
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
PropertyValue<std::vector<TextVariableAnchorType>> SymbolLayer::getDefaultTextVariableAnchor() {
return TextVariableAnchor::defaultValue();
}
PropertyValue<std::vector<TextVariableAnchorType>> SymbolLayer::getTextVariableAnchor() const {
return impl().layout.get<TextVariableAnchor>();
}
void SymbolLayer::setTextVariableAnchor(PropertyValue<std::vector<TextVariableAnchorType>> value) {
if (value == getTextVariableAnchor())
return;
auto impl_ = mutableImpl();
impl_->layout.get<TextVariableAnchor>() = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
PropertyValue<SymbolAnchorType> SymbolLayer::getDefaultTextAnchor() {
return TextAnchor::defaultValue();
}
@@ -1325,6 +1341,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
TextLineHeight,
TextLetterSpacing,
TextJustify,
TextVariableAnchor,
TextAnchor,
TextMaxAngle,
TextRotate,
@@ -1364,6 +1381,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
{ "text-line-height", static_cast<uint8_t>(Property::TextLineHeight) },
{ "text-letter-spacing", static_cast<uint8_t>(Property::TextLetterSpacing) },
{ "text-justify", static_cast<uint8_t>(Property::TextJustify) },
{ "text-variable-anchor", static_cast<uint8_t>(Property::TextVariableAnchor) },
{ "text-anchor", static_cast<uint8_t>(Property::TextAnchor) },
{ "text-max-angle", static_cast<uint8_t>(Property::TextMaxAngle) },
{ "text-rotate", static_cast<uint8_t>(Property::TextRotate) },
@@ -1674,6 +1692,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
if (property == Property::TextVariableAnchor) {
Error error;
optional<PropertyValue<std::vector<TextVariableAnchorType>>> typedValue = convert<PropertyValue<std::vector<TextVariableAnchorType>>>(value, error, false, false);
if (!typedValue) {
return error;
}
setTextVariableAnchor(*typedValue);
return nullopt;
}
if (property == Property::TextTransform) {
Error error;
optional<PropertyValue<TextTransformType>> typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false);

View File

@@ -147,6 +147,11 @@ struct TextJustify : DataDrivenLayoutProperty<TextJustifyType> {
static TextJustifyType defaultValue() { return TextJustifyType::Center; }
};
struct TextVariableAnchor : LayoutProperty<std::vector<TextVariableAnchorType>> {
static constexpr const char *name() { return "text-variable-anchor"; }
static std::vector<TextVariableAnchorType> defaultValue() { return { }; }
};
struct TextAnchor : DataDrivenLayoutProperty<SymbolAnchorType> {
static constexpr const char *name() { return "text-anchor"; }
static SymbolAnchorType defaultValue() { return SymbolAnchorType::Center; }
@@ -284,6 +289,7 @@ class SymbolLayoutProperties : public Properties<
TextLineHeight,
TextLetterSpacing,
TextJustify,
TextVariableAnchor,
TextAnchor,
TextMaxAngle,
TextRotate,

View File

@@ -76,7 +76,7 @@ MBGL_DEFINE_ENUM(SymbolAnchorType, {
{ SymbolAnchorType::BottomLeft, "bottom-left" },
{ SymbolAnchorType::BottomRight, "bottom-right" }
});
MBGL_DEFINE_ENUM(SymbolZOrderType, {
{ SymbolZOrderType::ViewportY, "viewport-y" },
{ SymbolZOrderType::Source, "source" }