summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp4
-rw-r--r--src/mbgl/map/source.cpp2
-rw-r--r--src/mbgl/style/style_parser.cpp9
-rw-r--r--src/mbgl/style/style_parser.hpp2
-rw-r--r--src/mbgl/util/mapbox.cpp12
-rw-r--r--src/mbgl/util/mapbox.hpp2
-rw-r--r--test/style/style_parser.cpp6
-rw-r--r--test/util/mapbox.cpp50
8 files changed, 56 insertions, 31 deletions
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index 717bf3903c..27bf3b8c5b 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -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()) {
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 1a7933f53e..96af8c3cba 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -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;
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index 50276c8f5b..7c2a94b206 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -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;
diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp
index 162a10c87c..6b7c3fefbb 100644
--- a/src/mbgl/style/style_parser.hpp
+++ b/src/mbgl/style/style_parser.hpp
@@ -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&);
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 93b2b8521c..7ee0f279b6 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -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
diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp
index c03916ff63..bb0536cfa2 100644
--- a/src/mbgl/util/mapbox.hpp
+++ b/src/mbgl/util/mapbox.hpp
@@ -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
diff --git a/test/style/style_parser.cpp b/test/style/style_parser.cpp
index 8a9c4b3c4f..64ee4af9fc 100644
--- a/test/style/style_parser.cpp
+++ b/test/style/style_parser.cpp
@@ -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);
diff --git a/test/util/mapbox.cpp b/test/util/mapbox.cpp
index c211dc36b6..4fc22d3b34 100644
--- a/test/util/mapbox.cpp
+++ b/test/util/mapbox.cpp
@@ -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));
}