From 3e75feda52198952068ca45e290f8a691ba90b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 26 Sep 2016 17:26:15 +0200 Subject: [core] don't load tiles from sources that aren't used --- src/mbgl/style/style.cpp | 9 ++++++--- test/map/map.test.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index fbe28e1795..20d34b7605 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -214,7 +214,9 @@ double Style::getDefaultPitch() const { void Style::updateTiles(const UpdateParameters& parameters) { for (const auto& source : sources) { - source->baseImpl->updateTiles(parameters); + if (source->baseImpl->enabled) { + source->baseImpl->updateTiles(parameters); + } } } @@ -227,8 +229,9 @@ void Style::updateSymbolDependentTiles() { void Style::relayout() { for (const auto& sourceID : updateBatch.sourceIDs) { Source* source = getSource(sourceID); - if (!source) continue; - source->baseImpl->reloadTiles(); + if (source && source->baseImpl->enabled) { + source->baseImpl->reloadTiles(); + } } updateBatch.sourceIDs.clear(); } diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 97a09e94a0..f6b37d6bc2 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -394,3 +394,51 @@ TEST(Map, RemoveImage) { map.removeImage("test-icon"); test::checkImage("test/fixtures/map/remove_icon", test::render(map, test.view)); } + +TEST(Map, DontLoadUnneededTiles) { + MapTest test; + + Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + map.setStyleJSON(R"STYLE({ + "sources": { + "a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] } + }, + "layers": [{ + "id": "a", + "type": "fill", + "source": "a", + "source-layer": "a", + "minzoom": 0.3, + "maxzoom": 1.6 + }] +})STYLE"); + + using Tiles = std::unordered_set; + Tiles tiles; + + test.fileSource.tileResponse = [&](const Resource& rsc) { + tiles.emplace(rsc.url); + Response res; + res.noContent = true; + return res; + }; + + std::unordered_map referenceTiles = { + // Since the layer's minzoom is 0.3, we shouldn't load tiles before z0.3 + { 0.3, { "a/0/0/0" } }, + { 1.0, { "a/1/1/0", "a/1/0/1", "a/1/0/0", "a/1/1/1" } }, + // Since the layer's maxzoom is 1.6, we should never load z2 or z3 tiles. + }; + + // Loop through zoom levels from 0 to 3 and check that the correct tiles are loaded at every + // step. The source is marked with maxzoom 1.0, which means that it won't be visible anymore + // after z1.0, so we should under no circumstances attempt to load z2 tiles. + for (unsigned zoom = 0; zoom <= 30; zoom++) { // times 10 + // Note: using z += 0.1 in the loop doesn't produce accurate floating point numbers. + const double z = double(zoom) / 10; + tiles.clear(); + map.setZoom(z); + test::render(map, test.view); + EXPECT_EQ(referenceTiles[z], tiles) << "zoom level " << z; + } +} -- cgit v1.2.1