diff options
Diffstat (limited to 'src/mbgl/map/vector_tile_data.cpp')
-rw-r--r-- | src/mbgl/map/vector_tile_data.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp new file mode 100644 index 0000000000..06782057f6 --- /dev/null +++ b/src/mbgl/map/vector_tile_data.cpp @@ -0,0 +1,78 @@ +#include <mbgl/map/vector_tile_data.hpp> +#include <mbgl/map/tile_parser.hpp> +#include <mbgl/util/std.hpp> +#include <mbgl/map/map.hpp> +#include <mbgl/style/style_layer.hpp> +#include <mbgl/style/style_bucket.hpp> +#include <mbgl/geometry/glyph_atlas.hpp> + +using namespace mbgl; + +VectorTileData::VectorTileData(Tile::ID const& id_, + float mapMaxZoom, util::ptr<Style> style_, + GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, + SpriteAtlas& spriteAtlas_, util::ptr<Sprite> sprite_, + TexturePool& texturePool_, + const SourceInfo& source_) + : TileData(id_, source_), + glyphAtlas(glyphAtlas_), + glyphStore(glyphStore_), + spriteAtlas(spriteAtlas_), + sprite(sprite_), + texturePool(texturePool_), + style(style_), + depth(id.z >= source.max_zoom ? mapMaxZoom - id.z : 1) { +} + +VectorTileData::~VectorTileData() { + glyphAtlas.removeGlyphs(id.to_uint64()); +} + + +void VectorTileData::parse() { + if (state != State::loaded) { + return; + } + + try { + // Parsing creates state that is encapsulated in TileParser. While parsing, + // the TileParser object writes results into this objects. All other state + // is going to be discarded afterwards. + TileParser parser(data, *this, style, + glyphAtlas, glyphStore, + spriteAtlas, sprite, + texturePool); + parser.parse(); + } catch (const std::exception& ex) { +#if defined(DEBUG) + fprintf(stderr, "[%p] exception [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what()); +#endif + cancel(); + return; + } + + if (state != State::obsolete) { + state = State::parsed; + } +} + +void VectorTileData::render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) { + if (state == State::parsed && layer_desc->bucket) { + auto databucket_it = buckets.find(layer_desc->bucket->name); + if (databucket_it != buckets.end()) { + assert(databucket_it->second); + databucket_it->second->render(painter, layer_desc, id, matrix); + } + } +} + +bool VectorTileData::hasData(StyleLayer const& layer_desc) const { + if (state == State::parsed && layer_desc.bucket) { + auto databucket_it = buckets.find(layer_desc.bucket->name); + if (databucket_it != buckets.end()) { + assert(databucket_it->second); + return databucket_it->second->hasData(); + } + } + return false; +} |