Class: Tile
- Inherits:
-
Object
- Object
- Tile
- Defined in:
- lib/tile.rb
Instance Attribute Summary collapse
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#zoom ⇒ Object
readonly
Returns the value of attribute zoom.
Instance Method Summary collapse
- #create_coverage(cov_zoom) ⇒ Object
- #draw(dc, x, y) ⇒ Object
-
#initialize(col, row, zoom, cov_zoom) ⇒ Tile
constructor
A new instance of Tile.
- #load_image ⇒ Object
- #path ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(col, row, zoom, cov_zoom) ⇒ Tile
Returns a new instance of Tile.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tile.rb', line 6 def initialize(col, row, zoom, cov_zoom) @col = col @row = row @zoom = zoom if File.exist?(path) load_image else DownloadManager.enqueue(self) end create_coverage(cov_zoom) end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
4 5 6 |
# File 'lib/tile.rb', line 4 def col @col end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
4 5 6 |
# File 'lib/tile.rb', line 4 def row @row end |
#zoom ⇒ Object (readonly)
Returns the value of attribute zoom.
4 5 6 |
# File 'lib/tile.rb', line 4 def zoom @zoom end |
Instance Method Details
#create_coverage(cov_zoom) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tile.rb', line 18 def create_coverage(cov_zoom) if !cov_zoom @mask = nil else @mask = Wx::Bitmap.new(TILE_WIDTH, TILE_WIDTH) @mask.draw do |dc| dc.pen = Wx::TRANSPARENT_PEN dc.brush = Wx::WHITE_BRUSH dc.draw_rectangle(0, 0, TILE_WIDTH, TILE_WIDTH) draw_subtiles(dc, cov_zoom) end end end |
#draw(dc, x, y) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tile.rb', line 37 def draw(dc, x, y) dc.pen = Wx::TRANSPARENT_PEN dc.logical_function = Wx::COPY if @bitmap dc.draw_bitmap(@bitmap, x, y, false) else dc.brush = Wx::GREY_BRUSH dc.draw_rectangle(x, y, TILE_WIDTH, TILE_WIDTH) end if @mask dc.logical_function = Wx::AND dc.draw_bitmap(@mask, x, y, false) end end |
#load_image ⇒ Object
32 33 34 35 |
# File 'lib/tile.rb', line 32 def load_image image = Wx::Image.new(path, Wx::BITMAP_TYPE_PNG) @bitmap = Wx::Bitmap.from_image(image) end |
#path ⇒ Object
58 59 60 |
# File 'lib/tile.rb', line 58 def path "maps/GoogleMap_#{zoom}/#{col}_#{row}.mgm" end |
#url ⇒ Object
52 53 54 55 56 |
# File 'lib/tile.rb', line 52 def url server = (@col + 2 * @row) % 4 galileo = "Galileo"[0, (3 * @col + @row) % 8] "http://mt#{server}.google.com/vt/lyrs=m@115&hl=en&x=#{@col}&y=#{@row}&z=#{@zoom}&s=#{galileo}" end |