diff --git a/src/mbgl/style/paint_property_binder.hpp b/src/mbgl/style/paint_property_binder.hpp index bf98e6ef9..3915ee588 100644 --- a/src/mbgl/style/paint_property_binder.hpp +++ b/src/mbgl/style/paint_property_binder.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -90,6 +91,8 @@ public: virtual float interpolationFactor(float currentZoom) const = 0; static std::unique_ptr create(const PossiblyEvaluatedPropertyValue& value, float zoom, T defaultValue); + + PaintPropertyStatistics statistics; }; template @@ -136,7 +139,9 @@ public: } void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { - auto value = attributeValue(function.evaluate(feature, defaultValue)); + auto evaluated = function.evaluate(feature, defaultValue); + this->statistics.add(evaluated); + auto value = attributeValue(evaluated); for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) { vertexVector.emplace_back(BaseVertex { value }); } @@ -187,6 +192,8 @@ public: void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { Range range = function.evaluate(std::get<1>(coveringRanges), feature, defaultValue); + this->statistics.add(range.min); + this->statistics.add(range.max); AttributeValue value = zoomInterpolatedAttributeValue( attributeValue(range.min), attributeValue(range.max)); @@ -312,6 +319,11 @@ public: }; } + template + const auto& statistics() const { + return binders.template get

()->statistics; + } + private: Binders binders; }; diff --git a/src/mbgl/style/paint_property_statistics.hpp b/src/mbgl/style/paint_property_statistics.hpp new file mode 100644 index 000000000..01d634dd6 --- /dev/null +++ b/src/mbgl/style/paint_property_statistics.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace mbgl { +namespace style { + +template +class PaintPropertyStatistics { +public: + optional max() const { return {}; } + void add(const T&) {} +}; + +template <> +class PaintPropertyStatistics { +public: + optional max() const { + return _max; + } + + void add(float value) { + _max = _max ? std::max(*_max, value) : value; + } + +private: + optional _max; +}; + +} // namespace style +} // namespace mbgl