summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-10 16:22:10 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-10 16:25:47 -0800
commit20be32f217b860bb0b5af3b32cea2d928b091d29 (patch)
treeca167e3dfebee2fce67046bb80781b530e8961f6
parent7e287cae1b13354c202cb419c945f2883dbe0601 (diff)
downloadqtlocation-mapboxgl-20be32f217b860bb0b5af3b32cea2d928b091d29.tar.gz
[core] Always store tiles without ratio support with ratio = 1
-rw-r--r--platform/default/mbgl/storage/offline_schema.cpp.include2
-rw-r--r--platform/default/mbgl/storage/offline_schema.sql4
-rw-r--r--src/mbgl/storage/resource.cpp3
-rw-r--r--test/storage/resource.cpp26
4 files changed, 23 insertions, 12 deletions
diff --git a/platform/default/mbgl/storage/offline_schema.cpp.include b/platform/default/mbgl/storage/offline_schema.cpp.include
index b02f2dffa2..3068dadfe0 100644
--- a/platform/default/mbgl/storage/offline_schema.cpp.include
+++ b/platform/default/mbgl/storage/offline_schema.cpp.include
@@ -15,7 +15,7 @@ static const char * schema =
"CREATE TABLE tiles (\n"
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
" url_template TEXT NOT NULL,\n"
-" pixel_ratio INTEGER,\n"
+" pixel_ratio INTEGER NOT NULL,\n"
" z INTEGER NOT NULL,\n"
" x INTEGER NOT NULL,\n"
" y INTEGER NOT NULL,\n"
diff --git a/platform/default/mbgl/storage/offline_schema.sql b/platform/default/mbgl/storage/offline_schema.sql
index 409a70ca6d..cba922f3f7 100644
--- a/platform/default/mbgl/storage/offline_schema.sql
+++ b/platform/default/mbgl/storage/offline_schema.sql
@@ -13,8 +13,8 @@ CREATE TABLE resources ( -- Generic table for style, source, s
CREATE TABLE tiles (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- url_template TEXT NOT NULL, -- As it would appear in TileJSON (but no support for host sharding).
- pixel_ratio INTEGER, -- If NULL, 1 is assumed for raster sources.
+ url_template TEXT NOT NULL,
+ pixel_ratio INTEGER NOT NULL,
z INTEGER NOT NULL,
x INTEGER NOT NULL,
y INTEGER NOT NULL,
diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp
index 6f727a6027..d5b88d9292 100644
--- a/src/mbgl/storage/resource.cpp
+++ b/src/mbgl/storage/resource.cpp
@@ -49,6 +49,7 @@ Resource Resource::glyphs(const std::string& urlTemplate, const std::string& fon
}
Resource Resource::tile(const std::string& urlTemplate, float pixelRatio, int32_t x, int32_t y, int8_t z) {
+ bool supportsRatio = urlTemplate.find("{ratio}") != std::string::npos;
return Resource {
Resource::Kind::Tile,
util::replaceTokens(urlTemplate, [&](const std::string& token) {
@@ -71,7 +72,7 @@ Resource Resource::tile(const std::string& urlTemplate, float pixelRatio, int32_
}),
Resource::TileData {
urlTemplate,
- uint8_t(pixelRatio > 1.0 ? 2 : 1),
+ uint8_t(supportsRatio && pixelRatio > 1.0 ? 2 : 1),
x,
y,
z
diff --git a/test/storage/resource.cpp b/test/storage/resource.cpp
index 30c1597df2..0b04c1b3e4 100644
--- a/test/storage/resource.cpp
+++ b/test/storage/resource.cpp
@@ -18,14 +18,24 @@ TEST(Resource, Source) {
TEST(Resource, Tile) {
using namespace mbgl;
- Resource resource = Resource::tile("http://example.com/{z}/{x}/{y}{ratio}.png", 2.0, 1, 2, 3);
- EXPECT_EQ(Resource::Kind::Tile, resource.kind);
- EXPECT_EQ("http://example.com/3/1/2@2x.png", resource.url);
- EXPECT_EQ("http://example.com/{z}/{x}/{y}{ratio}.png", resource.tileData->urlTemplate);
- EXPECT_EQ(2.0, resource.tileData->pixelRatio);
- EXPECT_EQ(1, resource.tileData->x);
- EXPECT_EQ(2, resource.tileData->y);
- EXPECT_EQ(3, resource.tileData->z);
+
+ Resource rasterTile = Resource::tile("http://example.com/{z}/{x}/{y}{ratio}.png", 2.0, 1, 2, 3);
+ EXPECT_EQ(Resource::Kind::Tile, rasterTile.kind);
+ EXPECT_EQ("http://example.com/3/1/2@2x.png", rasterTile.url);
+ EXPECT_EQ("http://example.com/{z}/{x}/{y}{ratio}.png", rasterTile.tileData->urlTemplate);
+ EXPECT_EQ(2, rasterTile.tileData->pixelRatio);
+ EXPECT_EQ(1, rasterTile.tileData->x);
+ EXPECT_EQ(2, rasterTile.tileData->y);
+ EXPECT_EQ(3, rasterTile.tileData->z);
+
+ Resource vectorTile = Resource::tile("http://example.com/{z}/{x}/{y}.mvt", 2.0, 1, 2, 3);
+ EXPECT_EQ(Resource::Kind::Tile, vectorTile.kind);
+ EXPECT_EQ("http://example.com/3/1/2.mvt", vectorTile.url);
+ EXPECT_EQ("http://example.com/{z}/{x}/{y}.mvt", vectorTile.tileData->urlTemplate);
+ EXPECT_EQ(1, vectorTile.tileData->pixelRatio);
+ EXPECT_EQ(1, vectorTile.tileData->x);
+ EXPECT_EQ(2, vectorTile.tileData->y);
+ EXPECT_EQ(3, vectorTile.tileData->z);
}
TEST(Resource, Glyphs) {