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
# File 'lib/tilekit.rb', line 48

def initialize(bounding_box)
  @bounding_box = bounding_box

  # create transparent image canvas
  @canvas = Magick::Image.new(MapKit::TILE_SIZE, MapKit::TILE_SIZE) do |c|
    c.background_color= "Transparent"
  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



58
59
60
61
# File 'lib/tilekit.rb', line 58

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



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

def png
  @canvas.to_blob { |attrs| attrs.format = 'PNG' }
end