Only add {ratio} to raster tile URLs
Thanks to @mb12 for the suggestion.
This commit is contained in:
committed by
John Firebaugh
parent
a3d76dad10
commit
8804c47d27
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user