maplibre-gl-raster 0.14.7 → 0.14.9

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.
@@ -18151,6 +18151,38 @@ function deriveLayerName(source) {
18151
18151
  }
18152
18152
  //#endregion
18153
18153
  //#region src/lib/state/CogTilerEngine.ts
18154
+ /** Convert cog-tiler's TiTiler-style statistics into the panel's 128-bin shape. */
18155
+ function fromCogStatistics(raw) {
18156
+ const perBand = /* @__PURE__ */ new Map();
18157
+ for (const [key, stats] of Object.entries(raw)) {
18158
+ const band = Number(key.replace(/^b/, ""));
18159
+ if (!Number.isInteger(band) || !Number.isFinite(stats.min) || !Number.isFinite(stats.max)) continue;
18160
+ const histogram = new Array(128).fill(0);
18161
+ const counts = stats.histogram?.[0] ?? [];
18162
+ for (let i = 0; i < counts.length; i++) {
18163
+ const target = Math.min(127, Math.floor((i + .5) / counts.length * 128));
18164
+ histogram[target] += counts[i] ?? 0;
18165
+ }
18166
+ perBand.set(band, {
18167
+ min: stats.min,
18168
+ max: stats.max,
18169
+ histogram
18170
+ });
18171
+ }
18172
+ const values = [...perBand.values()];
18173
+ if (values.length === 0) return {
18174
+ perBand: null,
18175
+ global: null
18176
+ };
18177
+ return {
18178
+ perBand,
18179
+ global: {
18180
+ min: values.reduce((sum, s) => sum + s.min, 0) / values.length,
18181
+ max: values.reduce((sum, s) => sum + s.max, 0) / values.length,
18182
+ histogram: values[0].histogram.map((_, i) => values.reduce((sum, s) => sum + (s.histogram[i] ?? 0), 0))
18183
+ }
18184
+ };
18185
+ }
18154
18186
  /**
18155
18187
  * The colormaps assumed renderable before the wasm module has loaded.
18156
18188
  *
@@ -18284,7 +18316,8 @@ var CogTilerEngine = class {
18284
18316
  _applied = /* @__PURE__ */ new Map();
18285
18317
  /** Monotonic tile-URL version per layer, bumped to refetch on settings edits. */
18286
18318
  _versions = /* @__PURE__ */ new Map();
18287
- _onStyleData = null;
18319
+ _onStyleReady = null;
18320
+ _onStyleLoading = null;
18288
18321
  /** Latches true once the style has loaded. After that, `isStyleLoaded()` may
18289
18322
  * dip false again while sources load - which must NOT re-gate later syncs, or
18290
18323
  * stats-driven re-renders would be lost. */
