Class: GD::GIS::Legend

Inherits:
Object
  • Object
show all
Defined in:
lib/gd/gis/legend.rb

Overview

Represents a map legend rendered as part of the final image.

A Legend provides visual context for map elements by associating colors or symbols with human-readable labels.

Legends are rendered server-side and embedded directly into the resulting map image, allowing the map to be self-explanatory without relying on external UI components.

A Legend is typically created and configured via Map#legend and rendered automatically during the map rendering pipeline.

Examples:

Creating a legend

map.legend do |l|
  l.add [76, 175, 80, 0], "Delivered"
  l.add [255, 193, 7, 0], "In transit"
  l.add [244, 67, 54, 0], "Delayed"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position: :bottom_right) ⇒ Legend

Returns a new instance of Legend.



28
29
30
31
# File 'lib/gd/gis/legend.rb', line 28

def initialize(position: :bottom_right)
  @position = position
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



26
27
28
# File 'lib/gd/gis/legend.rb', line 26

def items
  @items
end

#positionObject (readonly)

Returns the value of attribute position.



26
27
28
# File 'lib/gd/gis/legend.rb', line 26

def position
  @position
end

Instance Method Details

#add(color, label) ⇒ Object



33
34
35
# File 'lib/gd/gis/legend.rb', line 33

def add(color, label)
  @items << LegendItem.new(color, label)
end