diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-25 13:15:44 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-02 14:51:39 -0700 |
commit | a43940afb2208c61b487bfd8729bbde1bd674794 (patch) | |
tree | 53d192ea899be1d88f99aeef3d1b3255f9cb5104 /include/mbgl/style | |
parent | 27baa34d44f0006c05ba7c417bf11e184b0bd22b (diff) | |
download | qtlocation-mapboxgl-a43940afb2208c61b487bfd8729bbde1bd674794.tar.gz |
[core] Runtime style layer API
Diffstat (limited to 'include/mbgl/style')
-rw-r--r-- | include/mbgl/style/layer.hpp | 78 | ||||
-rw-r--r-- | include/mbgl/style/types.hpp | 21 |
2 files changed, 99 insertions, 0 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp new file mode 100644 index 0000000000..e6c33a9784 --- /dev/null +++ b/include/mbgl/style/layer.hpp @@ -0,0 +1,78 @@ +#ifndef MBGL_LAYER +#define MBGL_LAYER + +#include <mbgl/util/noncopyable.hpp> +#include <mbgl/style/types.hpp> + +#include <memory> + +namespace mbgl { + +/** + * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style + * Specification. + * + * `Layer` is an abstract base class; concrete derived classes are provided for each layer type. `Layer` contains + * functionality that is common to all layer types: + * + * * Runtime type information: type predicates and casting + * * Accessors for properties common to all layer types: ID, visibility, etc. + * * Cloning and copying + * + * All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired + * type, passing the ID: + * + * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer"); + */ +class Layer : public mbgl::util::noncopyable { +public: + virtual ~Layer(); + + // Check whether this layer is of the given subtype. + template <class T> + bool is() const; + + // Dynamically cast this layer to the given subtype. + template <class T> + T* as() { + return is<T>() ? reinterpret_cast<T*>(this) : nullptr; + } + + template <class T> + const T* as() const { + return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; + } + + const std::string& getID() const; + + // Visibility + VisibilityType getVisibility() const; + void setVisibility(VisibilityType); + + // Create a new layer with the specified `id` and `ref`. All other properties + // are copied from this layer. + std::unique_ptr<Layer> copy(const std::string& id, + const std::string& ref) const; + + // Private implementation + class Impl; + const std::unique_ptr<Impl> baseImpl; + +protected: + enum class Type { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + }; + + const Type type; + Layer(Type, std::unique_ptr<Impl>); +}; + +} // namespace mbgl + +#endif diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 9b03ab8a2d..a852a09a14 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -5,6 +5,7 @@ #include <string> #include <array> #include <vector> +#include <utility> namespace mbgl { @@ -20,6 +21,26 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; +template <typename T> +class Function { +public: + using Stop = std::pair<float, T>; + using Stops = std::vector<Stop>; + + Function(const T& constant) + : stops({{ 0, constant }}) {} + + explicit Function(const Stops& stops_, float base_) + : base(base_), stops(stops_) {} + + float getBase() const { return base; } + const std::vector<std::pair<float, T>>& getStops() const { return stops; } + +private: + float base = 1; + std::vector<std::pair<float, T>> stops; +}; + // ------------------------------------------------------------------------------------------------- enum class SourceType : uint8_t { |