MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
offline.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/util/geo.hpp>
4 #include <mbgl/util/geometry.hpp>
5 #include <mbgl/util/range.hpp>
6 #include <mbgl/util/variant.hpp>
7 #include <mbgl/style/types.hpp>
9 
10 #include <string>
11 #include <vector>
12 #include <functional>
13 
14 namespace mbgl {
15 
16 class TileID;
17 
18 /*
19  * An offline region defined by a style URL, geographic bounding box, zoom range, and
20  * device pixel ratio.
21  *
22  * Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom.
23  *
24  * maxZoom may be ∞, in which case for each tile source, the region will include
25  * tiles from minZoom up to the maximum zoom level provided by that source.
26  *
27  * pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0.
28  */
30 public:
32 
33  /* Private */
36  double minZoom;
37  double maxZoom;
38  float pixelRatio;
40 };
41 
42 /*
43  * An offline region defined by a style URL, geometry, zoom range, and
44  * device pixel ratio.
45  *
46  * Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom.
47  *
48  * maxZoom may be ∞, in which case for each tile source, the region will include
49  * tiles from minZoom up to the maximum zoom level provided by that source.
50  *
51  * pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0.
52  */
54 public:
56 
57  /* Private */
60  double minZoom;
61  double maxZoom;
62  float pixelRatio;
64 };
65 
66 /*
67  * The offline region definition types supported
68  */
70 
71 /*
72  * The encoded format is private.
73  */
76 
77 /*
78  * Arbitrary binary region metadata. The contents are opaque to the mbgl implementation;
79  * it just stores and retrieves a BLOB. SDK bindings should leave the interpretation of
80  * this data up to the application; they _should not_ enforce a higher-level data format.
81  * In the future we want offline database to be portable across target platforms, and a
82  * platform-specific metadata format would prevent that.
83  */
84 using OfflineRegionMetadata = std::vector<uint8_t>;
85 
86 /*
87  * A region is either inactive (not downloading, but previously-downloaded
88  * resources are available for use), or active (resources are being downloaded
89  * or will be downloaded, if necessary, when network access is available).
90  *
91  * This state is independent of whether or not the complete set of resources
92  * is currently available for offline use. To check if that is the case, use
93  * `OfflineRegionStatus::complete()`.
94  */
96  Inactive,
97  Active
98 };
99 
100 /*
101  * A region's status includes its active/inactive state as well as counts
102  * of the number of resources that have completed downloading, their total
103  * size in bytes, and the total number of resources that are required.
104  *
105  * Note that the total required size in bytes is not currently available. A
106  * future API release may provide an estimate of this number.
107  */
109 public:
111 
117 
122  uint64_t completedResourceSize = 0;
123 
128  uint64_t completedTileCount = 0;
129 
133  uint64_t requiredTileCount = 0;
134 
139  uint64_t completedTileSize = 0;
140 
146  uint64_t requiredResourceCount = 0;
147 
158 
159  bool complete() const {
161  }
162 };
163 
164 /*
165  * A region can have a single observer, which gets notified whenever a change
166  * to the region's status occurs.
167  */
169 public:
170  virtual ~OfflineRegionObserver() = default;
171 
172  /*
173  * Implement this method to be notified of a change in the status of an
174  * offline region. Status changes include any change in state of the members
175  * of OfflineRegionStatus.
176  *
177  * Note that this method will be executed on the database thread; it is the
178  * responsibility of the SDK bindings to wrap this object in an interface that
179  * re-executes the user-provided implementation on the main thread.
180  */
182 
183  /*
184  * Implement this method to be notified of errors encountered while downloading
185  * regional resources. Such errors may be recoverable; for example the implementation
186  * will attempt to re-request failed resources based on an exponential backoff
187  * algorithm, or when it detects that network access has been restored.
188  *
189  * Note that this method will be executed on the database thread; it is the
190  * responsibility of the SDK bindings to wrap this object in an interface that
191  * re-executes the user-provided implementation on the main thread.
192  */
193  virtual void responseError(Response::Error) {} // NOLINT(performance-unnecessary-value-param)
194 
195  /*
196  * Implement this method to be notified when the limit on the number of Mapbox
197  * tiles stored for offline regions has been reached.
198  *
199  * Once the limit has been reached, the SDK will not download further offline
200  * tiles from Mapbox APIs until existing tiles have been removed.
201  *
202  * This limit does not apply to non-Mapbox tile sources.
203  *
204  * Note that this method will be executed on the database thread; it is the
205  * responsibility of the SDK bindings to wrap this object in an interface that
206  * re-executes the user-provided implementation on the main thread.
207  */
208  virtual void mapboxTileCountLimitExceeded(uint64_t /* limit */) {}
209 };
210 
212 public:
214  OfflineRegion() = delete;
215 
216  int64_t getID() const;
219 
220 private:
221  friend class OfflineDatabase;
222 
223  OfflineRegion(int64_t id,
226 
227  int64_t id;
228  OfflineRegionDefinition definition;
229  OfflineRegionMetadata metadata;
230 };
231 
232 using OfflineRegions = std::vector<OfflineRegion>;
233 
234 } // namespace mbgl
OfflineGeometryRegionDefinition(std::string styleURL, Geometry< double >, double minZoom, double maxZoom, float pixelRatio, bool includeIdeographs)
virtual void mapboxTileCountLimitExceeded(uint64_t)
Definition: offline.hpp:208
virtual void responseError(Response::Error)
Definition: offline.hpp:193
virtual void statusChanged(OfflineRegionStatus)
Definition: offline.hpp:181
virtual ~OfflineRegionObserver()=default
uint64_t requiredResourceCount
Definition: offline.hpp:146
uint64_t completedResourceSize
Definition: offline.hpp:122
OfflineRegionDownloadState downloadState
Definition: offline.hpp:110
uint64_t completedResourceCount
Definition: offline.hpp:116
const OfflineRegionMetadata & getMetadata() const
friend class OfflineDatabase
Definition: offline.hpp:221
const OfflineRegionDefinition & getDefinition() const
int64_t getID() const
OfflineTilePyramidRegionDefinition(std::string, LatLngBounds, double, double, float, bool)
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
std::unique_ptr< Expression > id()
Definition: actor.hpp:15
OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string &)
std::string encodeOfflineRegionDefinition(const OfflineRegionDefinition &)
OfflineRegionDownloadState
Definition: offline.hpp:95
std::vector< OfflineRegion > OfflineRegions
Definition: offline.hpp:232
mapbox::geometry::geometry< T > Geometry
Definition: geometry.hpp:42
variant< OfflineTilePyramidRegionDefinition, OfflineGeometryRegionDefinition > OfflineRegionDefinition
Definition: offline.hpp:69
mapbox::util::variant< T... > variant
Definition: variant.hpp:17
std::vector< uint8_t > OfflineRegionMetadata
Definition: offline.hpp:84