Class: Tiletanic::TileSchemes::BasicTiling
- Inherits:
-
Object
- Object
- Tiletanic::TileSchemes::BasicTiling
show all
- Defined in:
- lib/tiletanic/tileschemes.rb
Constant Summary
collapse
- QUADKEY_PATTERN =
/\A[0-3]+\z/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(xmin, ymin, xmax, ymax) ⇒ BasicTiling
Returns a new instance of BasicTiling.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/tiletanic/tileschemes.rb', line 10
def initialize(xmin, ymin, xmax, ymax)
raise ArgumentError, 'xmax must be greater than xmin' unless xmax > xmin
raise ArgumentError, 'ymax must be greater than ymin' unless ymax > ymin
@functional_bounds = CoordsBBox.new(
xmin: Float(xmin),
ymin: Float(ymin),
xmax: Float(xmax),
ymax: Float(ymax)
)
@bounds = CoordsBBox.new(
xmin: Float(xmin),
ymin: Float(ymin),
xmax: Float(xmax),
ymax: Float(ymax)
)
end
|
Instance Attribute Details
#bounds ⇒ Object
Returns the value of attribute bounds.
8
9
10
|
# File 'lib/tiletanic/tileschemes.rb', line 8
def bounds
@bounds
end
|
Instance Method Details
#bbox(*tile) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/tiletanic/tileschemes.rb', line 49
def bbox(*tile)
upper_left = ul(*tile)
bottom_right = br(*tile)
CoordsBBox.new(
xmin: upper_left.x,
ymin: bottom_right.y,
xmax: bottom_right.x,
ymax: upper_left.y
)
end
|
#children(*tile) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/tiletanic/tileschemes.rb', line 42
def children(*tile)
x, y, z = (*tile)
[[0, 0], [1, 0], [0, 1], [1, 1]].map do |delta_x, delta_y|
Tile.new(x: (2 * x) + delta_x, y: (2 * y) + delta_y, z: z + 1)
end
end
|
#parent(*tile) ⇒ Object
37
38
39
40
|
# File 'lib/tiletanic/tileschemes.rb', line 37
def parent(*tile)
x, y, z = (*tile)
Tile.new(x: x / 2, y: y / 2, z: z - 1)
end
|
#quadkey(*tile) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/tiletanic/tileschemes.rb', line 61
def quadkey(*tile)
x, y, z = (*tile)
return '' if z.zero?
z.downto(1).map do |zoom|
digit = 0
mask = 1 << (zoom - 1)
digit += 1 if x.anybits?(mask)
digit += 2 if y.anybits?(mask)
digit
end.join
end
|
#quadkey_to_tile(quadkey) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/tiletanic/tileschemes.rb', line 74
def quadkey_to_tile(quadkey)
raise ArgumentError, 'Input quadkey is invalid.' unless QUADKEY_PATTERN.match?(quadkey)
x = 0
y = 0
quadkey.reverse.each_char.with_index do |digit, index|
mask = 1 << index
case digit
when '1'
x |= mask
when '2'
y |= mask
when '3'
x |= mask
y |= mask
end
end
Tile.new(x: x, y: y, z: quadkey.length)
end
|
#tile(xcoord, ycoord, zoom) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/tiletanic/tileschemes.rb', line 28
def tile(xcoord, ycoord, zoom)
zoom = Integer(zoom)
Tile.new(
x: x_index(Float(xcoord), zoom),
y: y_index(Float(ycoord), zoom),
z: zoom
)
end
|