Skip to content

Change colormaps at runtime through core, custom ramps included - #661

Open
slesaad wants to merge 5 commits into
feature/655-vector-rangesfrom
feature/654-vector-colormap-simple
Open

slesaad wants to merge 5 commits into
feature/655-vector-rangesfrom
feature/654-vector-colormap-simple

Conversation

@slesaad

@slesaad slesaad commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Closes #654

Size

Files Added Removed
Code 23 585 281
Tests 12 584 307
Docs 1 3 0

236 of the removed code lines are the Layer Manager's own colormap fetching and caching, now done by core.

Stacked on #658, which draws style.colorBy from config. This PR adds custom ramps and runtime changes. Review #658 first; this diff is against its branch.

What

  • Custom ramps. A colormap colorBy can name a ramp that only the layer's TiTiler defines, such as naqfc_pm25. The ramp is looked up once and shared by every layer that names it. Until it arrives, the layer paints its fixed colour, then it is restyled. A failed lookup is retried after the service's failure window.
  • Core owns colormaps for raster and vector layers alike, through three bus calls:
    • layers:getColormaps: the ramp names a layer can be offered. This is its TiTiler's list, or the bundled ramps (forward and _r) when it has no TiTiler or the list can't be read.
    • layers:getColormapColors: one ramp's colours, from the same lookup the map paints with.
    • layers:setColormap: applies a ramp and/or range change. A raster takes it into its runtime colormap fields. A colorBy layer takes it into its setting and is restyled in place, without refetching data, on deck.gl and Leaflet GeoJSON. A layer that can't take the change is refused.
  • The Layer Manager only asks. Its ramp picker, reverse toggle and min/max inputs now appear for colormap colorBy layers. It no longer fetches TiTiler itself or edits layer config. Reverse is offered when the layer's ramp list includes <name>_r.
  • Deployment default. With a deployment-wide TiTiler (General Options: deployment-wide default TiTiler URL #662), its custom ramps are available to vector layers without setting titilerUrl on each one.

Reading order

  1. src/essence/Basics/Colormaps/:
    • titilerColormaps.ts adds the cached ramp-list fetch.
    • resolveColormapColors.ts adds listColormaps, plus lookupColormapColors, which answers null for an unknown ramp instead of the fallback.
  2. src/essence/Basics/Layers_/ColorBy.ts: loadColormapRamp and the cache of service-defined ramps.
  3. src/essence/Basics/Layers_/Layers_.js:
    • restyleColorByLayer and ensureColorByRamp handle late ramps.
    • setLayerColormap and the three providers.
    • cogCapabilitiesFor now answers for colorBy layers.
  4. Repainting without a refetch:
    • src/essence/Basics/Map_/Map_.js: restyleLayer.
    • DeckGLHelpers.ts: restyleDeckLayer, used by DeckGLAdapter.updateLayer.
    • Leaflet's style function re-reads the setting.
  5. Layer Manager:
    • adapters/handlers.ts sends layers:setColormap.
    • lib/utils/colormapSource.ts is what the picker's hooks read; MMGISLayerManagerAdapter.tsx installs it from the bus calls.
    • The old TiTiler fetch and cache in colormapCache.ts are removed.

Notes

  • The ramp cache is keyed by name. If two tiling services define a custom ramp with the same name, layers share whichever definition loads first.
  • On Leaflet, points drawn as icons keep their colour when restyled. Circle markers and paths update.
  • Picker swatches show the bundled ramp where one exists, because that is what core paints vector layers and legends with. It matches TiTiler's version within 1/255 per channel.

Testing

  • npx vitest run passes: 225 files and 3854 tests. npx tsc --noEmit -p . is clean.
  • On Air4US (deck.gl) with the EIC TiTiler as the deployment default:
    • PM₂.₅ lists 214 ramps.
    • Setting naqfc_pm25 loads it from the service and repaints the points: value 1 goes from jet navy to rgba(175,254,176), matching the service's table.
    • Setting viridis_r with 3–5 repaints the points and updates the legend.
    • Before the re-cut, the picker applied a ramp and the reverse toggle through the UI. The Layer Manager code is unchanged since.
    • On the O₃ raster, layers:setColormap with magma_r and 1–9 updates its runtime colormap fields and its legend.

@slesaad
slesaad added this pull request to stack #678 November 20, 2026 21:58
@slesaad
slesaad force-pushed the feature/654-vector-colormap-simple branch from 18c1157 to 7a73d3e Compare November 20, 2026 22:04
@slesaad slesaad changed the title Vector layers: colour by a colormap Change colormaps at runtime through core, custom ramps included Nov 20, 2026
A colorBy colormap can name a ramp only the layer's TiTiler defines; it is
looked up once, and the layer paints its fixed colour until it arrives.

Core answers three bus calls for raster and vector layers alike:
layers:getColormaps lists the ramps a layer can offer, layers:getColormapColors
returns one ramp's colours, and layers:setColormap applies a ramp or range
change. A colorBy layer is restyled in place without refetching its data, on
deck.gl and Leaflet GeoJSON.

The Layer Manager's ramp picker and handlers only ask core, so its own TiTiler
fetches, cache and config writes are gone.
@slesaad
slesaad force-pushed the feature/654-vector-colormap-simple branch from b55efa6 to d79ed3e Compare November 23, 2026 16:50
A colorBy colormap whose ramp is neither bundled nor supplied by the layer's tiling service paints no feature, but its legend fell back to a viridis gradient. The ramp loader now answers null for such a ramp, and the legend draws no gradient while still naming the ramp and its range, so the ramp picker can change it.
layers:setColormap accepts only a name from the layer's layers:getColormaps list, in any casing, so neither a typo nor an unlisted reversed form can leave a layer painting nothing. The whole change is refused, range included.
@slesaad
slesaad marked this pull request as ready for review November 23, 2026 19:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vector layers: colour by a colormap

1 participant