feat(legend): continuous/graduated legends for vector layers (#258) - #262
Merged
Conversation
Vector legends (#118/#248) were categorical-only: a vector layer styled with a continuous interpolate/step ramp got no legend, while a raster with the same ramp got a colorbar. _hasLegend rejected continuous vectors, and _showLegend's colorbar branch sourced its gradient from colormap+rescale (TiTiler/raster-only concepts a vector has neither of). - deriveContinuousLegend() (pure, legend-helpers.js) reads gradient + value range back out of a layer's interpolate/step color expression, so the legend mirrors the map with no duplicate config - _hasLegend accepts continuous vectors when a colorbar is resolvable; _continuousVectorLegend resolves it (explicit legend_gradient/legend_range config wins, else derive from paint) - _showLegend gains a continuous-vector branch reusing the colorbar DOM, colors validated via _safeColorHint - plumb legend_range/legend_gradient config through dataset-catalog - docs: continuous legend config + auto-derivation Tests: deriveContinuousLegend unit coverage; _hasLegend + _showLegend continuous-vector render + explicit-override paths.
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
# Conflicts: # app/map-manager.js
cboettig
added a commit
that referenced
this pull request
Jun 20, 2026
This local Claude Code permission config (machine-specific absolute paths, a /tmp worktree path) was swept into #262 by a stray git add -A during conflict resolution. It's not meant for the shared repo.
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.
Fixes #258.
Problem
Vector legends (PR #248, issue #118, v3.13.0) are categorical-only. A vector layer styled with a continuous
interpolate/stepramp — a graduated choropleth — gets no legend, while a raster with the same kind of ramp gets a colorbar._hasLegendadmitted a vector only whenlegendType === 'categorical' && legendClasses.length > 0._showLegend's continuous branch sourced its gradient fromstate.colormap+state.rescale— TiTiler/raster-only concepts a vector layer doesn't have.Real impact (ca-30x30): 12 ACE richness layers + CalEnviroScreen are
["interpolate",["linear"],["get",<col>],…]ramps that render correctly but show no legend.Approach
The graduated paint expression already encodes the gradient and value range, so the primary path auto-derives the legend from
default_style— setlegend_type: "continuous"and nothing else is needed.app/legend-helpers.js(new, pure/tested):deriveContinuousLegend(paint)parsesfill/line/circle-colorinterpolate/stepexpressions into{ gradient, range }. Returns null for flat colors,match/categorical, or unparseable paint._hasLegendnow accepts continuous vectors when a colorbar is resolvable;_continuousVectorLegend(state)resolves it — explicitlegend_gradient/legend_rangeconfig wins, else derive from paint._showLegendgains a continuous-vector branch that reuses the existing.legend-colorbar/.legend-labelsDOM; colors are validated through_safeColorHint(same XSS guard as the categorical path).dataset-catalog.jsplumbs the optionallegend_range/legend_gradientoverrides (vector + versioned +getMapLayerConfigs).Categorical vectors and raster colorbars are unchanged.
Tests
deriveContinuousLegend: interpolate/step parsing, fill/line/circle keys, out-of-order stops, null cases (flat, match, empty, single-stop)._hasLegend: continuous eligible via derived paint and via explicit config; not eligible with nothing to source from._showLegend: renders a derived colorbar withlegend_labelaxis labels; explicitlegend_range/legend_gradientoverride the paint.Full suite green (317 tests).