@@ -18326,9 +18359,14 @@ var CogTilerEngine = class {
18326
18359
  /** Tears the engine down: removes its layers, the protocol, and all caches. */
18327
18360
  destroy() {
18328
18361
  this._destroyed = true;
18329
- if (this._onStyleData) {
18330
- this._map.off("styledata", this._onStyleData);
18331
- this._onStyleData = null;
18362
+ if (this._onStyleReady) {
18363
+ this._map.off("styledata", this._onStyleReady);
18364
+ this._map.off("style.load", this._onStyleReady);
18365
+ this._onStyleReady = null;
18366
+ }
18367
+ if (this._onStyleLoading) {
18368
+ this._map.off("styledataloading", this._onStyleLoading);
18369
+ this._onStyleLoading = null;
18332
18370
  }
18333
18371
  this.clear();
18334
18372
  if (this._protocolRegistered) {
@@ -18341,25 +18379,33 @@ var CogTilerEngine = class {
18341
18379
  this._assetSources.clear();
18342
18380
  this._versions.clear();
18343
18381
  }
18344
- /** Reconciles the map with {@link _layers}, deferring until the style is
18345
- * loaded and the wasm module is ready. */
18382
+ /** Reconciles the map with {@link _layers}. COGs open as soon as the wasm
18383
+ * module is ready so their bounds are available even while the map style is
18384
+ * loading; only MapLibre source/layer mutations wait for the style. */
18346
18385
  _apply() {
18347
18386
  if (this._destroyed) return;
18348
- if (!this._onStyleData) {
18349
- this._onStyleData = () => {
18387
+ if (!this._onStyleReady) {
18388
+ this._onStyleReady = () => {
18350
18389
  if (this._destroyed || !this._map.isStyleLoaded()) return;
18351
18390
  this._styleReady = true;
18352
18391
  this._apply();
18353
18392
  };
18354
- this._map.on("styledata", this._onStyleData);
18393
+ this._map.on("styledata", this._onStyleReady);
18394
+ this._map.on("style.load", this._onStyleReady);
18395
+ this._onStyleLoading = () => {
18396
+ this._styleReady = false;
18397
+ };
18398
+ this._map.on("styledataloading", this._onStyleLoading);
18355
18399
  }
18356
- if (!this._styleReady) if (this._map.isStyleLoaded()) this._styleReady = true;
18357
- else return;
18400
+ const desired = this._layers;
18401
+ const desiredIds = new Set(desired.map((layer) => layer.id));
18402
+ for (const id of this._sources.keys()) if (!desiredIds.has(id)) this._sources.delete(id);
18358
18403
  const mod = this._ensureModule();
18359
18404
  if (!mod) return;
18405
+ for (const layer of desired) if (!layer.assets) this._ensureSource(layer, mod);
18406
+ if (!this._styleReady) if (this._map.isStyleLoaded()) this._styleReady = true;
18407
+ else return;
18360
18408
  this._ensureProtocol();
18361
- const desired = this._layers;
18362
- const desiredIds = new Set(desired.map((l) => l.id));
18363
18409
  for (const id of [...this._registry.keys()]) if (!desiredIds.has(id)) this._dropLayer(id);
18364
18410
  for (const layer of desired) this._applyLayer(layer, mod);
18365
18411
  this._reorder(desired);
@@ -18556,6 +18602,10 @@ var CogTilerEngine = class {
18556
18602
  east: b[2],
18557
18603
  north: b[3]
18558
18604
  }, layer.zoomTo);
18605
+ if (typeof source.statistics === "function") source.statistics().then((stats) => {
18606
+ if (this._destroyed || this._sources.get(layer.id) !== entry) return;
18607
+ this._deps.onStats?.(layer.id, fromCogStatistics(stats));
18608
+ }, () => {});
18559
18609
  this._apply();
18560
18610
  }, (err) => {
18561
18611
  if (this._destroyed || this._sources.get(layer.id) !== entry) return;
@@ -19961,6 +20011,16 @@ var LayerManager = class {
19961
20011
  if (!this._cogEngine) this._cogEngine = new CogTilerEngine(this._map, {
19962
20012
  loadModule: this._deps.loadCogTiler,
19963
20013
  onBounds: (id, bounds, zoomTo) => this._onCogBounds(id, bounds, zoomTo),
20014
+ onStats: (id, stats) => {
20015
+ const layer = this.getLayer(id);
20016
+ if (!layer || this._engine !== "cog-tiler-wasm") return;
20017
+ layer.autoStats = stats;
20018
+ this._rebuild();
20019
+ this._emit({
20020
+ type: "rasterchange",
20021
+ layerId: id
20022
+ });
20023
+ },
19964
20024
  onError: (id, error) => this._onCogError(id, error),
19965
20025
  onReady: () => this._emit({ type: "rasterchange" })
19966
20026
  });
@@ -20111,6 +20171,7 @@ var LayerManager = class {
20111
20171
  */
20112
20172
  _computeStats(layer) {
20113
20173
  if (!layer.geotiff) return;
20174
+ if (this._engine === "cog-tiler-wasm") return;
20114
20175
  const signal = layer.abort.signal;
20115
20176
  const apply = (stats) => {
20116
20177
  if (signal.aborted || this._destroyed) return;
@@ -23146,4 +23207,4 @@ var RasterControl = class {
23146
23207
  //#endregion
23147
23208
  export { Photometric as $, 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, Compression 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, PlanarConfiguration as et, MosaicUnsupportedError as f, mosaicMinZoom as g, mosaicInitialView as h, CUSTOM_NORMALIZED_DIFFERENCE as i, createResilientEpsgResolver as it, TITILER_TMS as j, loadGeoTIFF as k, DEFAULT_ENGINE as l, loadMosaic as m, Colorbar as n, SampleFormat as nt, guessBandForRole as o, assetUrlToHttps as p, computeAutoStats as q, CUSTOM_INDEX_ID as r, TiffTag as rt, indexById as s, RasterControl as t, Predictor as tt, LayerManager as u, clamp as v, VrtUnsupportedError as w, formatNumericValue as x, classNames as y, COLORMAP_OPTIONS as z };
23148
23209
 
23149
- //# sourceMappingURL=RasterControl-GAiOG6eI.js.map
23210
+ //# sourceMappingURL=RasterControl-CPtuFlxg.js.map