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/mbgl/util/url.cpp | |
parent | aac6b00dd0fa0dd6555b74cb252ea446463f36b8 (diff) | |
download | qtlocation-mapboxgl-1ff317c1cdebc2bb34bb759dea957f8dd9660eb1.tar.gz |
[core] remove SourceInfo dependency from *TileData
Diffstat (limited to 'src/mbgl/util/url.cpp')
-rw-r--r-- | src/mbgl/util/url.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
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://"; } |