From 141e995806576364d185626176c1b993fc519291 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 28 Oct 2016 16:39:50 -0700 Subject: [core] Add support for data-driven styling --- include/mbgl/style/function/source_function.hpp | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 include/mbgl/style/function/source_function.hpp (limited to 'include/mbgl/style/function/source_function.hpp') diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp new file mode 100644 index 0000000000..e998be082a --- /dev/null +++ b/include/mbgl/style/function/source_function.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace mbgl { +namespace style { + +template +class SourceFunction { +public: + using Stops = std::conditional_t< + util::Interpolatable, + variant< + ExponentialStops, + IntervalStops, + CategoricalStops, + IdentityStops>, + variant< + IntervalStops, + CategoricalStops, + IdentityStops>>; + + SourceFunction(std::string property_, Stops stops_) + : property(std::move(property_)), + stops(std::move(stops_)) { + } + + T evaluate(const GeometryTileFeature& feature) const { + optional v = feature.getValue(property); + if (!v) { + return T(); + } + return stops.match([&] (const auto& s) { + return s.evaluate(*v); + }); + } + + friend bool operator==(const SourceFunction& lhs, + const SourceFunction& rhs) { + return lhs.property == rhs.property && lhs.stops == rhs.stops; + } + + std::string property; + Stops stops; +}; + +} // namespace style +} // namespace mbgl -- cgit v1.2.1