summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-16 18:12:23 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-20 14:10:38 +0200
commit1e8f9c75ca3f11ee5d31b033744d99b616d6b946 (patch)
tree217420faaff56dd4a1da5ee56d8d29776da3c99e /test
parent34e783ed9cb52686ec61c67aa37054b3083ef66c (diff)
downloadqtlocation-mapboxgl-1e8f9c75ca3f11ee5d31b033744d99b616d6b946.tar.gz
[core] do not render layers that are outside their zoom range
So far, we didn't properly disable layers that are outside the zoom range. This means that we rendered layers that should not have been rendered, albeit we didn't make any attempt to load tiles for those layers. However, when zooming in/out, existing tiles might already have been loaded in the source which continued to be rendered. In most cases they weren't actually visible because either the matrices weren't updated, or the clip IDs weren't set so that they would be "rendered" off-screen and clipped completely. In any case, we did way too much work.
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/map/disabled_layers/first/expected.pngbin0 -> 103 bytes
-rw-r--r--test/fixtures/map/disabled_layers/second/expected.pngbin0 -> 103 bytes
-rw-r--r--test/fixtures/map/disabled_layers/tile.pngbin0 -> 103 bytes
-rw-r--r--test/map/map.cpp61
4 files changed, 61 insertions, 0 deletions
diff --git a/test/fixtures/map/disabled_layers/first/expected.png b/test/fixtures/map/disabled_layers/first/expected.png
new file mode 100644
index 0000000000..388180c6d1
--- /dev/null
+++ b/test/fixtures/map/disabled_layers/first/expected.png
Binary files differ
diff --git a/test/fixtures/map/disabled_layers/second/expected.png b/test/fixtures/map/disabled_layers/second/expected.png
new file mode 100644
index 0000000000..089ac0dde9
--- /dev/null
+++ b/test/fixtures/map/disabled_layers/second/expected.png
Binary files differ
diff --git a/test/fixtures/map/disabled_layers/tile.png b/test/fixtures/map/disabled_layers/tile.png
new file mode 100644
index 0000000000..089ac0dde9
--- /dev/null
+++ b/test/fixtures/map/disabled_layers/tile.png
Binary files differ
diff --git a/test/map/map.cpp b/test/map/map.cpp
index 6ecbc52e5f..0437296350 100644
--- a/test/map/map.cpp
+++ b/test/map/map.cpp
@@ -249,6 +249,67 @@ TEST(Map, RemoveLayer) {
test::checkImage("test/fixtures/map/remove_layer", test::render(map));
}
+TEST(Map, DisabledSources) {
+ MapTest test;
+
+ // Always load the same image tile for raster layers.
+ test.fileSource.response = [] (const Resource& res) -> optional<Response> {
+ if (res.url == "asset://tile.png") {
+ Response response;
+ response.data = std::make_shared<std::string>(
+ util::read_file("test/fixtures/map/disabled_layers/tile.png"));
+ return {std::move(response)};
+ }
+ return {};
+ };
+
+ Map map(test.view, test.fileSource, MapMode::Still);
+ map.setZoom(1);
+
+ // This stylesheet has two raster layers, one that starts at zoom 1, the other at zoom 0.
+ // We first render a map at zoom level 1, which should show both layers (both are "visible" due
+ // to an opacity of 0.5). Then, we are zooming back out to a zoom level of 0.5 and rerender.
+ // The "raster1" layer should not be visible anymore since it has minzoom 1, while "raster2"
+ // should still be there. Both layers have a distinct color through "raster-hue-rotate".
+ map.setStyleJSON(R"STYLE(
+{
+ "version": 8,
+ "name": "Test",
+ "sources": {
+ "raster": {
+ "type": "raster",
+ "tiles": [ "asset://tile.png" ],
+ "tileSize": 256
+ }
+ },
+ "layers": [{
+ "id": "background",
+ "type": "background",
+ "paint": {
+ "background-color": "white"
+ }
+ }, {
+ "id": "raster1",
+ "type": "raster",
+ "source": "raster",
+ "minzoom": 0
+ }, {
+ "id": "raster2",
+ "type": "raster",
+ "source": "raster",
+ "minzoom": 1,
+ "paint": {
+ "raster-hue-rotate": 180
+ }
+ }]
+}
+)STYLE");
+
+ test::checkImage("test/fixtures/map/disabled_layers/first", test::render(map));
+ map.setZoom(0.5);
+ test::checkImage("test/fixtures/map/disabled_layers/second", test::render(map));
+}
+
TEST(Map, Classes) {
MapTest test;