Class: TileKit::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/tilekit.rb

Overview

this image class represents a tile in the google maps

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bounding_box) ⇒ Image

initialize the image with a (lat/lng) bounding box of the tile it represents



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tilekit.rb', line 48

def initialize(bounding_box)
  @bounding_box = bounding_box
  
  # create image canvas
  @canvas = GD2::Image.new(MapKit::TILE_SIZE, MapKit::TILE_SIZE)

  # make image transparent
  @canvas.save_alpha = true
  @canvas.draw do |context|
    context.color = GD2::Color::TRANSPARENT
    context.fill
  end
end

Instance Attribute Details

#bounding_boxObject (readonly)

Returns the value of attribute bounding_box.



44
45
46
# File 'lib/tilekit.rb', line 44

def bounding_box
  @bounding_box
end

#canvasObject (readonly)

Returns the value of attribute canvas.



44
45
46
# File 'lib/tilekit.rb', line 44

def canvas
  @canvas
end

Instance Method Details

#draw_icon(point, icon) ⇒ Object

draws passed icon at passed position



63
64
65
66
# File 'lib/tilekit.rb', line 63

def draw_icon(point, icon)
  x, y = point.pixel(@bounding_box)
  icon.draw(@canvas, x, y)
end

#pngObject

returns the png binary string of the image



69
70
71
# File 'lib/tilekit.rb', line 69

def png
  @canvas.png
end