summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-26 17:26:15 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-10-27 16:15:36 -0700
commit91272992f3a7ca7baa124c3378f1c1e2b3e5bb76 (patch)
treef76b6293a302b3986dbf42a8e0b0f5975c31b677
parente7bfa7849e4ed7a80d27b63ac2f504660ecfb14b (diff)
downloadqtlocation-mapboxgl-91272992f3a7ca7baa124c3378f1c1e2b3e5bb76.tar.gz
[core] don't load tiles from sources that aren't used
-rw-r--r--src/mbgl/style/style.cpp9
-rw-r--r--test/map/map.test.cpp48
2 files changed, 54 insertions, 3 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index e1cbe56bc5..0605a66d80 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -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();
}
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<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;
+ }
+}