Class: Dotter::Dotter
- Inherits:
-
Object
- Object
- Dotter::Dotter
- Defined in:
- lib/dotter.rb
Overview
Dotter::Dotter allows to generate transparent image with dots representing points on map. This image can be used as a google maps tile.
Usage:
dotter = Dotter::Dotter.new(:dots => dots_array)
image = dotter.generate_image
image # Magick::Image instance containing transparent image with dots
A Dot can be any object that responds to :x and :y methods. If :colorize in options is set to true and dot responds to :dot_color method, dot will be drawn with this color (color can be anything that is acceptable as a color in RMagick, usually RGB value, ie: “#ff0000”. Dots are black by default)
x and y coordinates represents the actual place, where the dot will be placed on image. If you have latitude and longitude coordinates you must convert it first. It’s fairly easy with Dotter::Tile, which abstracts google maps tiles.
Instance Attribute Summary collapse
-
#colorize ⇒ Object
Returns the value of attribute colorize.
-
#dots ⇒ Object
Returns the value of attribute dots.
Instance Method Summary collapse
-
#colorize? ⇒ Boolean
Tells if dots can be colored.
-
#generate_image ⇒ Object
Generate transparent image with dots.
-
#initialize(opts = {}) ⇒ Dotter
constructor
Parameters options<Hash>::.
Constructor Details
#initialize(opts = {}) ⇒ Dotter
Parameters
- options<Hash>
-
Options
- :dots<Enumerable>
-
array of dots that should be displayed on the image
- :width<Fixnum>
-
tile width (default: 256)
- :height<Fixnum>
-
tile height (default: 256)
- :radius<Fixnym>
-
dot radius (default: 5)
- :colorize<Boolean>
-
if colorize is set to true and dot responds_to dot_color, dot is colored using that color. Otherwise it’s black (default: true)
30 31 32 33 34 35 36 37 |
# File 'lib/dotter.rb', line 30 def initialize(opts = {}) @dots = opts.delete(:dots) || [] @width = opts.delete(:width) || 256 @height = opts.delete(:height) || 256 @radius = opts.delete(:radius) || 5 colorize = opts.delete(:colorize) @colorize = colorize.nil? ? true : colorize end |
Instance Attribute Details
#colorize ⇒ Object
Returns the value of attribute colorize.
19 20 21 |
# File 'lib/dotter.rb', line 19 def colorize @colorize end |
#dots ⇒ Object
Returns the value of attribute dots.
19 20 21 |
# File 'lib/dotter.rb', line 19 def dots @dots end |
Instance Method Details
#colorize? ⇒ Boolean
Tells if dots can be colored. If yes, dotter colors dot with anything that is returned by dot_color method.
40 41 42 |
# File 'lib/dotter.rb', line 40 def colorize? @colorize end |
#generate_image ⇒ Object
Generate transparent image with dots
45 46 47 48 49 50 51 52 53 |
# File 'lib/dotter.rb', line 45 def generate_image image = Magick::Image.new(@width, @height) do self.background_color = "transparent" end draw_dots(image) image end |