Skip to content

Legend

Shows symbology for the layers that are currently visible: single swatches, category lists and gradient bars, each shaped for its geometry (dot, line or square).

  • id: legend
  • Surfaces: side-panel

Place it

"sidePanelWidgets": [{ "widgetName": "legend" }]

Behavior

  • Only visible layers with kit symbology or a legend appear. Raster layers and Esri layers using the service's own styling have nothing for the legend to read, so they're skipped unless they set legend.
  • Layers with simple symbology get one swatch, shaped by geometryType and drawn at the symbology's opacity and strokeOpacity. A layer without geometryType (mixed geometry) gets a small dot, line and square side by side in its color.
  • Categorized and graduated layers (raw symbology with match or interpolate expressions) become a category list or a gradient bar.
  • A layer's symbology.description appears as a muted line under its name, e.g. "Annual passengers".
  • Order: layers with raw symbology or their own legend first, then points, lines and polygons, keeping your layer order within each.
  • A PMTiles layer that draws several source layers gets its own block after the other layers: the layer's name as a header, with its visible source layers indented below in draw order. Hidden source layers drop out, and the block disappears when none are visible.

Controlling what shows

  • Set legend on any layer or PMTiles source layer to choose its swatches (categories or a gradient), or to bring a raster or service-styled Esri layer into the legend. It wins over a raw symbology's legend.
  • Hide a layer from the legend, but keep it on the map, with "hideFromLegend": true. It works with any symbology.

The legend has no settings block of its own. Everything comes from your layers' symbology and legend fields.