Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
A legend is there to say what the map's symbols mean, but a line or polygon swatch ignores most of the symbol the map draws. In a layout's legend (swatch in crates/render/src/layout.rs), and in the Layers and Symbology panes (patch_sized in crates/ui-egui/src/panes.rs):
- Lines: one stroke in the symbol's colour. The stacked strokes of
layer.lineStrokesare left out: casings, offsets, dashes, and markers along the line (shapes, characters, hash marks, images). - Polygons: a plain box in the fill colour. The stacked fills of
layer.fillLayersare left out: hatches, dot patterns (images too), gradients, shapeburst fills, and a class's own fills. - Layout only: a see-through layer and a layer with a reference scale come out opaque and at their plain width. Point swatches already follow both (Layout legend: point symbols don't match the map #1441).
To reproduce:
layer.addDataText={"fileName":"Roads.geojson","text":"{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[0,0],[1,0.5]]}}]}"}
layer.lineStrokes={"layer":"Roads","strokes":[{"color":"#5A3A1E","width":7},{"color":"#F28C28","width":5},{"color":"#FFFFFF","width":1,"dash":[4,2]}]}
layout.new={"name":"Legend","page":"a4","orientation":"landscape"}
The map frame shows a cased road with a dashed centre line; the legend shows a thin single line.
Proposed solution
Draw each swatch through the map's own drawing code, so the legend can't drift from the map again: the swatch's short line or box goes through the same stacked-stroke and stacked-fill paths as a feature, in the swatch's box.
What you see:
- In a layout's legend, each line or polygon swatch shows the strokes, markers, dashes, patterns and gradients the map draws, a class's own ones included, with the layer's transparency and reference scale.
- A stroke wider than the row, or shifted by its offset, is cut at the swatch's box; the row keeps its height.
- A PDF or SVG export keeps a marker's image once, as on the map (feat(render): a picture marker is one image in a PDF or SVG; a line's markers and shifted strokes show from off the view (#2266) #2477).
- Layers without stacked strokes or fills, opaque and without a reference scale, look exactly as before.
- Existing layouts change: a layout with such layers shows the new swatches the next time it is opened or exported.
Planned pull requests, each with its own tests:
- Layout legend:
LegendEntrycarries a class's own fills; line and polygon swatches drawn by the map's paths, composited with the layer's opacity, cut to their box. In the layout view, PNG, PDF and SVG exports. - Layers and Symbology panes:
patch_sizeddraws the same at row size, reusing the editors' previews (strokes, markers, fills).
Estimated scope
Medium: a broader feature that is feasible in a reasonable timeframe
About 330 lines for part 1 and 200 for part 2.
Alternatives considered
- Growing the row to hold a wide stroke, as a large point symbol does: rows of different heights for lines that differ only in casing width; cutting at the box keeps the legend even.
- A swatch drawer of its own for legends: it would drift from the map again, as the point swatches did before Layout legend: point symbols don't match the map #1441.
Activity
jgregoriorincon commentedon Nov 20, 2026
I'm working on this, starting with part 1 (the layout legend).
feat(render): layout legend swatches draw a layer's stacked strokes a…
fix(render): build with main's legend rows, cut swatches with a swatc…
feat(render): layout legend swatches draw a layer's stacked strokes a…
docs: the Layers and Symbology panes draw stacked strokes and fills (o…
fix(ui): pane patches draw a mark's outline and skip a line of no wid…
fix(ui): a mark's outline counts in its patch's fit, and a line's has…
feat(ui): Layers and Symbology patches draw a layer's stacked strokes…