Skip to content

Commit a15690b

Browse files
committed
Caught an issue where legend ticks disappeared when a second legend was toggled on.
1 parent e0845f2 commit a15690b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

plugins/core/tools/Legend/LegendTool.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,11 @@ function drawLegends(tools, _legend, layerUUID, display_name, opacity, shift) {
610610
let visibleLabels = legendEntries
611611

612612
// Calculate available width per label in horizontal mode.
613-
// Measure the actual rendered legend panel width instead of assuming a fixed size,
614-
// so labels and the gradient never overflow the panel (which clips them on the right).
615-
// Force a reflow by reading offsetWidth on the raw DOM node before measuring
616-
// jQuery .width() can return 0 if the browser hasn't laid out the element yet.
617-
const rawNode = legendContainer[0]
618-
void (rawNode && rawNode.offsetWidth) // trigger reflow
619-
const measuredWidth = Math.floor(legendContainer.width()) || 0
613+
// Measure from #LegendTool (already in the DOM) rather than legendContainer
614+
// (not yet appended), so the measured width is consistent on first render and
615+
// on subsequent legend toggles. Falls back to 240 if the panel isn't found.
616+
const panelNode = document.getElementById('LegendTool')
617+
const measuredWidth = panelNode ? Math.floor($(panelNode).width()) : 0
620618
const containerWidth = orientation === 'horizontal' ? (measuredWidth > 0 ? measuredWidth : 240) : 'auto'
621619

622620
// Consistent font size for horizontal labels (no per-legend shrinking)

0 commit comments

Comments
 (0)