Allow using tileSize: 512 as a switch to trade retina support for 512px raster tiles
This commit is contained in:
committed by
John Firebaugh
parent
7ca602b739
commit
43c44eccdc
@@ -104,7 +104,7 @@ void Source::load() {
|
||||
// from the stylesheet. Then merge in the values parsed from the TileJSON we retrieved
|
||||
// via the URL.
|
||||
try {
|
||||
newInfo = StyleParser::parseTileJSON(*res.data, url, type);
|
||||
newInfo = StyleParser::parseTileJSON(*res.data, url, type, tileSize);
|
||||
} catch (...) {
|
||||
observer->onSourceError(*this, std::current_exception());
|
||||
return;
|
||||
|
||||
@@ -256,7 +256,7 @@ std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> StyleParser::parseGeoJSON(const JS
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type) {
|
||||
std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
|
||||
document.Parse<0>(json.c_str());
|
||||
|
||||
@@ -270,10 +270,9 @@ std::unique_ptr<SourceInfo> StyleParser::parseTileJSON(const std::string& json,
|
||||
|
||||
// TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with.
|
||||
if (util::mapbox::isMapboxURL(sourceURL)) {
|
||||
std::transform(result->tiles.begin(),
|
||||
result->tiles.end(),
|
||||
result->tiles.begin(),
|
||||
std::bind(util::mapbox::canonicalizeTileURL, std::placeholders::_1, type));
|
||||
for (auto& url : result->tiles) {
|
||||
url = util::mapbox::canonicalizeTileURL(url, type, tileSize);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
// Statically evaluate layer properties to determine what font stacks are used.
|
||||
std::vector<std::string> fontStacks() const;
|
||||
|
||||
static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType);
|
||||
static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize);
|
||||
static std::unique_ptr<SourceInfo> parseTileJSON(const JSValue&);
|
||||
|
||||
static std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> parseGeoJSON(const JSValue&);
|
||||
|
||||
@@ -119,7 +119,7 @@ std::string normalizeTileURL(const std::string& url, const std::string& accessTo
|
||||
return baseURL + "v4/" + url.substr(sizeof("mapbox://tiles/") - 1) + "?access_token=" + accessToken;
|
||||
}
|
||||
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType type) {
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType type, uint16_t tileSize) {
|
||||
auto tilesetStartIdx = url.find("/v4/");
|
||||
if (tilesetStartIdx == std::string::npos) {
|
||||
return url;
|
||||
@@ -159,8 +159,14 @@ std::string canonicalizeTileURL(const std::string& url, SourceType type) {
|
||||
}
|
||||
#endif // !defined(__ANDROID__) && !defined(__APPLE__)
|
||||
|
||||
return "mapbox://tiles/" + tileset + "/{z}/{x}/{y}" +
|
||||
(type == SourceType::Raster ? "{ratio}" : "") + "." + extension;
|
||||
std::string result = "mapbox://tiles/" + tileset + "/{z}/{x}/{y}";
|
||||
|
||||
if (type == SourceType::Raster) {
|
||||
result += tileSize == 512 ? "@2x" : "{ratio}";
|
||||
}
|
||||
|
||||
result += "." + extension;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end namespace mapbox
|
||||
|
||||
@@ -17,7 +17,7 @@ std::string normalizeGlyphsURL(const std::string& url, const std::string& access
|
||||
std::string normalizeTileURL(const std::string& url, const std::string& accessToken);
|
||||
|
||||
// Return a "mapbox://tiles/..." URL (suitable for normalizeTileURL) for the given Mapbox tile URL.
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType);
|
||||
std::string canonicalizeTileURL(const std::string& url, SourceType, uint16_t tileSize);
|
||||
|
||||
} // namespace mapbox
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user