From 856aaaa2de05b875a51f4b728ccf85e76ed3d91c Mon Sep 17 00:00:00 2001 From: Benjamin Ramser Date: Mon, 4 Jul 2022 13:59:38 +0200 Subject: [PATCH] fix: filter by zoom level for min/max zoom 0 Prior to this, setting min_zoom=0 and max_zoom=0 would result in the layer being present across the entire zoom range. --- atlas/map.go | 2 +- atlas/map_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/atlas/map.go b/atlas/map.go index abb109190..2b635e5b4 100644 --- a/atlas/map.go +++ b/atlas/map.go @@ -145,7 +145,7 @@ func (m Map) FilterLayersByZoom(zoom uint) Map { var layers []Layer for i := range m.Layers { - if (m.Layers[i].MinZoom <= zoom || m.Layers[i].MinZoom == 0) && (m.Layers[i].MaxZoom >= zoom || m.Layers[i].MaxZoom == 0) { + if m.Layers[i].MinZoom <= zoom && m.Layers[i].MaxZoom >= zoom { layers = append(layers, m.Layers[i]) continue } diff --git a/atlas/map_test.go b/atlas/map_test.go index be889330b..0642a95f0 100644 --- a/atlas/map_test.go +++ b/atlas/map_test.go @@ -81,6 +81,58 @@ func TestMapFilterLayersByZoom(t *testing.T) { }, }, }, + { + atlasMap: atlas.Map{ + Layers: []atlas.Layer{ + { + Name: "layer1", + MinZoom: 0, + MaxZoom: 0, + }, + { + Name: "layer2", + MinZoom: 1, + MaxZoom: 5, + }, + }, + }, + zoom: 2, + expected: atlas.Map{ + Layers: []atlas.Layer{ + { + Name: "layer2", + MinZoom: 1, + MaxZoom: 5, + }, + }, + }, + }, + { + atlasMap: atlas.Map{ + Layers: []atlas.Layer{ + { + Name: "layer1", + MinZoom: 0, + MaxZoom: 0, + }, + { + Name: "layer2", + MinZoom: 1, + MaxZoom: 5, + }, + }, + }, + zoom: 0, + expected: atlas.Map{ + Layers: []atlas.Layer{ + { + Name: "layer1", + MinZoom: 0, + MaxZoom: 0, + }, + }, + }, + }, } for i, tc := range testcases {