Skip to content

Commit

Permalink
fix: filter by zoom level for min/max zoom 0
Browse files Browse the repository at this point in the history
Prior to this, setting min_zoom=0 and max_zoom=0 would result
in the layer being present across the entire zoom range.
  • Loading branch information
iwpnd authored and gdey committed Aug 30, 2022
1 parent c3aeca0 commit a78880d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
52 changes: 52 additions & 0 deletions atlas/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a78880d

Please sign in to comment.