[core] Always store tiles without ratio support with ratio = 1

This commit is contained in:
John Firebaugh
2016-02-10 16:22:10 -08:00
parent 7e287cae1b
commit 20be32f217
4 changed files with 23 additions and 12 deletions

View File

@@ -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"

View File

@@ -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,

View File

@@ -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

View File

@@ -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) {