From 9ed0ca59832ed59ea8f391a8e1db1c6b9406b453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 17 Jul 2014 15:52:39 -0700 Subject: [PATCH] pass SourceInfo object to TileData so that we can not skip buckets that appear later than the source maxzoom --- include/mbgl/map/raster_tile_data.hpp | 2 +- include/mbgl/map/tile_data.hpp | 8 +++++++- include/mbgl/map/vector_tile_data.hpp | 2 +- src/map/raster_tile_data.cpp | 4 ++-- src/map/source.cpp | 13 ++----------- src/map/tile_data.cpp | 12 ++++++++++-- src/map/tile_parser.cpp | 5 ++--- src/map/vector_tile_data.cpp | 6 +++--- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp index 976faa91b..23f097972 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -12,7 +12,7 @@ class RasterTileData : public TileData { friend class TileParser; public: - RasterTileData(Tile::ID id, Map &map, const std::string url); + RasterTileData(Tile::ID id, Map &map, const SourceInfo &source); ~RasterTileData(); virtual void parse(); diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index a4b73c339..416a29d2a 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -17,6 +17,7 @@ namespace mbgl { class Map; class Painter; class StyleLayer; +class SourceInfo; class TileData : public std::enable_shared_from_this, private util::noncopyable { @@ -37,7 +38,7 @@ public: }; public: - TileData(Tile::ID id, Map &map, const std::string url); + TileData(Tile::ID id, Map &map, const SourceInfo &source); ~TileData(); void request(); @@ -60,8 +61,13 @@ public: protected: Map ↦ +public: + const SourceInfo &source; + // Request-related information. const std::string url; + +protected: std::weak_ptr req; std::string data; diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index dd55e8dae..dc67b9251 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -23,7 +23,7 @@ class VectorTileData : public TileData { friend class TileParser; public: - VectorTileData(Tile::ID id, Map &map, const std::string url); + VectorTileData(Tile::ID id, Map &map, const SourceInfo &source); ~VectorTileData(); virtual void beforeParse(); diff --git a/src/map/raster_tile_data.cpp b/src/map/raster_tile_data.cpp index ef6bea7e6..26c122da6 100644 --- a/src/map/raster_tile_data.cpp +++ b/src/map/raster_tile_data.cpp @@ -5,8 +5,8 @@ using namespace mbgl; -RasterTileData::RasterTileData(Tile::ID id, Map &map, const std::string url) - : TileData(id, map, url), +RasterTileData::RasterTileData(Tile::ID id, Map &map, const SourceInfo &source) + : TileData(id, map, source), bucket(map.getTexturepool()) { } diff --git a/src/map/source.cpp b/src/map/source.cpp index b885ee764..f9e34d926 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -146,18 +145,10 @@ TileData::State Source::addTile(Map &map, const Tile::ID& id) { if (!new_tile.data) { // If we don't find working tile data, we're just going to load it. - const std::string formed_url = util::replaceTokens(info.url, [&](const std::string &token) -> std::string { - if (token == "z") return std::to_string(normalized_id.z); - if (token == "x") return std::to_string(normalized_id.x); - if (token == "y") return std::to_string(normalized_id.y); - if (token == "ratio") return (map.getState().getPixelRatio() > 1.0 ? "@2x" : ""); - return ""; - }); - if (info.type == SourceType::Vector) { - new_tile.data = std::make_shared(normalized_id, map, formed_url); + new_tile.data = std::make_shared(normalized_id, map, info); } else if (info.type == SourceType::Raster) { - new_tile.data = std::make_shared(normalized_id, map, formed_url); + new_tile.data = std::make_shared(normalized_id, map, info); } else { throw std::runtime_error("source type not implemented"); } diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 82f8fdedf..556a2e607 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -1,15 +1,23 @@ #include #include +#include #include using namespace mbgl; -TileData::TileData(Tile::ID id, Map &map, const std::string url) +TileData::TileData(Tile::ID id, Map &map, const SourceInfo &source) : id(id), state(State::initial), map(map), - url(url), + source(source), + url(util::replaceTokens(source.url, [&](const std::string &token) -> std::string { + if (token == "z") return std::to_string(id.z); + if (token == "x") return std::to_string(id.x); + if (token == "y") return std::to_string(id.y); + if (token == "ratio") return (map.getState().getPixelRatio() > 1.0 ? "@2x" : ""); + return ""; + })), debugBucket(debugFontBuffer) { // Initialize tile debug coordinates const std::string str = util::sprintf<32>("%d/%d/%d", id.z, id.x, id.y); diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index a580e0a78..03a884e43 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -109,9 +109,8 @@ std::unique_ptr TileParser::createBucket(std::shared_ptr bu } // Skip this bucket if we are to not render this - if (tile.id.z < bucket_desc->min_zoom || tile.id.z > bucket_desc->max_zoom) { - return nullptr; - } + if (tile.id.z < bucket_desc->min_zoom && bucket_desc->min_zoom < tile.source.max_zoom) return nullptr; + if (tile.id.z >= bucket_desc->max_zoom) return nullptr; auto layer_it = vector_data.layers.find(bucket_desc->source_layer); if (layer_it != vector_data.layers.end()) { diff --git a/src/map/vector_tile_data.cpp b/src/map/vector_tile_data.cpp index 7d0e0fb5a..f1f065d58 100644 --- a/src/map/vector_tile_data.cpp +++ b/src/map/vector_tile_data.cpp @@ -6,8 +6,8 @@ using namespace mbgl; -VectorTileData::VectorTileData(Tile::ID id, Map &map, const std::string url) - : TileData(id, map, url) { +VectorTileData::VectorTileData(Tile::ID id, Map &map, const SourceInfo &source) + : TileData(id, map, source) { } VectorTileData::~VectorTileData() { @@ -63,7 +63,7 @@ bool VectorTileData::hasData(std::shared_ptr layer_desc) const { auto databucket_it = buckets.find(layer_desc->bucket->name); if (databucket_it != buckets.end()) { assert(databucket_it->second); - return databucket_it->second->hasData(); + return databucket_it->second->hasData(); } } return false;