Sha256: 93d1d38e0d8c4c25111af819c8d3fb546a3775d469149204bca278966f79acf3

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

require 'open-uri'
require 'chunky_png'

module Smappy
  class Marker < Location
    DEFAULT_IMAGE = File.expand_path('../../../markers/information_marker.png', __FILE__)
    
    attr_accessor :image, :offset
    
    def initialize(latitude, longitude)
      @image  = DEFAULT_IMAGE
      @offset = [-(width / 2),  -height].map(&:to_i)
      
      super
    end
    
    def width
      marker_image.width
    end
    
    def height
      marker_image.height
    end
    
    def position_on_map(map)
      x, y = super
      
      [x + offset[0], y + offset[1]]
    end
    
    # UNTESTED:
    def marker_image
      @marker_image ||= ChunkyPNG::Image.from_datastream(
        ChunkyPNG::Datastream.from_io(open(image))
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smappy-0.0.3 lib/smappy/marker.rb