maplibre-gl-raster 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -164,7 +164,10 @@ layer:
164
164
  ([cog-tiler-wasm](https://github.com/opengeos/cog-tiler-wasm)) wired to a
165
165
  MapLibre custom protocol. Tiles are rendered on the CPU and served as native
166
166
  MapLibre raster layers. The panel's settings (bands, rescale, colormap,
167
- curve, gamma, nodata, opacity) map directly onto its render parameters.
167
+ curve, gamma, nodata, opacity) map directly onto its render parameters. This
168
+ tiler ships a shorter colormap list than the deck.gl sprite, so while it is
169
+ active the panel's colormap picker narrows to the ramps it can actually draw
170
+ (a name it does not know renders black rather than falling back).
168
171
  - **`titiler`** - a server-side dynamic tiler
169
172
  ([TiTiler](https://developmentseed.org/titiler/)). Tiles are rendered by a
170
173
  remote TiTiler instance and drawn as native MapLibre raster layers, so
@@ -2753,13 +2753,23 @@ var ColormapPicker = class {
2753
2753
  constructor(options) {
2754
2754
  this._palette = options.palette ?? null;
2755
2755
  this._stats = options.stats ?? null;
2756
- const selectOptions = [...this._palette ? [{
2757
- value: PALETTE_COLORMAP,
2758
- label: "Image palette (default)"
2759
- }] : [], ...COLORMAP_OPTIONS.map((o) => ({
2756
+ const allowed = options.allowed;
2757
+ const named = COLORMAP_OPTIONS.filter((o) => !allowed || allowed.has(o.name)).map((o) => ({
2760
2758
  value: o.name,
2761
2759
  label: o.label
2762
- }))];
2760
+ }));
2761
+ const unsupported = allowed && options.value && options.value !== "palette" && !allowed.has(options.value) ? [{
2762
+ value: options.value,
2763
+ label: `${colormapDisplayName(options.value)} (not supported by this engine)`
2764
+ }] : [];
2765
+ const selectOptions = [
2766
+ ...this._palette ? [{
2767
+ value: PALETTE_COLORMAP,
2768
+ label: "Image palette (default)"
2769
+ }] : [],
2770
+ ...unsupported,
2771
+ ...named
2772
+ ];
2763
2773
  this._select = select(selectOptions, options.value, (next) => {
2764
2774
  this._updatePreview(next);
2765
2775
  options.onChange(next);
@@ -19056,6 +19066,36 @@ function classNames(classes) {
19056
19066
  }
19057
19067
  //#endregion
19058
19068
  //#region src/lib/state/CogTilerEngine.ts
19069
+ /**
19070
+ * The colormaps assumed renderable before the wasm module has loaded.
19071
+ *
19072
+ * This is only a starting guess: once the module is in memory the engine
19073
+ * reports its real set from `colormaps()` (see
19074
+ * {@link CogTilerEngine.supportedColormaps}), so a package that ships more
19075
+ * ramps widens the picker on its own with no change here. The conservative
19076
+ * subset below is what every published version has always known, so the picker
19077
+ * never offers a ramp the tiler cannot draw during that first moment.
19078
+ *
19079
+ * Rendering an unknown name is a soft failure, not a hard one: the tiler falls
19080
+ * back to its `gray` ramp (asserted upstream by
19081
+ * `colormap::tests::unknown_name_falls_back_to_gray`), so a mismatch looks like
19082
+ * a greyscale image rather than a blank tile.
19083
+ */
19084
+ var COG_TILER_COLORMAPS = [
19085
+ "viridis",
19086
+ "magma",
19087
+ "plasma",
19088
+ "inferno",
19089
+ "cividis",
19090
+ "turbo",
19091
+ "terrain",
19092
+ "blues",
19093
+ "greens",
19094
+ "reds",
19095
+ "rdylgn",
19096
+ "spectral",
19097
+ "gray"
19098
+ ];
19059
19099
  /** A blank tile: cog-tiler returns an empty buffer for tiles outside the COG. */
19060
19100
  var EMPTY_TILE = new Uint8Array(0);
19061
19101
  /** Upper bound on how many mosaic assets one tile will composite.
@@ -19169,6 +19209,23 @@ var CogTilerEngine = class {
19169
19209
  this._map = map;
19170
19210
  this._deps = deps;
19171
19211
  }
19212
+ /**
19213
+ * The colormap names this build of `cog-tiler-wasm` can actually render.
19214
+ *
19215
+ * Read from the module's own `colormaps()` once it has loaded, so upgrading
19216
+ * the package widens the picker without a change here; until then the
19217
+ * conservative {@link COG_TILER_COLORMAPS} baseline stands in. A module too
19218
+ * old to expose `colormaps()` also falls back to the baseline.
19219
+ */
19220
+ get supportedColormaps() {
19221
+ let names;
19222
+ try {
19223
+ names = this._module?.colormaps?.();
19224
+ } catch {
19225
+ names = void 0;
19226
+ }
19227
+ return new Set(names?.length ? names : COG_TILER_COLORMAPS);
19228
+ }
19172
19229
  /** Renders the given layers (in draw order, first = bottom), adding, updating,
19173
19230
  * reordering, and removing native MapLibre raster layers to match. */
19174
19231
  sync(layers) {
@@ -19240,7 +19297,9 @@ var CogTilerEngine = class {
19240
19297
  throw err;
19241
19298
  });
19242
19299
  this._modulePromise.then(() => {
19243
- if (!this._destroyed) this._apply();
19300
+ if (this._destroyed) return;
19301
+ this._apply();
19302
+ this._deps.onReady?.();
19244
19303
  }, () => {});
19245
19304
  }
19246
19305
  return null;
@@ -20400,6 +20459,26 @@ var LayerManager = class {
20400
20459
  return this._titilerEndpoint;
20401
20460
  }
20402
20461
  /**
20462
+ * The colormap names the active engine can actually render, or null when it
20463
+ * supports every colormap the panel offers.
20464
+ *
20465
+ * Only `cog-tiler-wasm` is limited: it knows a fixed set compiled into the
20466
+ * wasm, and renders an unknown name with its `gray` ramp rather than the
20467
+ * requested one — which reads as "the colormap was ignored". The panel
20468
+ * narrows its picker to this set so a user cannot pick a ramp that will not
20469
+ * draw as chosen. The deck.gl engine draws the full sprite, and TiTiler
20470
+ * resolves names server-side.
20471
+ *
20472
+ * The set comes from the loaded engine, not a hard-coded list, so a
20473
+ * `cog-tiler-wasm` release that adds ramps widens the picker with no change
20474
+ * here. Before the engine exists (or its module has loaded) the conservative
20475
+ * {@link COG_TILER_COLORMAPS} baseline applies.
20476
+ */
20477
+ get supportedColormaps() {
20478
+ if (this._engine !== "cog-tiler-wasm") return null;
20479
+ return this._cogEngine?.supportedColormaps ?? new Set(COG_TILER_COLORMAPS);
20480
+ }
20481
+ /**
20403
20482
  * Points the `titiler` engine at a different TiTiler instance. Empty input
20404
20483
  * restores the default endpoint. When the `titiler` engine is active, tiles
20405
20484
  * refetch from the new server immediately. A no-op when unchanged.
@@ -20902,7 +20981,8 @@ var LayerManager = class {
20902
20981
  if (!this._cogEngine) this._cogEngine = new CogTilerEngine(this._map, {
20903
20982
  loadModule: this._deps.loadCogTiler,
20904
20983
  onBounds: (id, bounds, zoomTo) => this._onCogBounds(id, bounds, zoomTo),
20905
- onError: (id, error) => this._onCogError(id, error)
20984
+ onError: (id, error) => this._onCogError(id, error),
20985
+ onReady: () => this._emit({ type: "rasterchange" })
20906
20986
  });
20907
20987
  return this._cogEngine;
20908
20988
  }
@@ -22472,15 +22552,22 @@ var SettingsSection = class {
22472
22552
  /** Collapsed/expanded state of the Rescale section, preserved across the
22473
22553
  * full re-renders this section performs on every structural change. */
22474
22554
  _rescaleOpen = true;
22555
+ /** Colormaps the active engine can draw, or null for all. Re-read on every
22556
+ * render, so switching engines renarrows the picker. */
22557
+ _getAllowedColormaps;
22475
22558
  /**
22476
22559
  * Creates the section.
22477
22560
  *
22478
22561
  * @param getLayer - Returns the currently selected layer (or null)
22479
22562
  * @param setState - Applies a state patch to the selected layer
22563
+ * @param inspect - Pixel-inspect hooks for the Inspect button
22564
+ * @param getAllowedColormaps - Returns the colormaps the active engine can
22565
+ * render, or null when every colormap is drawable
22480
22566
  */
22481
- constructor(getLayer, setState, inspect) {
22567
+ constructor(getLayer, setState, inspect, getAllowedColormaps) {
22482
22568
  this._getLayer = getLayer;
22483
22569
  this._inspect = inspect ?? null;
22570
+ this._getAllowedColormaps = getAllowedColormaps ?? (() => null);
22484
22571
  this._setState = (patch) => {
22485
22572
  this._applying = true;
22486
22573
  try {
@@ -22578,6 +22665,7 @@ var SettingsSection = class {
22578
22665
  value: state.colormap,
22579
22666
  palette: mode === "single" ? layer.palette : null,
22580
22667
  stats: mode === "single" ? statsForBand(layer.autoStats, state.bands[0] ?? 1) : null,
22668
+ allowed: this._getAllowedColormaps(),
22581
22669
  onChange: (name) => {
22582
22670
  this._setState({ colormap: name });
22583
22671
  this.render();
@@ -23083,7 +23171,7 @@ var PanelUI = class {
23083
23171
  }, (patch) => {
23084
23172
  const id = this._manager.selectedId;
23085
23173
  if (id) this._manager.setState(id, patch);
23086
- }, options?.inspect);
23174
+ }, options?.inspect, () => this._manager.supportedColormaps);
23087
23175
  this._root = el("div", { className: "mlr-panel" }, engine.el, addData.el, this._layerList.el, this._settings.el);
23088
23176
  container.appendChild(this._root);
23089
23177
  const onListChange = () => this._renderList();
@@ -24049,4 +24137,4 @@ var RasterControl = class {
24049
24137
  //#endregion
24050
24138
  export { DEFAULT_TITILER_ENDPOINT as A, COLORMAP_ROW_COUNT as B, throttle as C, loadVrt as D, isVrtUrl as E, loadColormapSprite as F, statsForBand as G, colormaps_default as H, sampleColormapStops as I, mergeAutoStats as J, MAX_SAMPLE_TILES as K, COLORMAP_DISPLAY_NAMES as L, isMosaicJsonUrl as M, PALETTE_COLORMAP as N, parseVrt as O, isKnownColormap as P, createResilientEpsgResolver as Q, COLORMAP_NAMES as R, generateId as S, isVrtFile as T, DEFAULT_INDEX_RANGE as U, colormapDisplayName as V, autoRangeFor as W, percentileFromHistogram as X, mergeBandStats as Y, readBandNames as Z, parseMosaic as _, NORMALIZED_DIFFERENCE_INDICES as a, debounce as b, readPixelValues as c, MAX_MOSAIC_ASSETS as d, MosaicUnsupportedError as f, mosaicMinZoom as g, mosaicInitialView as h, CUSTOM_NORMALIZED_DIFFERENCE as i, TITILER_TMS as j, loadGeoTIFF as k, DEFAULT_ENGINE as l, loadMosaic as m, Colorbar as n, guessBandForRole as o, assetUrlToHttps as p, computeAutoStats as q, CUSTOM_INDEX_ID as r, indexById as s, RasterControl as t, LayerManager as u, clamp as v, VrtUnsupportedError as w, formatNumericValue as x, classNames as y, COLORMAP_OPTIONS as z };
24051
24139
 
24052
- //# sourceMappingURL=RasterControl-Cv3yZ90Z.js.map
24140
+ //# sourceMappingURL=RasterControl-BDDduhO9.js.map