Class: GD::GIS::LinesLayer
- Inherits:
-
Object
- Object
- GD::GIS::LinesLayer
- Defined in:
- lib/gd/gis/layer_lines.rb
Overview
Renders collections of line geometries onto a GD image.
A LinesLayer draws simple line strings using a fixed stroke color and width. Coordinates are expected to be in
- longitude, latitude
-
order and are projected at render time.
Instance Attribute Summary collapse
-
#debug ⇒ Boolean
Enables debug rendering.
Instance Method Summary collapse
-
#initialize(lines, stroke:, width:) ⇒ LinesLayer
constructor
Creates a new lines layer.
-
#render!(img, projection) ⇒ void
Renders the lines onto the given image.
Constructor Details
#initialize(lines, stroke:, width:) ⇒ LinesLayer
Creates a new lines layer.
21 22 23 24 25 26 |
# File 'lib/gd/gis/layer_lines.rb', line 21 def initialize(lines, stroke:, width:) @lines = lines @stroke = stroke @width = width @debug = false end |
Instance Attribute Details
#debug ⇒ Boolean
Returns enables debug rendering.
13 14 15 |
# File 'lib/gd/gis/layer_lines.rb', line 13 def debug @debug end |
Instance Method Details
#render!(img, projection) ⇒ void
This method returns an undefined value.
Renders the lines onto the given image.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gd/gis/layer_lines.rb', line 36 def render!(img, projection) @lines.each do |line| raise "Invalid line: #{line.inspect}" unless valid_line?(line) pts = line.map do |lng, lat| projection.call(lng, lat) end color = @debug ? ColorHelpers.random_vivid : @stroke pts.each_cons(2) do |a, b| img.line( a[0], a[1], b[0], b[1], color, thickness: @width ) end end end |