Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Always store tiles without ratio support with ratio = 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 11, 2016
1 parent 7e287ca commit 20be32f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion platform/default/mbgl/storage/offline_schema.cpp.include
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions platform/default/mbgl/storage/offline_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/storage/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
26 changes: 18 additions & 8 deletions test/storage/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 20be32f

Please sign in to comment.