diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-05-22 17:38:07 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2020-05-26 20:35:06 +0300 |
commit | 0612938b8d408fc9c5e3ee975e1dfa58ebd48adb (patch) | |
tree | e64765b1eabbc5d351a2a0ee5b2903edb8c4d35e | |
parent | af22b1f0ce885f2d79c87a9cfb5f16bd59f0f62d (diff) | |
download | qtlocation-mapboxgl-0612938b8d408fc9c5e3ee975e1dfa58ebd48adb.tar.gz |
[core] Simplify mbgl::OfflineRegionDefinition
-rw-r--r-- | benchmark/storage/offline_database.benchmark.cpp | 2 | ||||
-rw-r--r-- | include/mbgl/storage/offline.hpp | 55 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/offline.cpp | 98 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/offline_download.cpp | 44 | ||||
-rw-r--r-- | test/storage/offline.test.cpp | 25 | ||||
-rw-r--r-- | test/storage/offline_database.test.cpp | 112 | ||||
-rw-r--r-- | test/storage/offline_download.test.cpp | 138 | ||||
-rw-r--r-- | tools/offline/offline.cpp | 6 |
8 files changed, 226 insertions, 254 deletions
diff --git a/benchmark/storage/offline_database.benchmark.cpp b/benchmark/storage/offline_database.benchmark.cpp index afdf6db4fc..1d107aad2c 100644 --- a/benchmark/storage/offline_database.benchmark.cpp +++ b/benchmark/storage/offline_database.benchmark.cpp @@ -43,7 +43,7 @@ public: db.deleteRegion(std::move(regions[0])); } - OfflineTilePyramidRegionDefinition definition{ "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition{"mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata{{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); diff --git a/include/mbgl/storage/offline.hpp b/include/mbgl/storage/offline.hpp index 97e7fc2e49..f92a5d4cd3 100644 --- a/include/mbgl/storage/offline.hpp +++ b/include/mbgl/storage/offline.hpp @@ -17,7 +17,7 @@ namespace mbgl { class TileID; /* - * An offline region defined by a style URL, geographic bounding box, zoom range, and + * An offline region defined by a style URL, geographic bounding box or geometry, zoom range, and * device pixel ratio. * * Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom. @@ -27,49 +27,42 @@ class TileID; * * pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0. */ -class OfflineTilePyramidRegionDefinition { +class OfflineRegionDefinition { public: - OfflineTilePyramidRegionDefinition(std::string, LatLngBounds, double, double, float, bool); + OfflineRegionDefinition(std::string styleURL_, + LatLngBounds bounds_, + double minZoom_, + double maxZoom_, + float pixelRatio_, + bool includeIdeographs_) + : OfflineRegionDefinition(std::move(styleURL_), minZoom_, maxZoom_, pixelRatio_, includeIdeographs_) { + location = std::move(bounds_); + } + OfflineRegionDefinition(std::string styleURL_, + Geometry<double> geometry_, + double minZoom_, + double maxZoom_, + float pixelRatio_, + bool includeIdeographs_) + : OfflineRegionDefinition(std::move(styleURL_), minZoom_, maxZoom_, pixelRatio_, includeIdeographs_) { + location = std::move(geometry_); + } /* Private */ std::string styleURL; - LatLngBounds bounds; double minZoom; double maxZoom; float pixelRatio; bool includeIdeographs; -}; + variant<LatLngBounds, Geometry<double>> location; -/* - * An offline region defined by a style URL, geometry, zoom range, and - * device pixel ratio. - * - * Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom. - * - * maxZoom may be ∞, in which case for each tile source, the region will include - * tiles from minZoom up to the maximum zoom level provided by that source. - * - * pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0. - */ -class OfflineGeometryRegionDefinition { -public: - OfflineGeometryRegionDefinition(std::string styleURL, Geometry<double>, double minZoom, double maxZoom, float pixelRatio, bool includeIdeographs); + bool isGeometryDefined() const { return location.is<Geometry<double>>(); } - /* Private */ - std::string styleURL; - Geometry<double> geometry; - double minZoom; - double maxZoom; - float pixelRatio; - bool includeIdeographs; +private: + OfflineRegionDefinition(std::string, double, double, float, bool); }; /* - * The offline region definition types supported - */ -using OfflineRegionDefinition = variant<OfflineTilePyramidRegionDefinition, OfflineGeometryRegionDefinition>; - -/* * The encoded format is private. */ std::string encodeOfflineRegionDefinition(const OfflineRegionDefinition&); diff --git a/platform/default/src/mbgl/storage/offline.cpp b/platform/default/src/mbgl/storage/offline.cpp index a0b596b861..a82d5351a8 100644 --- a/platform/default/src/mbgl/storage/offline.cpp +++ b/platform/default/src/mbgl/storage/offline.cpp @@ -14,16 +14,9 @@ namespace mbgl { -// OfflineTilePyramidRegionDefinition - -OfflineTilePyramidRegionDefinition::OfflineTilePyramidRegionDefinition(std::string styleURL_, - LatLngBounds bounds_, - double minZoom_, - double maxZoom_, - float pixelRatio_, - bool includeIdeographs_) +OfflineRegionDefinition::OfflineRegionDefinition( + std::string styleURL_, double minZoom_, double maxZoom_, float pixelRatio_, bool includeIdeographs_) : styleURL(std::move(styleURL_)), - bounds(bounds_), minZoom(minZoom_), maxZoom(maxZoom_), pixelRatio(pixelRatio_), @@ -34,21 +27,6 @@ OfflineTilePyramidRegionDefinition::OfflineTilePyramidRegionDefinition(std::stri } } -// OfflineGeometryRegionDefinition - -OfflineGeometryRegionDefinition::OfflineGeometryRegionDefinition(std::string styleURL_, Geometry<double> geometry_, double minZoom_, double maxZoom_, float pixelRatio_, bool includeIdeographs_) - : styleURL(std::move(styleURL_)) - , geometry(std::move(geometry_)) - , minZoom(minZoom_) - , maxZoom(maxZoom_) - , pixelRatio(pixelRatio_) - , includeIdeographs(includeIdeographs_){ - if (minZoom < 0 || maxZoom < 0 || maxZoom < minZoom || pixelRatio < 0 || - !std::isfinite(minZoom) || std::isnan(maxZoom) || !std::isfinite(pixelRatio)) { - throw std::invalid_argument("Invalid offline region definition"); - } -} - OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string& region) { rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; doc.Parse<0>(region.c_str()); @@ -84,19 +62,22 @@ OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string& region) bool includeIdeographs = doc.HasMember("include_ideographs") ? doc["include_ideographs"].GetBool() : true; if (doc.HasMember("bounds")) { - return OfflineTilePyramidRegionDefinition{ - styleURL, - LatLngBounds::hull( - LatLng(doc["bounds"][0].GetDouble(), doc["bounds"][1].GetDouble()), - LatLng(doc["bounds"][2].GetDouble(), doc["bounds"][3].GetDouble())), - minZoom, maxZoom, pixelRatio, includeIdeographs }; - } else { - return OfflineGeometryRegionDefinition{ - styleURL, - mapbox::geojson::convert<Geometry<double>>(doc["geometry"].GetObject()), - minZoom, maxZoom, pixelRatio, includeIdeographs }; - }; + return OfflineRegionDefinition{ + styleURL, + LatLngBounds::hull(LatLng(doc["bounds"][0].GetDouble(), doc["bounds"][1].GetDouble()), + LatLng(doc["bounds"][2].GetDouble(), doc["bounds"][3].GetDouble())), + minZoom, + maxZoom, + pixelRatio, + includeIdeographs}; + } + return OfflineRegionDefinition{styleURL, + mapbox::geojson::convert<Geometry<double>>(doc["geometry"].GetObject()), + minZoom, + maxZoom, + pixelRatio, + includeIdeographs}; } std::string encodeOfflineRegionDefinition(const OfflineRegionDefinition& region) { @@ -104,34 +85,29 @@ std::string encodeOfflineRegionDefinition(const OfflineRegionDefinition& region) doc.SetObject(); // Encode common properties - region.match([&](auto& _region) { - doc.AddMember("style_url", rapidjson::StringRef(_region.styleURL.data(), _region.styleURL.length()), doc.GetAllocator()); - doc.AddMember("min_zoom", _region.minZoom, doc.GetAllocator()); - if (std::isfinite(_region.maxZoom)) { - doc.AddMember("max_zoom", _region.maxZoom, doc.GetAllocator()); - } + doc.AddMember( + "style_url", rapidjson::StringRef(region.styleURL.data(), region.styleURL.length()), doc.GetAllocator()); + doc.AddMember("min_zoom", region.minZoom, doc.GetAllocator()); + if (std::isfinite(region.maxZoom)) { + doc.AddMember("max_zoom", region.maxZoom, doc.GetAllocator()); + } - doc.AddMember("pixel_ratio", _region.pixelRatio, doc.GetAllocator()); - doc.AddMember("include_ideographs", _region.includeIdeographs, doc.GetAllocator()); - }); + doc.AddMember("pixel_ratio", region.pixelRatio, doc.GetAllocator()); + doc.AddMember("include_ideographs", region.includeIdeographs, doc.GetAllocator()); // Encode specific properties - region.match( - [&] (const OfflineTilePyramidRegionDefinition& _region) { - rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator> bounds(rapidjson::kArrayType); - bounds.PushBack(_region.bounds.south(), doc.GetAllocator()); - bounds.PushBack(_region.bounds.west(), doc.GetAllocator()); - bounds.PushBack(_region.bounds.north(), doc.GetAllocator()); - bounds.PushBack(_region.bounds.east(), doc.GetAllocator()); - doc.AddMember("bounds", bounds, doc.GetAllocator()); - - }, - [&] (const OfflineGeometryRegionDefinition& _region) { - doc.AddMember("geometry", mapbox::geojson::convert(_region.geometry, doc.GetAllocator()), doc.GetAllocator()); - - } - ); - + region.location.match( + [&](const LatLngBounds& regionBounds) { + rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator> bounds(rapidjson::kArrayType); + bounds.PushBack(regionBounds.south(), doc.GetAllocator()); + bounds.PushBack(regionBounds.west(), doc.GetAllocator()); + bounds.PushBack(regionBounds.north(), doc.GetAllocator()); + bounds.PushBack(regionBounds.east(), doc.GetAllocator()); + doc.AddMember("bounds", bounds, doc.GetAllocator()); + }, + [&](const Geometry<double>& geometry) { + doc.AddMember("geometry", mapbox::geojson::convert(geometry, doc.GetAllocator()), doc.GetAllocator()); + }); rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); diff --git a/platform/default/src/mbgl/storage/offline_download.cpp b/platform/default/src/mbgl/storage/offline_download.cpp index ef33d2f3ee..8fa2748a34 100644 --- a/platform/default/src/mbgl/storage/offline_download.cpp +++ b/platform/default/src/mbgl/storage/offline_download.cpp @@ -30,9 +30,7 @@ namespace mbgl { using namespace style; // Generic functions - -template <class RegionDefinition> -Range<uint8_t> coveringZoomRange(const RegionDefinition& definition, +Range<uint8_t> coveringZoomRange(const OfflineRegionDefinition& definition, const style::Source& source, const Range<uint8_t>& zoomRange) { double minZ = std::max<double>(source.getCoveringZoomLevel(definition.minZoom), zoomRange.min); @@ -58,26 +56,24 @@ void tileCover(const OfflineRegionDefinition& definition, const style::Source& source, const Range<uint8_t>& zoomRange, Fn&& fn) { - const Range<uint8_t> clampedZoomRange = - definition.match([&](auto& reg) { return coveringZoomRange(reg, source, zoomRange); }); + const Range<uint8_t> clampedZoomRange = coveringZoomRange(definition, source, zoomRange); - for (uint8_t z = clampedZoomRange.min; z <= clampedZoomRange.max; z++) { - definition.match([&](const OfflineTilePyramidRegionDefinition& reg) { tileCover(reg.bounds, z, fn); }, - [&](const OfflineGeometryRegionDefinition& reg) { tileCover(reg.geometry, z, fn); }); + for (uint8_t z = clampedZoomRange.min; z <= clampedZoomRange.max; ++z) { + definition.location.match([&](const LatLngBounds& bounds) { tileCover(bounds, z, fn); }, + [&](const Geometry<double>& geometry) { tileCover(geometry, z, fn); }); } } uint64_t tileCount(const OfflineRegionDefinition& definition, const style::Source& source, const Range<uint8_t>& zoomRange) { - const Range<uint8_t> clampedZoomRange = - definition.match([&](auto& reg) { return coveringZoomRange(reg, source, zoomRange); }); + const Range<uint8_t> clampedZoomRange = coveringZoomRange(definition, source, zoomRange); unsigned long result = 0; - for (uint8_t z = clampedZoomRange.min; z <= clampedZoomRange.max; z++) { - result += definition.match( - [&](const OfflineTilePyramidRegionDefinition& reg) { return util::tileCount(reg.bounds, z); }, - [&](const OfflineGeometryRegionDefinition& reg) { return util::tileCount(reg.geometry, z); }); + for (uint8_t z = clampedZoomRange.min; z <= clampedZoomRange.max; ++z) { + result += + definition.location.match([z](const Geometry<double>& geometry) { return util::tileCount(geometry, z); }, + [z](const LatLngBounds& bounds) { return util::tileCount(bounds, z); }); } return result; @@ -131,8 +127,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const { } result->requiredResourceCount++; - optional<Response> styleResponse = - offlineDatabase.get(Resource::style(definition.match([](auto& reg) { return reg.styleURL; }))); + optional<Response> styleResponse = offlineDatabase.get(Resource::style(definition.styleURL)); if (!styleResponse) { return *result; } @@ -179,9 +174,8 @@ OfflineRegionStatus OfflineDownload::getStatus() const { if (!parser.glyphURL.empty()) { result->requiredResourceCount += - parser.fontStacks().size() * (definition.match([](auto& reg) { return reg.includeIdeographs; }) - ? GLYPH_RANGES_PER_FONT_STACK - : NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK); + parser.fontStacks().size() * + (definition.includeIdeographs ? GLYPH_RANGES_PER_FONT_STACK : NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK); } if (!parser.spriteURL.empty()) { @@ -196,7 +190,7 @@ void OfflineDownload::activateDownload() { status.downloadState = OfflineRegionDownloadState::Active; status.requiredResourceCount++; - auto styleResource = Resource::style(definition.match([](auto& reg) { return reg.styleURL; })); + auto styleResource = Resource::style(definition.styleURL); styleResource.setPriority(Resource::Priority::Low); styleResource.setUsage(Resource::Usage::Offline); @@ -249,7 +243,7 @@ void OfflineDownload::activateDownload() { } if (!parser.glyphURL.empty()) { - const bool includeIdeographs = definition.match([](auto& reg) { return reg.includeIdeographs; }); + const bool includeIdeographs = definition.includeIdeographs; for (const auto& fontStack : parser.fontStacks()) { for (char16_t i = 0; i < GLYPH_RANGES_PER_FONT_STACK; i++) { // Assumes that if a glyph range starts with fixed width/ideographic characters, the entire @@ -351,12 +345,8 @@ void OfflineDownload::queueTiles(const Source& source, const Tileset& tileset) { status.requiredResourceCount++; status.requiredTileCount++; - auto tileResource = Resource::tile(tileset.tiles[0], - definition.match([](auto& def) { return def.pixelRatio; }), - tile.x, - tile.y, - tile.z, - tileset.scheme); + auto tileResource = + Resource::tile(tileset.tiles[0], definition.pixelRatio, tile.x, tile.y, tile.z, tileset.scheme); tileResource.setPriority(Resource::Priority::Low); tileResource.setUsage(Resource::Usage::Offline); diff --git a/test/storage/offline.test.cpp b/test/storage/offline.test.cpp index 8335e43db1..227f9f7c1a 100644 --- a/test/storage/offline.test.cpp +++ b/test/storage/offline.test.cpp @@ -7,30 +7,37 @@ using namespace mbgl; TEST(OfflineTilePyramidRegionDefinition, EncodeDecode) { - OfflineTilePyramidRegionDefinition region("mapbox://style", LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }), 0, 20, 1.0, true); + const auto kBounds = LatLngBounds::hull({37.6609, -122.5744}, {37.8271, -122.3204}); + OfflineRegionDefinition region("mapbox://style", kBounds, 0, 20, 1.0, true); auto encoded = encodeOfflineRegionDefinition(region); - auto decoded = decodeOfflineRegionDefinition(encoded).get<OfflineTilePyramidRegionDefinition>(); - + auto decoded = decodeOfflineRegionDefinition(encoded); + EXPECT_EQ(decoded.styleURL, region.styleURL); EXPECT_EQ(decoded.minZoom, region.minZoom); EXPECT_EQ(decoded.maxZoom, region.maxZoom); EXPECT_EQ(decoded.pixelRatio, region.pixelRatio); - EXPECT_EQ(decoded.bounds.southwest(), region.bounds.southwest()); - EXPECT_EQ(decoded.bounds.northeast(), region.bounds.northeast()); + EXPECT_EQ(decoded.location, region.location); + EXPECT_EQ(decoded.isGeometryDefined(), region.isGeometryDefined()); + ASSERT_FALSE(decoded.isGeometryDefined()); + EXPECT_EQ(kBounds, decoded.location.get<LatLngBounds>()); EXPECT_EQ(decoded.includeIdeographs, region.includeIdeographs); } TEST(OfflineGeometryRegionDefinition, EncodeDecode) { - OfflineGeometryRegionDefinition region("mapbox://style", Point<double>(-122.5744, 37.6609), 0, 2, 1.0, false); + const Geometry<double> kGeometry{Point<double>(-122.5744, 37.6609)}; + OfflineRegionDefinition region("mapbox://style", kGeometry, 0, 2, 1.0, false); auto encoded = encodeOfflineRegionDefinition(region); - auto decoded = decodeOfflineRegionDefinition(encoded).get<OfflineGeometryRegionDefinition>(); - + auto decoded = decodeOfflineRegionDefinition(encoded); + EXPECT_EQ(decoded.styleURL, region.styleURL); EXPECT_EQ(decoded.minZoom, region.minZoom); EXPECT_EQ(decoded.maxZoom, region.maxZoom); EXPECT_EQ(decoded.pixelRatio, region.pixelRatio); - EXPECT_EQ(decoded.geometry, region.geometry); + EXPECT_EQ(decoded.location, region.location); + EXPECT_EQ(decoded.isGeometryDefined(), region.isGeometryDefined()); + ASSERT_TRUE(decoded.isGeometryDefined()); + EXPECT_EQ(kGeometry, decoded.location.get<Geometry<double>>()); EXPECT_EQ(decoded.includeIdeographs, region.includeIdeographs); } diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 6b444bf3d1..ea987a6838 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -431,32 +431,29 @@ TEST(OfflineDatabase, PutTileNotFound) { TEST(OfflineDatabase, CreateRegion) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + const auto bounds = LatLngBounds::hull({1, 2}, {3, 4}); + OfflineRegionDefinition definition{"http://example.com/style", bounds, 5, 6, 2.0, true}; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); EXPECT_EQ(0u, log.uncheckedCount()); + const auto& def = region->getDefinition(); + EXPECT_EQ(definition.styleURL, def.styleURL); + EXPECT_EQ(definition.minZoom, def.minZoom); + EXPECT_EQ(definition.maxZoom, def.maxZoom); + EXPECT_EQ(definition.pixelRatio, def.pixelRatio); + EXPECT_EQ(definition.includeIdeographs, def.includeIdeographs); + EXPECT_EQ(definition.isGeometryDefined(), def.isGeometryDefined()); - region->getDefinition().match( - [&](OfflineTilePyramidRegionDefinition& def) { - EXPECT_EQ(definition.styleURL, def.styleURL); - EXPECT_EQ(definition.bounds, def.bounds); - EXPECT_EQ(definition.minZoom, def.minZoom); - EXPECT_EQ(definition.maxZoom, def.maxZoom); - EXPECT_EQ(definition.pixelRatio, def.pixelRatio); - EXPECT_EQ(definition.includeIdeographs, def.includeIdeographs); - }, [](auto&) { - EXPECT_FALSE(false); - } - ); + def.location.match([&](LatLngBounds& bounds_) { EXPECT_EQ(bounds, bounds_); }, [](auto&) { EXPECT_FALSE(false); }); EXPECT_EQ(metadata, region->getMetadata()); } TEST(OfflineDatabase, UpdateMetadata) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition{"http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); @@ -472,7 +469,8 @@ TEST(OfflineDatabase, UpdateMetadata) { TEST(OfflineDatabase, ListRegions) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false }; + OfflineRegionDefinition definition{ + "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false}; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); @@ -482,18 +480,13 @@ TEST(OfflineDatabase, ListRegions) { ASSERT_EQ(1u, regions.size()); EXPECT_EQ(region->getID(), regions.at(0).getID()); - regions.at(0).getDefinition().match( - [&](OfflineTilePyramidRegionDefinition& def) { - EXPECT_EQ(definition.styleURL, def.styleURL); - EXPECT_EQ(definition.bounds, def.bounds); - EXPECT_EQ(definition.minZoom, def.minZoom); - EXPECT_EQ(definition.maxZoom, def.maxZoom); - EXPECT_EQ(definition.pixelRatio, def.pixelRatio); - EXPECT_EQ(definition.includeIdeographs, def.includeIdeographs); - }, - [&](auto&) { - EXPECT_FALSE(false); - }); + const auto& def = regions.at(0).getDefinition(); + EXPECT_EQ(definition.styleURL, def.styleURL); + EXPECT_EQ(definition.location, def.location); + EXPECT_EQ(definition.minZoom, def.minZoom); + EXPECT_EQ(definition.maxZoom, def.maxZoom); + EXPECT_EQ(definition.pixelRatio, def.pixelRatio); + EXPECT_EQ(definition.includeIdeographs, def.includeIdeographs); EXPECT_EQ(metadata, regions.at(0).getMetadata()); EXPECT_EQ(0u, log.uncheckedCount()); @@ -502,25 +495,21 @@ TEST(OfflineDatabase, ListRegions) { TEST(OfflineDatabase, GetRegionDefinition) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false }; + OfflineRegionDefinition definition{ + "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false}; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; EXPECT_EQ(0u, log.uncheckedCount()); auto region = db.createRegion(definition, metadata); - db.getRegionDefinition(region->getID())->match( - [&](OfflineTilePyramidRegionDefinition& result) { - EXPECT_EQ(definition.styleURL, result.styleURL); - EXPECT_EQ(definition.bounds, result.bounds); - EXPECT_EQ(definition.minZoom, result.minZoom); - EXPECT_EQ(definition.maxZoom, result.maxZoom); - EXPECT_EQ(definition.pixelRatio, result.pixelRatio); - EXPECT_EQ(definition.includeIdeographs, result.includeIdeographs); - }, - [&](auto&) { - EXPECT_FALSE(false); - } - ); + auto result = db.getRegionDefinition(region->getID()); + ASSERT_TRUE(result); + EXPECT_EQ(definition.styleURL, result->styleURL); + EXPECT_EQ(definition.location, result->location); + EXPECT_EQ(definition.minZoom, result->minZoom); + EXPECT_EQ(definition.maxZoom, result->maxZoom); + EXPECT_EQ(definition.pixelRatio, result->pixelRatio); + EXPECT_EQ(definition.includeIdeographs, result->includeIdeographs); } // Disabled due to flakiness: https://github.com/mapbox/mapbox-gl-native/issues/14966 @@ -546,7 +535,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DISABLED_MaximumAmbientCacheSize)) { OfflineDatabase db(filename); db.setMaximumAmbientCacheSize(maximumSize); // 50 MB - OfflineTilePyramidRegionDefinition definition{ "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition{"mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata{{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); @@ -690,7 +679,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) { OfflineDatabase db(filename); - OfflineTilePyramidRegionDefinition definition{ "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition{"mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata{{ 1, 2, 3 }}; auto region1 = db.createRegion(definition, metadata); @@ -787,10 +776,10 @@ TEST(OfflineDatabase, MapboxTileLimitExceeded) { db.putRegionResource(regionID, tile, response); }; - OfflineTilePyramidRegionDefinition definition1{ "mapbox://style1", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition1{"mapbox://style1", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata1{{ 1, 2, 3 }}; - OfflineTilePyramidRegionDefinition definition2{ "mapbox://style2", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition2{"mapbox://style2", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata2{{ 1, 2, 3 }}; auto region1 = db.createRegion(definition1, metadata1); @@ -881,7 +870,7 @@ TEST(OfflineDatabase, Invalidate) { const Resource ambientStyle = Resource::style("mapbox://style_ambient"); db.put(ambientStyle, response); - OfflineTilePyramidRegionDefinition definition { "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true }; + OfflineRegionDefinition definition{"mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region1 = db.createRegion(definition, metadata); @@ -989,17 +978,14 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ClearAmbientCache)) { TEST(OfflineDatabase, CreateRegionInfiniteMaxZoom) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, false }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, false}; OfflineRegionMetadata metadata; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); EXPECT_EQ(0u, log.uncheckedCount()); - - region->getDefinition().match([&](auto& def) { - EXPECT_EQ(0, def.minZoom); - EXPECT_EQ(INFINITY, def.maxZoom); - }); + EXPECT_EQ(0, region->getDefinition().minZoom); + EXPECT_EQ(INFINITY, region->getDefinition().maxZoom); } TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) { @@ -1091,8 +1077,7 @@ TEST(OfflineDatabase, OfflineRegionDoesNotAffectAmbientCacheSize) { // First 100KB ambient cache resource. db.put(Resource::style("http://example.com/ambient1.json"s), response); - OfflineTilePyramidRegionDefinition definition( - "http://example.com/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false); + OfflineRegionDefinition definition("http://example.com/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false); auto region = db.createRegion(definition, OfflineRegionMetadata()); // 1MB of offline region data. @@ -1118,7 +1103,7 @@ TEST(OfflineDatabase, PutRegionResourceDoesNotEvict) { OfflineDatabase db(":memory:"); db.setMaximumAmbientCacheSize(1024 * 100); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, true }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, true}; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -1157,7 +1142,8 @@ TEST(OfflineDatabase, PutFailsWhenEvictionInsuffices) { TEST(OfflineDatabase, GetRegionCompletedStatus) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false }; + OfflineRegionDefinition definition{ + "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, false}; OfflineRegionMetadata metadata; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); @@ -1198,7 +1184,7 @@ TEST(OfflineDatabase, HasRegionResource) { OfflineDatabase db(":memory:"); db.setMaximumAmbientCacheSize(1024 * 100); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, true }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, true}; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -1224,7 +1210,7 @@ TEST(OfflineDatabase, HasRegionResourceTile) { OfflineDatabase db(":memory:"); db.setMaximumAmbientCacheSize(1024 * 100); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, false }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, false}; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -1258,7 +1244,7 @@ TEST(OfflineDatabase, HasRegionResourceTile) { TEST(OfflineDatabase, OfflineMapboxTileCount) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 , true}; + OfflineRegionDefinition definition{"http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true}; OfflineRegionMetadata metadata; auto region1 = db.createRegion(definition, metadata); @@ -1321,7 +1307,7 @@ TEST(OfflineDatabase, BatchInsertion) { OfflineDatabase db(":memory:"); db.setMaximumAmbientCacheSize(1024 * 100); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, true }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, true}; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -1349,7 +1335,7 @@ TEST(OfflineDatabase, BatchInsertionMapboxTileCountExceeded) { db.setOfflineMapboxTileCountLimit(1); db.setMaximumAmbientCacheSize(1024 * 100); - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0, false }; + OfflineRegionDefinition definition{"", LatLngBounds::world(), 0, INFINITY, 1.0, false}; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -1600,8 +1586,8 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DisallowedIO)) { EXPECT_EQ(0u, log.uncheckedCount()); // First, create a region object so that we can try deleting it later. - OfflineTilePyramidRegionDefinition definition( - "mapbox://style", LatLngBounds::hull({ 37.66, -122.57 }, { 37.83, -122.32 }), 0, 8, 2, false); + OfflineRegionDefinition definition( + "mapbox://style", LatLngBounds::hull({37.66, -122.57}, {37.83, -122.32}), 0, 8, 2, false); auto region = db.createRegion(definition, {}); ASSERT_TRUE(region); diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp index e5178e3901..2e37f3cd7b 100644 --- a/test/storage/offline_download.test.cpp +++ b/test/storage/offline_download.test.cpp @@ -68,7 +68,7 @@ public: std::size_t size = 0; auto createRegion() { - OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 1.0, true }; + OfflineRegionDefinition definition{"", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 1.0, true}; OfflineRegionMetadata metadata; return db.createRegion(definition, metadata); } @@ -93,8 +93,9 @@ TEST(OfflineDownload, NoSubresources) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -134,8 +135,9 @@ TEST(OfflineDownload, InlineSource) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -176,8 +178,9 @@ TEST(OfflineDownload, GeoJSONSource) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -212,8 +215,9 @@ TEST(OfflineDownload, Activate) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -290,10 +294,11 @@ TEST(OfflineDownload, ExcludeIdeographs) { auto region = test.createRegion(); ASSERT_TRUE(region); OfflineDownload download( - region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); - + region->getID(), + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); + test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); return test.response("style.json"); @@ -371,8 +376,9 @@ TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + fileSource); auto observer = std::make_unique<MockObserver>(); @@ -394,8 +400,9 @@ TEST(OfflineDownload, GetStatusNoResources) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); OfflineRegionStatus status = download.getStatus(); EXPECT_EQ(OfflineRegionDownloadState::Inactive, status.downloadState); @@ -414,8 +421,9 @@ TEST(OfflineDownload, GetStatusStyleComplete) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.db.putRegionResource(1, Resource::style("http://127.0.0.1:3000/style.json"), @@ -439,8 +447,9 @@ TEST(OfflineDownload, GetStatusStyleAndSourceComplete) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.db.putRegionResource(1, Resource::style("http://127.0.0.1:3000/style.json"), @@ -468,8 +477,9 @@ TEST(OfflineDownload, RequestError) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource&) { Response response; @@ -497,8 +507,9 @@ TEST(OfflineDownload, RequestErrorsAreRetried) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource&) { test.fileSource.styleResponse = [&] (const Resource&) { @@ -531,8 +542,9 @@ TEST(OfflineDownload, TileCountLimitExceededNoTileResponse) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); uint64_t tileLimit = 0; @@ -574,8 +586,9 @@ TEST(OfflineDownload, TileCountLimitExceededWithTileResponse) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); uint64_t tileLimit = 1; @@ -629,8 +642,9 @@ TEST(OfflineDownload, WithPreviouslyExistingTile) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -664,8 +678,9 @@ TEST(OfflineDownload, ReactivatePreviouslyCompletedDownload) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -690,8 +705,9 @@ TEST(OfflineDownload, ReactivatePreviouslyCompletedDownload) { OfflineDownload redownload( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); std::vector<OfflineRegionStatus> statusesAfterReactivate; @@ -732,8 +748,9 @@ TEST(OfflineDownload, Deactivate) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -762,8 +779,9 @@ TEST(OfflineDownload, AllOfflineRequestsHaveLowPriorityAndOfflineUsage) { ASSERT_TRUE(region); OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_TRUE(resource.priority == Resource::Priority::Low); @@ -839,8 +857,9 @@ TEST(OfflineDownload, DiskFull) { OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); bool hasRequestedStyle = false; @@ -885,9 +904,10 @@ TEST(OfflineDownload, ResourceOfflineUsageUnset) { OfflineDownload download( region->getID(), - OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/inline_source.style.json", - LatLngBounds::world(), 0.0, 0.0, 1.0, false), - test.db, test.fileSource); + OfflineRegionDefinition( + "http://127.0.0.1:3000/inline_source.style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, false), + test.db, + test.fileSource); test.fileSource.styleResponse = [&] (const Resource& resource) { EXPECT_TRUE(resource.priority == Resource::Priority::Low); @@ -950,11 +970,11 @@ TEST(OfflineDownload, InterruptAndResume) { OfflineTest test; auto region = test.createRegion(); ASSERT_TRUE(region); - OfflineDownload download(region->getID(), - OfflineTilePyramidRegionDefinition( - "http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, - test.fileSource); + OfflineDownload download( + region->getID(), + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&](const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); @@ -1031,11 +1051,11 @@ TEST(OfflineDownload, NoFreezingOnCachedTilesAndNewStyle) { OfflineTest test; auto region = test.createRegion(); ASSERT_TRUE(region); - OfflineDownload download(region->getID(), - OfflineTilePyramidRegionDefinition( - "http://127.0.0.1:3000/style.json", LatLngBounds::world(), 1.0, 1.0, 1.0, true), - test.db, - test.fileSource); + OfflineDownload download( + region->getID(), + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 1.0, 1.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.setProperty(MAX_CONCURRENT_REQUESTS_KEY, 2u); test.fileSource.styleResponse = [&](const Resource&) { return test.response("inline_source.style.json"); }; @@ -1067,11 +1087,11 @@ TEST(OfflineDownload, NoFreezingOnNotFoundError) { OfflineTest test; auto region = test.createRegion(); ASSERT_TRUE(region); - OfflineDownload download(region->getID(), - OfflineTilePyramidRegionDefinition( - "http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), - test.db, - test.fileSource); + OfflineDownload download( + region->getID(), + OfflineRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true), + test.db, + test.fileSource); test.fileSource.styleResponse = [&](const Resource& resource) { EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url); diff --git a/tools/offline/offline.cpp b/tools/offline/offline.cpp index 97b60c223f..1847692432 100644 --- a/tools/offline/offline.cpp +++ b/tools/offline/offline.cpp @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) { const double minZoom = minZoomValue ? args::get(minZoomValue) : 0.0; const double maxZoom = maxZoomValue ? args::get(maxZoomValue) : 15.0; - const double pixelRatio = pixelRatioValue ? args::get(pixelRatioValue) : 1.0; + const float pixelRatio = pixelRatioValue ? float(args::get(pixelRatioValue)) : 1.0f; const bool includeIdeographs = includeIdeographsValue ? args::get(includeIdeographsValue) : false; const std::string output = outputValue ? args::get(outputValue) : "offline.db"; @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) { try { std::string json = readFile(geometryValue.Get()); auto geometry = parseGeometry(json); - return OfflineRegionDefinition{ OfflineGeometryRegionDefinition(style, geometry, minZoom, maxZoom, pixelRatio, includeIdeographs) }; + return OfflineRegionDefinition{style, geometry, minZoom, maxZoom, pixelRatio, includeIdeographs}; } catch(const std::runtime_error& e) { std::cerr << "Could not parse geojson file " << geometryValue.Get() << ": " << e.what() << std::endl; exit(1); @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { const double south = southValue ? args::get(southValue) : 38.1; const double east = eastValue ? args::get(eastValue) : -121.7; LatLngBounds boundingBox = LatLngBounds::hull(LatLng(north, west), LatLng(south, east)); - return OfflineRegionDefinition{ OfflineTilePyramidRegionDefinition(style, boundingBox, minZoom, maxZoom, pixelRatio, includeIdeographs) }; + return OfflineRegionDefinition{style, boundingBox, minZoom, maxZoom, pixelRatio, includeIdeographs}; } }(); |