diff options
Diffstat (limited to 'src/mbgl/style/layers/symbol_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/symbol_layer.cpp | 731 |
1 files changed, 332 insertions, 399 deletions
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 1383293d6d..fe9658b25a 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1249,127 +1249,424 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"text-transform", toUint8(Property::TextTransform)}, {"text-variable-anchor", toUint8(Property::TextVariableAnchor)}, {"text-writing-mode", toUint8(Property::TextWritingMode)}}); - -constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::TextTranslateAnchorTransition); } // namespace -optional<Error> SymbolLayer::setPaintProperty(const std::string& name, const Convertible& value) { +optional<Error> SymbolLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + if (it == layerProperties.end()) { + if (name == "visibility") return setVisibility(value); return Error{"layer doesn't support this property"}; } auto property = static_cast<Property>(it->second); - - if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || property == Property::TextHaloColor) { + if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || + property == Property::TextHaloColor) { Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); + const auto& typedValue = convert<PropertyValue<Color>>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::IconColor) { setIconColor(*typedValue); return nullopt; } - + if (property == Property::IconHaloColor) { setIconHaloColor(*typedValue); return nullopt; } - + if (property == Property::TextColor) { setTextColor(*typedValue); return nullopt; } - + if (property == Property::TextHaloColor) { setTextHaloColor(*typedValue); return nullopt; } - } - - if (property == Property::IconHaloBlur || property == Property::IconHaloWidth || property == Property::IconOpacity || property == Property::TextHaloBlur || property == Property::TextHaloWidth || property == Property::TextOpacity) { + if (property == Property::IconHaloBlur || property == Property::IconHaloWidth || + property == Property::IconOpacity || property == Property::TextHaloBlur || + property == Property::TextHaloWidth || property == Property::TextOpacity || property == Property::IconRotate || + property == Property::IconSize || property == Property::SymbolSortKey || + property == Property::TextLetterSpacing || property == Property::TextMaxWidth || + property == Property::TextRadialOffset || property == Property::TextRotate || property == Property::TextSize) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + const auto& typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - + if (property == Property::IconHaloBlur) { setIconHaloBlur(*typedValue); return nullopt; } - + if (property == Property::IconHaloWidth) { setIconHaloWidth(*typedValue); return nullopt; } - + if (property == Property::IconOpacity) { setIconOpacity(*typedValue); return nullopt; } - + if (property == Property::TextHaloBlur) { setTextHaloBlur(*typedValue); return nullopt; } - + if (property == Property::TextHaloWidth) { setTextHaloWidth(*typedValue); return nullopt; } - + if (property == Property::TextOpacity) { setTextOpacity(*typedValue); return nullopt; } - + + if (property == Property::IconRotate) { + setIconRotate(*typedValue); + return nullopt; + } + + if (property == Property::IconSize) { + setIconSize(*typedValue); + return nullopt; + } + + if (property == Property::SymbolSortKey) { + setSymbolSortKey(*typedValue); + return nullopt; + } + + if (property == Property::TextLetterSpacing) { + setTextLetterSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxWidth) { + setTextMaxWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextRadialOffset) { + setTextRadialOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextRotate) { + setTextRotate(*typedValue); + return nullopt; + } + + if (property == Property::TextSize) { + setTextSize(*typedValue); + return nullopt; + } } - if (property == Property::IconTranslate || property == Property::TextTranslate) { Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = - convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); + const auto& typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::IconTranslate) { setIconTranslate(*typedValue); return nullopt; } - + if (property == Property::TextTranslate) { setTextTranslate(*typedValue); return nullopt; } - } - if (property == Property::IconTranslateAnchor || property == Property::TextTranslateAnchor) { Error error; - optional<PropertyValue<TranslateAnchorType>> typedValue = - convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); + const auto& typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - + if (property == Property::IconTranslateAnchor) { setIconTranslateAnchor(*typedValue); return nullopt; } - + if (property == Property::TextTranslateAnchor) { setTextTranslateAnchor(*typedValue); return nullopt; } - } - + if (property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || + property == Property::IconKeepUpright || property == Property::IconOptional || + property == Property::SymbolAvoidEdges || property == Property::TextAllowOverlap || + property == Property::TextIgnorePlacement || property == Property::TextKeepUpright || + property == Property::TextOptional) { + Error error; + const auto& typedValue = convert<PropertyValue<bool>>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconAllowOverlap) { + setIconAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::IconIgnorePlacement) { + setIconIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::IconKeepUpright) { + setIconKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::IconOptional) { + setIconOptional(*typedValue); + return nullopt; + } + + if (property == Property::SymbolAvoidEdges) { + setSymbolAvoidEdges(*typedValue); + return nullopt; + } + + if (property == Property::TextAllowOverlap) { + setTextAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::TextIgnorePlacement) { + setTextIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::TextKeepUpright) { + setTextKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextOptional) { + setTextOptional(*typedValue); + return nullopt; + } + } + if (property == Property::IconAnchor || property == Property::TextAnchor) { + Error error; + const auto& typedValue = convert<PropertyValue<SymbolAnchorType>>(value, error, true, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconAnchor) { + setIconAnchor(*typedValue); + return nullopt; + } + + if (property == Property::TextAnchor) { + setTextAnchor(*typedValue); + return nullopt; + } + } + if (property == Property::IconImage) { + Error error; + const auto& typedValue = convert<PropertyValue<expression::Image>>(value, error, true, true); + if (!typedValue) { + return error; + } + + setIconImage(*typedValue); + return nullopt; + } + if (property == Property::IconOffset || property == Property::TextOffset) { + Error error; + const auto& typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, true, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconOffset) { + setIconOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextOffset) { + setTextOffset(*typedValue); + return nullopt; + } + } + if (property == Property::IconPadding || property == Property::SymbolSpacing || + property == Property::TextLineHeight || property == Property::TextMaxAngle || + property == Property::TextPadding) { + Error error; + const auto& typedValue = convert<PropertyValue<float>>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconPadding) { + setIconPadding(*typedValue); + return nullopt; + } + + if (property == Property::SymbolSpacing) { + setSymbolSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextLineHeight) { + setTextLineHeight(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxAngle) { + setTextMaxAngle(*typedValue); + return nullopt; + } + + if (property == Property::TextPadding) { + setTextPadding(*typedValue); + return nullopt; + } + } + if (property == Property::IconPitchAlignment || property == Property::IconRotationAlignment || + property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { + Error error; + const auto& typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconPitchAlignment) { + setIconPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::IconRotationAlignment) { + setIconRotationAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextPitchAlignment) { + setTextPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextRotationAlignment) { + setTextRotationAlignment(*typedValue); + return nullopt; + } + } + if (property == Property::IconTextFit) { + Error error; + const auto& typedValue = convert<PropertyValue<IconTextFitType>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setIconTextFit(*typedValue); + return nullopt; + } + if (property == Property::IconTextFitPadding) { + Error error; + const auto& typedValue = convert<PropertyValue<std::array<float, 4>>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setIconTextFitPadding(*typedValue); + return nullopt; + } + if (property == Property::SymbolPlacement) { + Error error; + const auto& typedValue = convert<PropertyValue<SymbolPlacementType>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setSymbolPlacement(*typedValue); + return nullopt; + } + if (property == Property::SymbolZOrder) { + Error error; + const auto& typedValue = convert<PropertyValue<SymbolZOrderType>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setSymbolZOrder(*typedValue); + return nullopt; + } + if (property == Property::TextField) { + Error error; + const auto& typedValue = convert<PropertyValue<expression::Formatted>>(value, error, true, true); + if (!typedValue) { + return error; + } + + setTextField(*typedValue); + return nullopt; + } + if (property == Property::TextFont) { + Error error; + const auto& typedValue = convert<PropertyValue<std::vector<std::string>>>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextFont(*typedValue); + return nullopt; + } + if (property == Property::TextJustify) { + Error error; + const auto& typedValue = convert<PropertyValue<TextJustifyType>>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextJustify(*typedValue); + return nullopt; + } + if (property == Property::TextTransform) { + Error error; + const auto& typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false); + if (!typedValue) { + return error; + } + + setTextTransform(*typedValue); + return nullopt; + } + if (property == Property::TextVariableAnchor) { + Error error; + const auto& typedValue = + convert<PropertyValue<std::vector<TextVariableAnchorType>>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setTextVariableAnchor(*typedValue); + return nullopt; + } + if (property == Property::TextWritingMode) { + Error error; + const auto& typedValue = convert<PropertyValue<std::vector<TextWritingModeType>>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setTextWritingMode(*typedValue); + return nullopt; + } Error error; optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); @@ -1599,370 +1896,6 @@ StyleProperty SymbolLayer::getProperty(const std::string& name) const { return {}; } -optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Convertible& value) { - if (name == "visibility") { - return Layer::setVisibility(value); - } - const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end() || it->second <= lastPaintPropertyIndex) { - return Error { "layer doesn't support this property" }; - } - - auto property = static_cast<Property>(it->second); - - - if (property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || property == Property::IconKeepUpright || property == Property::IconOptional || property == Property::SymbolAvoidEdges || property == Property::TextAllowOverlap || property == Property::TextIgnorePlacement || property == Property::TextKeepUpright || property == Property::TextOptional) { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconAllowOverlap) { - setIconAllowOverlap(*typedValue); - return nullopt; - } - - if (property == Property::IconIgnorePlacement) { - setIconIgnorePlacement(*typedValue); - return nullopt; - } - - if (property == Property::IconKeepUpright) { - setIconKeepUpright(*typedValue); - return nullopt; - } - - if (property == Property::IconOptional) { - setIconOptional(*typedValue); - return nullopt; - } - - if (property == Property::SymbolAvoidEdges) { - setSymbolAvoidEdges(*typedValue); - return nullopt; - } - - if (property == Property::TextAllowOverlap) { - setTextAllowOverlap(*typedValue); - return nullopt; - } - - if (property == Property::TextIgnorePlacement) { - setTextIgnorePlacement(*typedValue); - return nullopt; - } - - if (property == Property::TextKeepUpright) { - setTextKeepUpright(*typedValue); - return nullopt; - } - - if (property == Property::TextOptional) { - setTextOptional(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconAnchor || property == Property::TextAnchor) { - Error error; - optional<PropertyValue<SymbolAnchorType>> typedValue = - convert<PropertyValue<SymbolAnchorType>>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconAnchor) { - setIconAnchor(*typedValue); - return nullopt; - } - - if (property == Property::TextAnchor) { - setTextAnchor(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconImage) { - Error error; - optional<PropertyValue<expression::Image>> typedValue = - convert<PropertyValue<expression::Image>>(value, error, true, true); - if (!typedValue) { - return error; - } - - setIconImage(*typedValue); - return nullopt; - - } - - if (property == Property::IconOffset || property == Property::TextOffset) { - Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = - convert<PropertyValue<std::array<float, 2>>>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconOffset) { - setIconOffset(*typedValue); - return nullopt; - } - - if (property == Property::TextOffset) { - setTextOffset(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconPadding || property == Property::SymbolSpacing || property == Property::TextLineHeight || property == Property::TextMaxAngle || property == Property::TextPadding) { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconPadding) { - setIconPadding(*typedValue); - return nullopt; - } - - if (property == Property::SymbolSpacing) { - setSymbolSpacing(*typedValue); - return nullopt; - } - - if (property == Property::TextLineHeight) { - setTextLineHeight(*typedValue); - return nullopt; - } - - if (property == Property::TextMaxAngle) { - setTextMaxAngle(*typedValue); - return nullopt; - } - - if (property == Property::TextPadding) { - setTextPadding(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconPitchAlignment || property == Property::IconRotationAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { - Error error; - optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconPitchAlignment) { - setIconPitchAlignment(*typedValue); - return nullopt; - } - - if (property == Property::IconRotationAlignment) { - setIconRotationAlignment(*typedValue); - return nullopt; - } - - if (property == Property::TextPitchAlignment) { - setTextPitchAlignment(*typedValue); - return nullopt; - } - - if (property == Property::TextRotationAlignment) { - setTextRotationAlignment(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconRotate || property == Property::IconSize || property == Property::SymbolSortKey || property == Property::TextLetterSpacing || property == Property::TextMaxWidth || property == Property::TextRadialOffset || property == Property::TextRotate || property == Property::TextSize) { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - if (property == Property::IconRotate) { - setIconRotate(*typedValue); - return nullopt; - } - - if (property == Property::IconSize) { - setIconSize(*typedValue); - return nullopt; - } - - if (property == Property::SymbolSortKey) { - setSymbolSortKey(*typedValue); - return nullopt; - } - - if (property == Property::TextLetterSpacing) { - setTextLetterSpacing(*typedValue); - return nullopt; - } - - if (property == Property::TextMaxWidth) { - setTextMaxWidth(*typedValue); - return nullopt; - } - - if (property == Property::TextRadialOffset) { - setTextRadialOffset(*typedValue); - return nullopt; - } - - if (property == Property::TextRotate) { - setTextRotate(*typedValue); - return nullopt; - } - - if (property == Property::TextSize) { - setTextSize(*typedValue); - return nullopt; - } - - } - - if (property == Property::IconTextFit) { - Error error; - optional<PropertyValue<IconTextFitType>> typedValue = - convert<PropertyValue<IconTextFitType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTextFit(*typedValue); - return nullopt; - - } - - if (property == Property::IconTextFitPadding) { - Error error; - optional<PropertyValue<std::array<float, 4>>> typedValue = - convert<PropertyValue<std::array<float, 4>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTextFitPadding(*typedValue); - return nullopt; - - } - - if (property == Property::SymbolPlacement) { - Error error; - optional<PropertyValue<SymbolPlacementType>> typedValue = - convert<PropertyValue<SymbolPlacementType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setSymbolPlacement(*typedValue); - return nullopt; - - } - - if (property == Property::SymbolZOrder) { - Error error; - optional<PropertyValue<SymbolZOrderType>> typedValue = - convert<PropertyValue<SymbolZOrderType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setSymbolZOrder(*typedValue); - return nullopt; - - } - - if (property == Property::TextField) { - Error error; - optional<PropertyValue<expression::Formatted>> typedValue = - convert<PropertyValue<expression::Formatted>>(value, error, true, true); - if (!typedValue) { - return error; - } - - setTextField(*typedValue); - return nullopt; - - } - - if (property == Property::TextFont) { - Error error; - optional<PropertyValue<std::vector<std::string>>> typedValue = - convert<PropertyValue<std::vector<std::string>>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextFont(*typedValue); - return nullopt; - - } - - if (property == Property::TextJustify) { - Error error; - optional<PropertyValue<TextJustifyType>> typedValue = convert<PropertyValue<TextJustifyType>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextJustify(*typedValue); - return nullopt; - - } - - if (property == Property::TextTransform) { - Error error; - optional<PropertyValue<TextTransformType>> typedValue = - convert<PropertyValue<TextTransformType>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextTransform(*typedValue); - return nullopt; - - } - - 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::TextWritingMode) { - Error error; - optional<PropertyValue<std::vector<TextWritingModeType>>> typedValue = - convert<PropertyValue<std::vector<TextWritingModeType>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextWritingMode(*typedValue); - return nullopt; - - } - - - return Error { "layer doesn't support this property" }; -} - Mutable<Layer::Impl> SymbolLayer::mutableBaseImpl() const { return staticMutableCast<Layer::Impl>(mutableImpl()); } |