diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-03-06 12:14:21 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-03-06 13:51:20 -0800 |
commit | 8804c47d2736e284bb3d6272a38ecc90797d01f0 (patch) | |
tree | fb7318497abd43cf4f95a533a519ad527dadce90 /src | |
parent | a3d76dad1064d3020f8b972ed5e7427966f30983 (diff) | |
download | qtlocation-mapboxgl-8804c47d2736e284bb3d6272a38ecc90797d01f0.tar.gz |
Only add {ratio} to raster tile URLs
Thanks to @mb12 for the suggestion.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/tile_data.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/util/mapbox.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/util/mapbox.hpp | 3 |
3 files changed, 16 insertions, 10 deletions
diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp index b8f317a07e..7b379e9fe3 100644 --- a/src/mbgl/map/tile_data.cpp +++ b/src/mbgl/map/tile_data.cpp @@ -38,7 +38,8 @@ void TileData::request(uv::worker &worker, float pixelRatio, std::function<void( return; std::string url = source.tiles[(id.x + id.y) % source.tiles.size()]; - url = util::replaceTokens(util::mapbox::normalizeTileURL(url, source.url), [&](const std::string &token) -> std::string { + url = util::mapbox::normalizeTileURL(url, source.url, source.type); + url = util::replaceTokens(url, [&](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); diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index f89ed6c006..d5b4672465 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -39,23 +39,27 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access return normalizeURL(url, accessToken); } -std::string normalizeTileURL(const std::string& url, const std::string& sourceURL) { - if (sourceURL.empty() || sourceURL.compare(0, mapbox.length(), mapbox) != 0) +std::string normalizeTileURL(const std::string& url, const std::string& sourceURL, SourceType sourceType) { + if (sourceURL.empty() || sourceURL.compare(0, mapbox.length(), mapbox) != 0 || + sourceType != SourceType::Raster) { return url; + } std::string::size_type queryIdx = url.rfind("?"); // Trim off the right end but never touch anything before the extension dot. std::string urlSansParams((queryIdx == std::string::npos) ? url : url.substr(0, queryIdx)); - while (!urlSansParams.empty() && isdigit(urlSansParams.back())) + while (!urlSansParams.empty() && isdigit(urlSansParams.back())) { urlSansParams.pop_back(); + } - std::string::size_type extensionIdx = urlSansParams.length() - 4; - if (extensionIdx <= 0) - return url; - std::string extension = urlSansParams.substr(extensionIdx); - if (extension.compare(".png") != 0 && extension.compare(".jpg") != 0) + std::string::size_type basenameIdx = url.rfind("/"); + std::string::size_type extensionIdx = url.rfind("."); + if (basenameIdx == std::string::npos || extensionIdx == std::string::npos || + basenameIdx > extensionIdx) { + // No file extension: probably not a file name we can tack a ratio onto. return url; + } std::string normalizedURL(url); normalizedURL.insert(extensionIdx, "{ratio}"); diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp index 68b821eabb..8ad92c0b40 100644 --- a/src/mbgl/util/mapbox.hpp +++ b/src/mbgl/util/mapbox.hpp @@ -2,6 +2,7 @@ #define MBGL_UTIL_MAPBOX #include <string> +#include <mbgl/style/types.hpp> namespace mbgl { namespace util { @@ -9,7 +10,7 @@ namespace mapbox { std::string normalizeSourceURL(const std::string& url, const std::string& accessToken); std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken); -std::string normalizeTileURL(const std::string& url, const std::string& sourceURL); +std::string normalizeTileURL(const std::string& url, const std::string& sourceURL, SourceType sourceType); } } |