Class: Smappy::Marker

Inherits:
Location show all
Defined in:
lib/smappy/marker.rb

Constant Summary collapse

DEFAULT_IMAGE =
File.expand_path('../../../markers/marker.png', __FILE__)

Instance Attribute Summary collapse

Attributes inherited from Location

#latitude, #longitude

Instance Method Summary collapse

Methods inherited from Location

#position_on_tile, #to_tile

Constructor Details

#initialize(latitude, longitude) ⇒ Marker

Returns a new instance of Marker.



10
11
12
13
14
15
# File 'lib/smappy/marker.rb', line 10

def initialize(latitude, longitude)
  @image  = DEFAULT_IMAGE
  @offset = [-(width / 2),  -height].map(&:to_i)
  
  super
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



8
9
10
# File 'lib/smappy/marker.rb', line 8

def image
  @image
end

#offsetObject

Returns the value of attribute offset.



8
9
10
# File 'lib/smappy/marker.rb', line 8

def offset
  @offset
end

Instance Method Details

#heightObject



21
22
23
# File 'lib/smappy/marker.rb', line 21

def height
  marker_image.height
end

#marker_imageObject

UNTESTED:



32
33
34
35
36
# File 'lib/smappy/marker.rb', line 32

def marker_image
  @marker_image ||= ChunkyPNG::Image.from_datastream(
    ChunkyPNG::Datastream.from_io(open(image))
  )
end

#position_on_map(map) ⇒ Object



25
26
27
28
29
# File 'lib/smappy/marker.rb', line 25

def position_on_map(map)
  x, y = super
  
  [x + offset[0], y + offset[1]]
end

#widthObject



17
18
19
# File 'lib/smappy/marker.rb', line 17

def width
  marker_image.width
end