diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-01-05 15:59:10 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-13 13:04:59 -0800 |
commit | 1ff317c1cdebc2bb34bb759dea957f8dd9660eb1 (patch) | |
tree | a507fc907e28c2417e537a1ef9dc485e7d3b230a /src | |
parent | aac6b00dd0fa0dd6555b74cb252ea446463f36b8 (diff) | |
download | qtlocation-mapboxgl-1ff317c1cdebc2bb34bb759dea957f8dd9660eb1.tar.gz |
[core] remove SourceInfo dependency from *TileData
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/raster_tile_data.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/map/raster_tile_data.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/source_info.cpp | 33 | ||||
-rw-r--r-- | src/mbgl/map/source_info.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/util/url.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/util/url.hpp | 5 |
9 files changed, 43 insertions, 51 deletions
diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp index 5c85cbd034..a462b86bec 100644 --- a/src/mbgl/map/raster_tile_data.cpp +++ b/src/mbgl/map/raster_tile_data.cpp @@ -10,11 +10,9 @@ using namespace mbgl; RasterTileData::RasterTileData(const TileID& id_, TexturePool &texturePool_, - const SourceInfo &source_, Worker& worker_) : TileData(id_), texturePool(texturePool_), - source(source_), worker(worker_) { } @@ -22,9 +20,8 @@ RasterTileData::~RasterTileData() { cancel(); } -void RasterTileData::request(float pixelRatio, +void RasterTileData::request(const std::string& url, const RasterTileData::Callback& callback) { - std::string url = source.tileURL(id, pixelRatio); state = State::loading; FileSource* fs = util::ThreadContext::getFileSource(); diff --git a/src/mbgl/map/raster_tile_data.hpp b/src/mbgl/map/raster_tile_data.hpp index 54330b73a8..34a79cad4c 100644 --- a/src/mbgl/map/raster_tile_data.hpp +++ b/src/mbgl/map/raster_tile_data.hpp @@ -6,7 +6,6 @@ namespace mbgl { -class SourceInfo; class FileRequest; class StyleLayer; class TexturePool; @@ -14,12 +13,12 @@ class WorkRequest; class RasterTileData : public TileData { public: - RasterTileData(const TileID&, TexturePool&, const SourceInfo&, Worker&); + RasterTileData(const TileID&, TexturePool&, Worker&); ~RasterTileData(); using Callback = std::function<void()>; - void request(float pixelRatio, + void request(const std::string& url, const Callback& callback); void cancel() override; @@ -28,7 +27,6 @@ public: private: TexturePool& texturePool; - const SourceInfo& source; Worker& worker; std::unique_ptr<FileRequest> req; diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 107c405efe..a14e0badd0 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -22,6 +22,7 @@ #include <mbgl/util/token.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/tile_cover.hpp> +#include <mbgl/util/url.hpp> #include <mbgl/map/vector_tile_data.hpp> #include <mbgl/map/raster_tile_data.hpp> @@ -307,16 +308,15 @@ TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& p if (info.type == SourceType::Raster) { auto tileData = std::make_shared<RasterTileData>(normalized_id, parameters.texturePool, - info, parameters.worker); - tileData->request(parameters.pixelRatio, callback); + tileData->request(util::templateTileURL(info.tiles.at(0), normalized_id, parameters.pixelRatio), callback); newTile->data = tileData; } else { std::unique_ptr<GeometryTileMonitor> monitor; if (info.type == SourceType::Vector) { - monitor = std::make_unique<VectorTileMonitor>(info, normalized_id, parameters.pixelRatio); + monitor = std::make_unique<VectorTileMonitor>(normalized_id, info.tiles.at(0)); } else if (info.type == SourceType::Annotations) { monitor = std::make_unique<AnnotationTileMonitor>(normalized_id, parameters.data); } else if (info.type == SourceType::GeoJSON) { diff --git a/src/mbgl/map/source_info.cpp b/src/mbgl/map/source_info.cpp deleted file mode 100644 index 2980e3ec42..0000000000 --- a/src/mbgl/map/source_info.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include <mbgl/map/source_info.hpp> -#include <mbgl/map/tile_id.hpp> -#include <mbgl/util/mapbox.hpp> -#include <mbgl/util/string.hpp> -#include <mbgl/util/token.hpp> - -namespace mbgl { - -std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const { - std::string result = tiles.at(0); - result = util::mapbox::normalizeTileURL(result, url, type); - result = util::replaceTokens(result, [&](const std::string& token) -> std::string { - if (token == "z") { - return util::toString(std::min(id.z, static_cast<int8_t>(max_zoom))); - } else if (token == "x") { - return util::toString(id.x); - } else if (token == "y") { - return util::toString(id.y); - } else if (token == "prefix") { - std::string prefix{ 2 }; - prefix[0] = "0123456789abcdef"[id.x % 16]; - prefix[1] = "0123456789abcdef"[id.y % 16]; - return prefix; - } else if (token == "ratio") { - return pixelRatio > 1.0 ? "@2x" : ""; - } else { - return ""; - } - }); - return result; -} - -} // namespace mbgl diff --git a/src/mbgl/map/source_info.hpp b/src/mbgl/map/source_info.hpp index 6e52dc8c04..0a72380d63 100644 --- a/src/mbgl/map/source_info.hpp +++ b/src/mbgl/map/source_info.hpp @@ -25,8 +25,6 @@ public: std::array<float, 3> center = { { 0, 0, 0 } }; std::array<float, 4> bounds = { { -180, -90, 180, 90 } }; std::string source_id = ""; - - std::string tileURL(const TileID&, float pixelRatio) const; }; } // namespace mbgl diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index 39e31da0d4..c53559d9cf 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -4,6 +4,7 @@ #include <mbgl/storage/response.hpp> #include <mbgl/storage/file_source.hpp> #include <mbgl/util/thread_context.hpp> +#include <mbgl/util/url.hpp> #include <utility> @@ -177,11 +178,12 @@ util::ptr<const GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i) return std::make_shared<VectorTileFeature>(features.at(i), *this); } -VectorTileMonitor::VectorTileMonitor(const SourceInfo& source, const TileID& id, float pixelRatio) - : url(source.tileURL(id, pixelRatio)) { +VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, const std::string& urlTemplate_) + : tileID(tileID_), urlTemplate(urlTemplate_) { } std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) { + const std::string url = util::templateTileURL(urlTemplate, tileID); return util::ThreadContext::getFileSource()->request({ Resource::Kind::Tile, url }, [callback, this](Response res) { if (res.data && data == res.data) { // We got the same data again. Abort early. diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index 61b97bc9a5..fb2007aa44 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -2,6 +2,7 @@ #define MBGL_MAP_VECTOR_TILE #include <mbgl/map/geometry_tile.hpp> +#include <mbgl/map/tile_id.hpp> #include <mbgl/util/pbf.hpp> #include <map> @@ -56,17 +57,17 @@ private: mutable std::map<std::string, util::ptr<GeometryTileLayer>> layers; }; -class SourceInfo; class TileID; class VectorTileMonitor : public GeometryTileMonitor { public: - VectorTileMonitor(const SourceInfo&, const TileID&, float pixelRatio); + VectorTileMonitor(const TileID&, const std::string& urlTemplate); std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override; private: - std::string url; + TileID tileID; + std::string urlTemplate; std::shared_ptr<const std::string> data; }; diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp index 07a226414c..1bd9f410fe 100644 --- a/src/mbgl/util/url.cpp +++ b/src/mbgl/util/url.cpp @@ -1,4 +1,7 @@ #include <mbgl/util/url.hpp> +#include <mbgl/util/token.hpp> +#include <mbgl/util/string.hpp> +#include <mbgl/map/tile_id.hpp> #include <cctype> #include <iomanip> @@ -47,6 +50,27 @@ std::string percentDecode(const std::string& input) { return decoded; } +std::string templateTileURL(const std::string& url, const TileID& id, float pixelRatio) { + return util::replaceTokens(url, [&](const std::string& token) -> std::string { + if (token == "z") { + return util::toString(id.sourceZ); + } else if (token == "x") { + return util::toString(id.x); + } else if (token == "y") { + return util::toString(id.y); + } else if (token == "prefix") { + std::string prefix{ 2 }; + prefix[0] = "0123456789abcdef"[id.x % 16]; + prefix[1] = "0123456789abcdef"[id.y % 16]; + return prefix; + } else if (token == "ratio") { + return pixelRatio > 1.0 ? "@2x" : ""; + } else { + return ""; + } + }); +} + namespace { const std::string assetProtocol = "asset://"; } diff --git a/src/mbgl/util/url.hpp b/src/mbgl/util/url.hpp index 583e04c302..da4cfb2672 100644 --- a/src/mbgl/util/url.hpp +++ b/src/mbgl/util/url.hpp @@ -4,11 +4,16 @@ #include <string> namespace mbgl { + +class TileID; + namespace util { std::string percentEncode(const std::string&); std::string percentDecode(const std::string&); +std::string templateTileURL(const std::string& url, const TileID& id, float pixelRatio = 1); + bool isAssetURL(const std::string&); } // namespace util |