Load 2× raster tiles on HiDPI screens
Based on mapbox.normalizeTileURL() in mapbox/mapbox-gl-js, but insert a “{ratio}” placeholder instead of “@2x” in order to keep the pixelRatio logic in TileData::request().
Fixes #919.
This commit is contained in:
committed by
John Firebaugh
parent
10d84f6be8
commit
41c01373d5
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <mbgl/util/token.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/uv_detail.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
@@ -37,7 +38,7 @@ 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(url, [&](const std::string &token) -> std::string {
|
||||
url = util::replaceTokens(util::mapbox::normalizeTileURL(url, source.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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -39,6 +40,14 @@ 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)
|
||||
return url;
|
||||
|
||||
static std::regex extension_re("\\.((?:png|jpg)\\d*)(?=$|\\?)");
|
||||
return std::regex_replace(url, extension_re, std::string("{ratio}.$1"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user