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
@@ -107,7 +107,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
|
||||
optional<Response> sourceResponse = offlineDatabase.get(Resource::source(source->url));
|
||||
if (sourceResponse) {
|
||||
result.requiredResourceCount += tileResources(source->type, source->tileSize,
|
||||
*StyleParser::parseTileJSON(*sourceResponse->data, source->url, source->type)).size();
|
||||
*StyleParser::parseTileJSON(*sourceResponse->data, source->url, source->type, source->tileSize)).size();
|
||||
} else {
|
||||
result.requiredResourceCountIsIndeterminate = true;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ void OfflineDownload::activateDownload() {
|
||||
requiredSourceURLs.insert(url);
|
||||
|
||||
ensureResource(Resource::source(url), [=] (Response sourceResponse) {
|
||||
ensureTiles(type, tileSize, *StyleParser::parseTileJSON(*sourceResponse.data, url, type));
|
||||
ensureTiles(type, tileSize, *StyleParser::parseTileJSON(*sourceResponse.data, url, type, tileSize));
|
||||
|
||||
requiredSourceURLs.erase(url);
|
||||
if (requiredSourceURLs.empty()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -90,7 +90,8 @@ TEST(StyleParser, ParseTileJSONRaster) {
|
||||
auto result = StyleParser::parseTileJSON(
|
||||
util::read_file("test/fixtures/style_parser/tilejson.raster.json"),
|
||||
"mapbox://mapbox.satellite",
|
||||
SourceType::Raster);
|
||||
SourceType::Raster,
|
||||
256);
|
||||
|
||||
EXPECT_EQ(0, result->minZoom);
|
||||
EXPECT_EQ(15, result->maxZoom);
|
||||
@@ -106,7 +107,8 @@ TEST(StyleParser, ParseTileJSONVector) {
|
||||
auto result = StyleParser::parseTileJSON(
|
||||
util::read_file("test/fixtures/style_parser/tilejson.vector.json"),
|
||||
"mapbox://mapbox.streets",
|
||||
SourceType::Vector);
|
||||
SourceType::Vector,
|
||||
256);
|
||||
|
||||
EXPECT_EQ(0, result->minZoom);
|
||||
EXPECT_EQ(15, result->maxZoom);
|
||||
|
||||
@@ -58,56 +58,74 @@ TEST(Mapbox, TileURL) {
|
||||
TEST(Mapbox, CanonicalURL) {
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://a.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://a.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://b.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://b.tiles.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf", SourceType::Vector, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}.vector.pbf",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b,c.d/{z}/{x}/{y}.vector.pbf",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b,c.d/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b,c.d/{z}/{x}/{y}.vector.pbf?access_token=key", SourceType::Vector, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.jpg",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg?access_token=key", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg?access_token=key", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.jpg70",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg70?access_token=key", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg70?access_token=key", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.jpg",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg?access_token=key", SourceType::Raster, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.jpg70",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.jpg70?access_token=key", SourceType::Raster, 512));
|
||||
|
||||
#if defined(__ANDROID__) || defined(__APPLE__)
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.png",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.png",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.png",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.png",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster, 512));
|
||||
#else
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.webp",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}{ratio}.webp",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.webp",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png", SourceType::Raster, 512));
|
||||
EXPECT_EQ(
|
||||
"mapbox://tiles/a.b/{z}/{x}/{y}@2x.webp",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.png?access_token=key", SourceType::Raster, 512));
|
||||
#endif // defined(__ANDROID__) || defined(__APPLE__)
|
||||
|
||||
// We don't ever expect to see these inputs, but be safe anyway.
|
||||
EXPECT_EQ(
|
||||
"",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"http://path",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://path", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://path", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"http://api.mapbox.com/v4/",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}.", SourceType::Raster, 256));
|
||||
EXPECT_EQ(
|
||||
"http://api.mapbox.com/v4/a.b/{z}/{x}/{y}/.",
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}/.", SourceType::Raster));
|
||||
mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}/.", SourceType::Raster, 256));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user