Skip to content

Commit 27f2b23

Browse files
authored
Merge pull request #31 from gravitystorm/endless
Implement endless zoom ranges
2 parents 7941575 + 364f7f6 commit 27f2b23

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

.rubocop_todo.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-11-28 15:41:06 UTC using RuboCop version 1.81.7.
3+
# on 2025-12-01 11:50:08 UTC using RuboCop version 1.81.7.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -9,34 +9,34 @@
99
# Offense count: 4
1010
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1111
Metrics/AbcSize:
12-
Max: 49
12+
Max: 53
1313

1414
# Offense count: 2
1515
# Configuration parameters: CountComments, CountAsOne.
1616
Metrics/ClassLength:
17-
Max: 200
17+
Max: 206
1818

1919
# Offense count: 3
2020
# Configuration parameters: AllowedMethods, AllowedPatterns.
2121
Metrics/CyclomaticComplexity:
22-
Max: 17
22+
Max: 18
2323

2424
# Offense count: 4
2525
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
2626
Metrics/MethodLength:
27-
Max: 31
27+
Max: 35
2828

2929
# Offense count: 2
3030
# Configuration parameters: AllowedMethods, AllowedPatterns.
3131
Metrics/PerceivedComplexity:
32-
Max: 19
32+
Max: 21
3333

3434
# Offense count: 1
3535
Naming/AccessorMethodName:
3636
Exclude:
3737
- 'lib/glug/layer.rb'
3838

39-
# Offense count: 1
39+
# Offense count: 5
4040
# Configuration parameters: CountAsOne.
4141
RSpec/ExampleLength:
4242
Max: 53

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You create a layer like this:
8181

8282
The layer call begins with the layer id (`:water`) and then any additional layer-wide properties (source, source_layer, metadata, interactive). If no source is specified, the default will be used. If no source_layer is specified, the layer id will be used - so in this case, Glug would assume a source_layer of 'water'.
8383

84-
Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties.
84+
Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties. "Beginless" and "Endless" ranges (e.g. `..5` or `13..`) are supported.
8585

8686
### Style definitions
8787

lib/glug/layer.rb

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

254254
# Convert zoom level
255255
if (v = hash['zoom'])
256-
hash['minzoom'] = v.is_a?(Range) ? v.first : v
257-
hash['maxzoom'] = v.is_a?(Range) ? v.last : v
256+
if v.is_a?(Range)
257+
hash['minzoom'] = v.first unless v.begin.nil?
258+
hash['maxzoom'] = v.last unless v.end.nil?
259+
else
260+
hash['minzoom'] = hash['maxzoom'] = v
261+
end
258262
hash.delete('zoom')
259263
end
260264

spec/lib/glug/layer_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,33 @@
2525
expect(h['minzoom']).to be(1)
2626
expect(h['maxzoom']).to be(5)
2727
end
28+
29+
context 'with endless ranges' do
30+
it 'does not set a max zoom' do
31+
stylesheet = Glug::Stylesheet.new do
32+
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
33+
end
34+
l = described_class.new(stylesheet, { zoom: 1.. })
35+
l.line_width 1
36+
37+
h = l.to_hash
38+
expect(h).to have_key('minzoom')
39+
expect(h['minzoom']).to be(1)
40+
expect(h).not_to have_key('maxzoom')
41+
end
42+
43+
it 'does not set a min zoom' do
44+
stylesheet = Glug::Stylesheet.new do
45+
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
46+
end
47+
l = described_class.new(stylesheet, { zoom: ..5 })
48+
l.line_width 1
49+
50+
h = l.to_hash
51+
expect(h).not_to have_key('minzoom')
52+
expect(h).to have_key('maxzoom')
53+
expect(h['maxzoom']).to be(5)
54+
end
55+
end
2856
end
2957
end

0 commit comments

Comments
 (0)