From da4eb01bc7b74b09405f9911ef506c190b426f9d Mon Sep 17 00:00:00 2001 From: Andrew Hay Kurtz Date: Tue, 17 Sep 2019 17:35:08 -0700 Subject: [core] Enable 'line-sort-key' and 'fill-sort-key' layout properties (#15839) - Generate style code for 'line-sort-key' and 'symbol-sort-key' - Add new layout properties to FillLayer::Impl, FillBucket, and FillLayerFactory - Fix consistency of paint and layout properties type alias usage in FillBucket, LineBucket - Add optional feature sorting to fill and line Layout creation - Enable node render tests for fill-sort-key and line-sort-key - Fix FillBucket test construction - Prefer emplace_back to push_back for PatternFeature container - Fix buggy static_cast for PatternFeature indices - Maintain sort of features as they are created - Switch pattern layout features container to list from vector for better insert performance - Fix formatting expected by sanity check - Use subclass PatternLayoutSorted to work around lack of template functions - Fix to retain source order for features with equivalent sort keys during sorting - [core] Fix clang-format - [core] Address review comments - [core] Pass inserting strategy class at compile time - [core] Use sorted strategy only if sort key is defined in layout - [core] Update style generator - [core] Merge PatternLayout and PatternLayoutSorted classes - Use static methods for inserter strategies - Merge PatternLayout and PatternLayoutSorted classes --- src/mbgl/style/layers/fill_layer.cpp | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'src/mbgl/style/layers/fill_layer.cpp') diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 9a43037871..757738dfef 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -55,11 +55,27 @@ std::unique_ptr FillLayer::cloneRef(const std::string& id_) const { return std::make_unique(std::move(impl_)); } -void FillLayer::Impl::stringifyLayout(rapidjson::Writer&) const { +void FillLayer::Impl::stringifyLayout(rapidjson::Writer& writer) const { + layout.stringify(writer); } // Layout properties +PropertyValue FillLayer::getDefaultFillSortKey() { + return FillSortKey::defaultValue(); +} + +const PropertyValue& FillLayer::getFillSortKey() const { + return impl().layout.get(); +} + +void FillLayer::setFillSortKey(const PropertyValue& value) { + if (value == getFillSortKey()) return; + auto impl_ = mutableImpl(); + impl_->layout.get() = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} // Paint properties @@ -271,6 +287,7 @@ enum class Property : uint8_t { FillPatternTransition, FillTranslateTransition, FillTranslateAnchorTransition, + FillSortKey, }; template @@ -292,7 +309,8 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"fill-outline-color-transition", toUint8(Property::FillOutlineColorTransition)}, {"fill-pattern-transition", toUint8(Property::FillPatternTransition)}, {"fill-translate-transition", toUint8(Property::FillTranslateTransition)}, - {"fill-translate-anchor-transition", toUint8(Property::FillTranslateAnchorTransition)}}); + {"fill-translate-anchor-transition", toUint8(Property::FillTranslateAnchorTransition)}, + {"fill-sort-key", toUint8(Property::FillSortKey)}}); } // namespace optional FillLayer::setProperty(const std::string& name, const Convertible& value) { @@ -331,15 +349,22 @@ optional FillLayer::setProperty(const std::string& name, const Convertibl return nullopt; } } - if (property == Property::FillOpacity) { + if (property == Property::FillOpacity || property == Property::FillSortKey) { Error error; const auto& typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - setFillOpacity(*typedValue); - return nullopt; + if (property == Property::FillOpacity) { + setFillOpacity(*typedValue); + return nullopt; + } + + if (property == Property::FillSortKey) { + setFillSortKey(*typedValue); + return nullopt; + } } if (property == Property::FillPattern) { Error error; @@ -451,6 +476,8 @@ StyleProperty FillLayer::getProperty(const std::string& name) const { return makeStyleProperty(getFillTranslateTransition()); case Property::FillTranslateAnchorTransition: return makeStyleProperty(getFillTranslateAnchorTransition()); + case Property::FillSortKey: + return makeStyleProperty(getFillSortKey()); } return {}; } -- cgit v1.2.1