MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
source.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/style/types.hpp>
4 #include <mbgl/util/chrono.hpp>
6 
7 #include <mapbox/std/weak.hpp>
8 #include <mapbox/util/type_wrapper.hpp>
9 
10 #include <memory>
11 #include <string>
12 #include <optional>
13 
14 namespace mbgl {
15 
16 class FileSource;
17 
18 namespace style {
19 
20 class VectorSource;
21 class RasterSource;
22 class RasterDEMSource;
23 class GeoJSONSource;
24 class SourceObserver;
25 struct LayerTypeInfo;
26 
43 class Source {
44 public:
45  Source(const Source&) = delete;
46  Source& operator=(const Source&) = delete;
47 
48  virtual ~Source();
49 
51  template <class T>
52  bool is() const;
53 
55  template <class T>
56  T* as() {
57  return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
58  }
59 
60  template <class T>
61  const T* as() const {
62  return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
63  }
64 
65  SourceType getType() const;
66  std::string getID() const;
67  std::optional<std::string> getAttribution() const;
68 
69  // The data from the volatile sources are not stored in a persistent storage.
70  bool isVolatile() const noexcept;
71  void setVolatile(bool) noexcept;
72 
73  // Private implementation
75 
76  class Impl;
77  Immutable<Impl> baseImpl;
78 
79  void setObserver(SourceObserver*);
80  SourceObserver* observer = nullptr;
81 
82  virtual void loadDescription(FileSource&) = 0;
83  void setPrefetchZoomDelta(std::optional<uint8_t> delta) noexcept;
84  std::optional<uint8_t> getPrefetchZoomDelta() const noexcept;
85 
86  // If the given source supports loading tiles from a server,
87  // sets the minimum tile update interval.
88  // Update network requests that are more frequent than the
89  // minimum tile update interval are suppressed.
90  //
91  // Default value is `Duration::zero()`.
92  void setMinimumTileUpdateInterval(Duration) noexcept;
93  Duration getMinimumTileUpdateInterval() const noexcept;
94 
95  // Sets a limit for how much a parent tile can be overscaled.
96  //
97  // When a set of tiles for a current zoom level is being rendered and some of the
98  // ideal tiles that cover the screen are not yet loaded, parent tile could be
99  // used instead. This might introduce unwanted rendering side-effects, especially
100  // for raster tiles that are overscaled multiple times.
101  //
102  // For example, an overscale factor of 3 would mean that on zoom level 3, the
103  // minimum zoom level of a parent tile that could be used in place of an ideal
104  // tile during rendering would be zoom 0. By default, no limit is set, so any
105  // parent tile may be used.
106  void setMaxOverscaleFactorForParentTiles(std::optional<uint8_t> overscaleFactor) noexcept;
107  std::optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept;
108  void dumpDebugLogs() const;
109 
110  virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0;
111 
112  bool loaded = false;
113 
114  // For use in SDK bindings, which store a reference to a platform-native peer
115  // object here, so that separately-obtained references to this object share
116  // identical platform-native peers.
117  mapbox::base::TypeWrapper peer;
118 
119  virtual mapbox::base::WeakPtr<Source> makeWeakPtr() = 0;
120 
121 protected:
122  explicit Source(Immutable<Impl>);
123  virtual Mutable<Impl> createMutable() const noexcept = 0;
124 };
125 
126 } // namespace style
127 } // namespace mbgl
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
Definition: actor.hpp:15
Clock::duration Duration
Definition: chrono.hpp:18
Definition: tile_id.hpp:256