Skip to content

Commit 7941575

Browse files
authored
Merge pull request #28 from gravitystorm/one_zoom
Fix a bug with single-zoom layers
2 parents 77f85c0 + f059467 commit 7941575

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ AllCops:
99

1010
Naming/MethodParameterName:
1111
AllowedNames: ['op', 'kv', 'k', 'id']
12+
RSpec/MultipleExpectations:
13+
Max: 3

lib/glug/layer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def to_hash
253253

254254
# Convert zoom level
255255
if (v = hash['zoom'])
256-
hash['minzoom'] = v.is_a?(Range) ? v.first : value
257-
hash['maxzoom'] = v.is_a?(Range) ? v.last : value
256+
hash['minzoom'] = v.is_a?(Range) ? v.first : v
257+
hash['maxzoom'] = v.is_a?(Range) ? v.last : v
258258
hash.delete('zoom')
259259
end
260260

spec/lib/glug/layer_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
describe Glug::Layer do
4+
describe 'zoom levels' do
5+
it 'treats an integer as both min and max' do
6+
stylesheet = Glug::Stylesheet.new do
7+
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
8+
end
9+
l = described_class.new(stylesheet, { zoom: 7 })
10+
l.line_width 1
11+
12+
h = l.to_hash
13+
expect(h['minzoom']).to be(7)
14+
expect(h['maxzoom']).to be(7)
15+
end
16+
17+
it 'splits a range into min and max' do
18+
stylesheet = Glug::Stylesheet.new do
19+
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
20+
end
21+
l = described_class.new(stylesheet, { zoom: 1..5 })
22+
l.line_width 1
23+
24+
h = l.to_hash
25+
expect(h['minzoom']).to be(1)
26+
expect(h['maxzoom']).to be(5)
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)