The add_polygons method allows you to render custom polygon overlays directly on a map,
using geographic coordinates, without requiring a GeoJSON file.
It is useful for highlighting areas, regions, or dynamically generated shapes.
require "gd/gis"
PARIS = [2.25, 48.80, 2.42, 48.90]
map = GD::GIS::Map.new(
bbox: PARIS,
zoom: 10,
basemap: :carto_light
)
map.style = GD::GIS::Style.load("dark")
Polygons are defined as an array of polygons, where each polygon may contain one or more rings.
polygons = [
[
[
[-74.01, 40.70],
[-74.00, 40.70],
[-74.00, 40.71],
[-74.05, 41.02],
[-74.01, 40.71],
[-74.01, 40.70]
]
]
]
[lng, lat] ordermap.add_polygons(
polygons,
fill: [34, 197, 94, 180],
stroke: [16, 185, 129],
width: 2
)
polygons (required)Array of polygons defined by geographic coordinates.
fillfill: [R, G, B]
fill: [R, G, B, A]
Defines the polygon fill color. Alpha is optional.
strokestroke: [R, G, B]
Defines the polygon border color.
widthwidth: 2
Border width in pixels.
map.render
map.save("output/polygons.png")
add_polygons does not rely on YAML styles.
[lng, lat] coordinates