move vector tile parsing to separate class + iterators
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "../geometry/line_buffer.hpp"
|
||||
|
||||
#include "layer.hpp"
|
||||
#include "vector_tile.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <forward_list>
|
||||
@@ -22,6 +23,8 @@ class Bucket;
|
||||
class LayerDescription;
|
||||
class BucketDescription;
|
||||
|
||||
|
||||
|
||||
class Tile {
|
||||
public:
|
||||
struct exception : std::exception {};
|
||||
@@ -52,13 +55,9 @@ public:
|
||||
// Other functions
|
||||
void setData(uint8_t *data, uint32_t bytes);
|
||||
bool parse();
|
||||
void parseLayers(const pbf& tile, const std::vector<LayerDescription>& layers);
|
||||
std::shared_ptr<Bucket> createBucket(const pbf& tile, const BucketDescription& bucket_desc);
|
||||
// void parseLayer(const pbf layer);
|
||||
|
||||
// void (const std::vector<LayerDescription>& child_layers);
|
||||
|
||||
std::shared_ptr<Bucket> createFillBucket(const pbf data, const BucketDescription& bucket_desc);
|
||||
void parseStyleLayers(const std::vector<LayerDescription>& layers);
|
||||
std::shared_ptr<Bucket> createBucket(const BucketDescription& bucket_desc);
|
||||
std::shared_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc);
|
||||
|
||||
void cancel();
|
||||
|
||||
@@ -85,6 +84,7 @@ private:
|
||||
// Source data
|
||||
uint8_t *data;
|
||||
uint32_t bytes;
|
||||
VectorTile tile;
|
||||
|
||||
std::mutex mtx;
|
||||
|
||||
|
||||
68
include/llmr/map/vector_tile.hpp
Normal file
68
include/llmr/map/vector_tile.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef LLMR_MAP_VECTOR_TILE
|
||||
#define LLMR_MAP_VECTOR_TILE
|
||||
|
||||
#include <llmr/util/pbf.hpp>
|
||||
#include <llmr/style/value.hpp>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
class BucketDescription;
|
||||
class VectorTileLayer;
|
||||
|
||||
struct pbf;
|
||||
|
||||
class FilteredVectorTileLayer {
|
||||
public:
|
||||
class iterator {
|
||||
public:
|
||||
iterator(const FilteredVectorTileLayer& filter, const pbf& data);
|
||||
void operator++();
|
||||
bool operator!=(const iterator& other) const;
|
||||
const pbf& operator*() const;
|
||||
|
||||
private:
|
||||
const FilteredVectorTileLayer& filter;
|
||||
bool valid = false;
|
||||
pbf feature;
|
||||
pbf data;
|
||||
};
|
||||
|
||||
public:
|
||||
FilteredVectorTileLayer(const VectorTileLayer& layer, const BucketDescription& bucket_desc);
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
|
||||
private:
|
||||
const VectorTileLayer& layer;
|
||||
const BucketDescription& bucket_desc;
|
||||
int32_t key = -1;
|
||||
std::set<uint32_t> values;
|
||||
};
|
||||
|
||||
class VectorTileLayer {
|
||||
public:
|
||||
VectorTileLayer(pbf data);
|
||||
|
||||
const pbf data;
|
||||
std::string name;
|
||||
uint32_t extent = 4096;
|
||||
std::vector<std::string> keys;
|
||||
std::vector<Value> values;
|
||||
};
|
||||
|
||||
class VectorTile {
|
||||
public:
|
||||
VectorTile();
|
||||
VectorTile(pbf data);
|
||||
VectorTile& operator=(VectorTile&& other);
|
||||
|
||||
std::map<std::string, const VectorTileLayer> layers;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -29,6 +29,7 @@ struct pbf {
|
||||
inline operator bool() const;
|
||||
|
||||
inline bool next();
|
||||
inline bool next(uint32_t tag);
|
||||
template <typename T = uint32_t> inline T varint();
|
||||
template <typename T = uint32_t> inline T svarint();
|
||||
|
||||
@@ -75,6 +76,16 @@ bool pbf::next() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pbf::next(uint32_t requested_tag) {
|
||||
while (next()) {
|
||||
if (tag == requested_tag) {
|
||||
return true;
|
||||
} else {
|
||||
skip();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T pbf::varint() {
|
||||
|
||||
Reference in New Issue
Block a user