The add_lines method allows you to draw custom line overlays on a map using
geographic coordinates, without requiring a GeoJSON file.
It is suitable for routes, paths, tracks, and any linear geometry generated at runtime.
require "gd/gis"
CITY = [-74.05, 40.70, -73.95, 40.80]
map = GD::GIS::Map.new(
bbox: CITY,
zoom: 10,
basemap: :carto_light,
width: 800,
height: 800
)
map.style = GD::GIS::Style.load("light")
Lines are defined as an array of line strings, where each line is an array of
[lng, lat] coordinate pairs.
lines = [
[
[-74.02, 40.71],
[-74.00, 40.73],
[-73.98, 40.75]
]
]
[lng, lat] ordermap.add_lines(
lines,
stroke: [239, 68, 68],
width: 3
)
lines (required)Array of line strings defined by geographic coordinates.
strokestroke: [R, G, B]
Defines the line color.
widthwidth: 3
Line width in pixels.
map.render
map.save("output/lines.png")
add_lines does not rely on YAML styles.
[lng, lat] coordinates