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

Commit

Permalink
[core] don't load tiles from sources that aren't used
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Oct 27, 2016
1 parent e7bfa78 commit 9127299
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,18 @@ 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);
}
}
}

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();
}
Expand Down
48 changes: 48 additions & 0 deletions test/map/map.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>;
Tiles tiles;

test.fileSource.tileResponse = [&](const Resource& rsc) {
tiles.emplace(rsc.url);
Response res;
res.noContent = true;
return res;
};

std::unordered_map<double, Tiles> 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;
}
}

0 comments on commit 9127299

Please sign in to comment.