[core] switch to vector-tile library for decoding Mapbox vector tiles

This commit is contained in:
Konstantin Käfer
2017-06-19 19:17:09 -07:00
parent 0f300d8dcd
commit 2cc330463d
6 changed files with 68 additions and 255 deletions

View File

@@ -1,5 +1,6 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mapbox/vector_tile.hpp>
#include <protozero/pbf_reader.hpp>
#include <unordered_map>
@@ -8,74 +9,42 @@
namespace mbgl {
class VectorTileLayer;
using packed_iter_type = protozero::iterator_range<protozero::pbf_reader::const_uint32_iterator>;
struct VectorTileLayerData {
VectorTileLayerData(std::shared_ptr<const std::string>);
// Hold a reference to the underlying pbf data that backs the lazily-built
// components of the owning VectorTileLayer and VectorTileFeature objects
std::shared_ptr<const std::string> data;
uint32_t version = 1;
uint32_t extent = 4096;
std::unordered_map<std::string, uint32_t> keysMap;
std::vector<std::reference_wrapper<const std::string>> keys;
std::vector<Value> values;
};
class VectorTileFeature : public GeometryTileFeature {
public:
VectorTileFeature(protozero::pbf_reader, std::shared_ptr<VectorTileLayerData> layerData);
VectorTileFeature(const mapbox::vector_tile::layer&, const protozero::data_view&);
FeatureType getType() const override { return type; }
optional<Value> getValue(const std::string&) const override;
std::unordered_map<std::string,Value> getProperties() const override;
FeatureType getType() const override;
optional<Value> getValue(const std::string& key) const override;
std::unordered_map<std::string, Value> getProperties() const override;
optional<FeatureIdentifier> getID() const override;
GeometryCollection getGeometries() const override;
private:
std::shared_ptr<VectorTileLayerData> layerData;
optional<FeatureIdentifier> id;
FeatureType type = FeatureType::Unknown;
packed_iter_type tags_iter;
packed_iter_type geometry_iter;
mapbox::vector_tile::feature feature;
};
class VectorTileLayer : public GeometryTileLayer {
public:
VectorTileLayer(protozero::pbf_reader, std::shared_ptr<const std::string>);
VectorTileLayer(std::shared_ptr<const std::string> data, const protozero::data_view&);
std::size_t featureCount() const override { return features.size(); }
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t) const override;
std::size_t featureCount() const override;
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override;
std::string getName() const override;
private:
friend class VectorTileData;
friend class VectorTileFeature;
std::string name;
std::vector<protozero::pbf_reader> features;
std::shared_ptr<VectorTileLayerData> data;
std::shared_ptr<const std::string> data;
mapbox::vector_tile::layer layer;
};
class VectorTileData : public GeometryTileData {
public:
VectorTileData(std::shared_ptr<const std::string> data);
std::unique_ptr<GeometryTileData> clone() const override {
return std::make_unique<VectorTileData>(*this);
}
const GeometryTileLayer* getLayer(const std::string&) const override;
std::unique_ptr<GeometryTileData> clone() const override;
const GeometryTileLayer* getLayer(const std::string& name) const override;
std::vector<std::string> layerNames() const;
private:
void parse() const;
private:
std::shared_ptr<const std::string> data;
mutable bool parsed = false;