feat(hex): zoom-reactive color legend for hex layers (#316) - #320
Merged
Conversation
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
Hex tile layers rendered no legend: they bypass registerLayer (which wires
the legend) and style with a per-res case/match paint that
deriveContinuousLegend can't parse.
Add a hex-specific legend path instead of bending the continuous deriver:
- addHexTileLayer stores valueStats + palette on the layer state, sets
legendType 'hex', and calls _showLegendIfVisible (as registerLayer does
for curated layers).
- _hexLegend derives {colors, range, res} from the fixed 3-stop PALETTES and
the value domain of the resolution currently on screen; _currentHexRes
samples the rendered features' res property (the server pyramid serves one
resolution per tile keyed off zoom) with a finest-res fallback.
- _showLegend renders a colorbar + min/max labels + an 'H3 resolution N'
caption. A single lazy moveend handler (_updateHexLegends) relabels visible
hex legends as the on-screen resolution changes (~7x/step scaling).
- removeHexTileLayer tears down the legend entry.
Covered by test/map-manager.hex-legend.test.js (jsdom, 9 tests).
cboettig
force-pushed
the
feat/hex-layer-legend
branch
from
July 14, 2026 18:30
01bda70 to
615d709
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #316.
Problem
Hex tile layers rendered no legend. Two independent blockers:
registerLayer(which wires the legend via_showLegendIfVisible), so the legend was never even invoked for them.deriveContinuousLegendonly parses a top-levelinterpolate/step; hex paint is['case', …, ['match', ['get','res'], …]], so it returnsnull.Change — a hex-specific legend path (not a bent continuous deriver)
addHexTileLayerstoresvalueStats+paletteon the layer state, setslegendType: 'hex', and calls_showLegendIfVisible()(mirroring whatregisterLayerdoes for curated layers)._hexLegend(state)derives{colors, range, res}from the fixed 3-stopPALETTES(imported fromhex-layer-helpers.js, the same source the map ramp uses) and the value domain of the resolution currently on screen._currentHexRes(state)determines that resolution by sampling the rendered features'resproperty (the server pyramid serves one resolution per tile keyed off zoom, so this is more honest than reproducing the server's zoom→res formula client-side), with a finest-resolution fallback for the moment right after add / for GeoJSON layers whose features carry nores._showLegendgets ahexbranch: colorbar + min/max labels + anH3 resolution Ncaption.moveendhandler (_updateHexLegends) relabels every visible hex legend as the on-screen resolution changes. This matters because the per-resdomain scales ~7×/step, so a static range would mismatch the colors at most zoom levels.removeHexTileLayertears down the legend entry.Design notes
PALETTESrather than re-parsing thecase/matchpaint — the gradient is[c0,c1,c2](min→max), matchingbuildFillColorExpression._fmtLegendValue).Testing
test/map-manager.hex-legend.test.js(jsdom, 9 tests):_hasLegendfor hex;_currentHexResdominant-res sampling + finest fallback;_hexLegendpalette+domain;_showLegendDOM (colorbar/labels/res note);_updateHexLegendsrelabel on zoom; removal cleanup; value formatting.map-manager.jsis browser-bound; visual check on a deployed app recommended (colorbar + label updates while zooming a hex layer).