MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
layer.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include <mbgl/style/types.hpp>
7 
8 #include <mapbox/std/weak.hpp>
9 #include <mapbox/util/type_wrapper.hpp>
10 
11 #include <cassert>
12 #include <memory>
13 #include <string>
14 #include <stdexcept>
15 #include <optional>
16 
17 namespace mbgl {
18 namespace style {
19 
20 class LayerObserver;
21 class Filter;
22 
26 struct LayerTypeInfo {
30  const char* type;
31 
36  const enum class Source { Required, NotRequired } source;
37 
42  const enum class Pass3D { Required, NotRequired } pass3d;
43 
48  const enum class Layout { Required, NotRequired } layout;
49 
54  const enum class FadingTiles { Required, NotRequired } fadingTiles;
55 
60  const enum class CrossTileIndex { Required, NotRequired } crossTileIndex;
61 
66  const enum class TileKind : uint8_t { Geometry, Raster, RasterDEM, NotRequired } tileKind;
67 };
68 
85 class Layer {
86 public:
87  Layer(const Layer& ) = delete;
88  Layer& operator=(const Layer&) = delete;
89 
90  virtual ~Layer();
91 
92  std::string getID() const;
93  // Source
94  std::string getSourceID() const;
95  std::string getSourceLayer() const;
96  void setSourceLayer(const std::string& sourceLayer);
97  void setSourceID(const std::string& sourceID);
98 
99  // Filter
100  const Filter& getFilter() const;
101  void setFilter(const Filter&);
102 
103  // Visibility
104  VisibilityType getVisibility() const;
105  void setVisibility(VisibilityType);
106 
107  // Zoom range
108  float getMinZoom() const;
109  float getMaxZoom() const;
110  void setMinZoom(float);
111  void setMaxZoom(float);
112 
113  // Dynamic properties
114  std::optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
115 
116  virtual StyleProperty getProperty(const std::string&) const = 0;
117  virtual Value serialize() const;
118 
119  // Private implementation
121 
122  // TODO : We should not have public mutable data members.
123  class Impl;
124  Immutable<Impl> baseImpl;
125 
126  // Create a layer, copying all properties except id and paint properties from this layer.
127  virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0;
128 
129 
130  void setObserver(LayerObserver*);
131 
132  // For use in SDK bindings, which store a reference to a platform-native peer
133  // object here, so that separately-obtained references to this object share
134  // identical platform-native peers.
135  mapbox::base::TypeWrapper peer;
136  Layer(Immutable<Impl>);
137 
138  const LayerTypeInfo* getTypeInfo() const noexcept;
139 
140  mapbox::base::WeakPtr<Layer> makeWeakPtr() {
141  return weakFactory.makeWeakPtr();
142  }
143 
144 protected:
145  virtual Mutable<Impl> mutableBaseImpl() const = 0;
146  void serializeProperty(Value&, const StyleProperty&, const char* propertyName, bool isPaint) const;
147  virtual std::optional<conversion::Error> setPropertyInternal(const std::string& name,
148  const conversion::Convertible& value) = 0;
149  LayerObserver* observer;
150  mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
151 
152 private:
153  std::optional<conversion::Error> setVisibility(const conversion::Convertible& value);
154  std::optional<conversion::Error> setMinZoom(const conversion::Convertible& value);
155  std::optional<conversion::Error> setMaxZoom(const conversion::Convertible& value);
156 };
157 
158 } // namespace style
159 } // namespace mbgl
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
VisibilityType
Definition: types.hpp:21
Definition: actor.hpp:15
mapbox::base::Value Value
Definition: feature.hpp:11
mapbox::geometry::geometry< T > Geometry
Definition: geometry.hpp:42