diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 4697d7018..b6a941b26 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,25 @@ void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) { parse(value, bounds, "bounds"); } +std::string SourceInfo::tileURL(const Tile::ID& id, float pixelRatio) const { + std::string result = tiles[(id.x + id.y) % tiles.size()]; + result = util::mapbox::normalizeTileURL(result, url, type); + result = util::replaceTokens(result, [&](const std::string &token) -> std::string { + if (token == "z") return util::toString(id.z); + if (token == "x") return util::toString(id.x); + if (token == "y") return util::toString(id.y); + if (token == "prefix") { + std::string prefix { 2 }; + prefix[0] = "0123456789abcdef"[id.x % 16]; + prefix[1] = "0123456789abcdef"[id.y % 16]; + return prefix; + } + if (token == "ratio") return pixelRatio > 1.0 ? "@2x" : ""; + return ""; + }); + return result; +} + Source::Source() { } diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 9c59acfc4..c853ac295 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -45,6 +45,7 @@ public: std::array bounds = {{-180, -90, 180, 90}}; void parseTileJSONProperties(const rapidjson::Value&); + std::string tileURL(const Tile::ID& id, float pixelRatio) const; }; class Source : public std::enable_shared_from_this, private util::noncopyable { diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp index aa8e159fa..2675c0644 100644 --- a/src/mbgl/map/tile_data.cpp +++ b/src/mbgl/map/tile_data.cpp @@ -1,11 +1,7 @@ #include -#include #include #include -#include -#include -#include #include #include #include @@ -37,22 +33,7 @@ void TileData::request(uv::worker &worker, float pixelRatio, std::function std::string { - if (token == "z") return util::toString(id.z); - if (token == "x") return util::toString(id.x); - if (token == "y") return util::toString(id.y); - if (token == "prefix") { - std::string prefix { 2 }; - prefix[0] = "0123456789abcdef"[id.x % 16]; - prefix[1] = "0123456789abcdef"[id.y % 16]; - return prefix; - } - if (token == "ratio") return pixelRatio > 1.0 ? "@2x" : ""; - return ""; - }); - + std::string url = source.tileURL(id, pixelRatio); state = State::loading; std::weak_ptr weak_tile = shared_from_this();