maplibre-gl-raster 0.14.8 → 0.14.10
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,18 +18151,35 @@ function deriveLayerName(source) {
|
|
|
18151
18151
|
}
|
|
18152
18152
|
//#endregion
|
|
18153
18153
|
//#region src/lib/state/CogTilerEngine.ts
|
|
18154
|
+
/** Resample histogram buckets by their covered interval, preserving the total.
|
|
18155
|
+
* Point-mapping a short histogram leaves artificial empty gaps between bars. */
|
|
18156
|
+
function resampleHistogram(counts, targetBins = 128) {
|
|
18157
|
+
const output = new Array(targetBins).fill(0);
|
|
18158
|
+
if (counts.length === 0) return output;
|
|
18159
|
+
if (counts.length === targetBins) return counts.slice();
|
|
18160
|
+
const sourceWidth = 1 / counts.length;
|
|
18161
|
+
const targetWidth = 1 / targetBins;
|
|
18162
|
+
for (let source = 0; source < counts.length; source++) {
|
|
18163
|
+
const count = counts[source] ?? 0;
|
|
18164
|
+
if (!Number.isFinite(count) || count === 0) continue;
|
|
18165
|
+
const sourceStart = source * sourceWidth;
|
|
18166
|
+
const sourceEnd = (source + 1) * sourceWidth;
|
|
18167
|
+
const firstTarget = Math.floor(sourceStart * targetBins);
|
|
18168
|
+
const lastTarget = Math.min(targetBins - 1, Math.ceil(sourceEnd * targetBins) - 1);
|
|
18169
|
+
for (let target = firstTarget; target <= lastTarget; target++) {
|
|
18170
|
+
const overlap = Math.max(0, Math.min(sourceEnd, (target + 1) * targetWidth) - Math.max(sourceStart, target * targetWidth));
|
|
18171
|
+
output[target] += count * (overlap / sourceWidth);
|
|
18172
|
+
}
|
|
18173
|
+
}
|
|
18174
|
+
return output;
|
|
18175
|
+
}
|
|
18154
18176
|
/** Convert cog-tiler's TiTiler-style statistics into the panel's 128-bin shape. */
|
|
18155
18177
|
function fromCogStatistics(raw) {
|
|
18156
18178
|
const perBand = /* @__PURE__ */ new Map();
|
|
18157
18179
|
for (const [key, stats] of Object.entries(raw)) {
|
|
18158
18180
|
const band = Number(key.replace(/^b/, ""));
|
|
18159
18181
|
if (!Number.isInteger(band) || !Number.isFinite(stats.min) || !Number.isFinite(stats.max)) continue;
|
|
18160
|
-
const histogram =
|
|
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
|
-
}
|
|
18182
|
+
const histogram = resampleHistogram(stats.histogram?.[0] ?? []);
|
|
18166
18183
|
perBand.set(band, {
|
|
18167
18184
|
min: stats.min,
|
|
18168
18185
|
max: stats.max,
|
|
@@ -18316,7 +18333,8 @@ var CogTilerEngine = class {
|
|
|
18316
18333
|
_applied = /* @__PURE__ */ new Map();
|
|
18317
18334
|
/** Monotonic tile-URL version per layer, bumped to refetch on settings edits. */
|
|
18318
18335
|
_versions = /* @__PURE__ */ new Map();
|
|
18319
|
-
|
|
18336
|
+
_onStyleReady = null;
|
|
18337
|
+
_onStyleLoading = null;
|
|
18320
18338
|
/** Latches true once the style has loaded. After that, `isStyleLoaded()` may
|
|
18321
18339
|
* dip false again while sources load - which must NOT re-gate later syncs, or
|
|
18322
18340
|
* stats-driven re-renders would be lost. */
|
|
@@ -18358,9 +18376,14 @@ var CogTilerEngine = class {
|
|
|
18358
18376
|
/** Tears the engine down: removes its layers, the protocol, and all caches. */
|
|
18359
18377
|
destroy() {
|
|
18360
18378
|
this._destroyed = true;
|
|
18361
|
-
if (this.
|
|
18362
|
-
this._map.off("styledata", this.
|
|
18363
|
-
this.
|
|
18379
|
+
if (this._onStyleReady) {
|
|
18380
|
+
this._map.off("styledata", this._onStyleReady);
|
|
18381
|
+
this._map.off("style.load", this._onStyleReady);
|
|
18382
|
+
this._onStyleReady = null;
|
|
18383
|
+
}
|
|
18384
|
+
if (this._onStyleLoading) {
|
|
18385
|
+
this._map.off("styledataloading", this._onStyleLoading);
|
|
18386
|
+
this._onStyleLoading = null;
|
|
18364
18387
|
}
|
|
18365
18388
|
this.clear();
|
|
18366
18389
|
if (this._protocolRegistered) {
|
|
@@ -18373,25 +18396,33 @@ var CogTilerEngine = class {
|
|
|
18373
18396
|
this._assetSources.clear();
|
|
18374
18397
|
this._versions.clear();
|
|
18375
18398
|
}
|
|
18376
|
-
/** Reconciles the map with {@link _layers}
|
|
18377
|
-
*
|
|
18399
|
+
/** Reconciles the map with {@link _layers}. COGs open as soon as the wasm
|
|
18400
|
+
* module is ready so their bounds are available even while the map style is
|
|
18401
|
+
* loading; only MapLibre source/layer mutations wait for the style. */
|
|
18378
18402
|
_apply() {
|
|
18379
18403
|
if (this._destroyed) return;
|
|
18380
|
-
if (!this.
|
|
18381
|
-
this.
|
|
18404
|
+
if (!this._onStyleReady) {
|
|
18405
|
+
this._onStyleReady = () => {
|
|
18382
18406
|
if (this._destroyed || !this._map.isStyleLoaded()) return;
|
|
18383
18407
|
this._styleReady = true;
|
|
18384
18408
|
this._apply();
|
|
18385
18409
|
};
|
|
18386
|
-
this._map.on("styledata", this.
|
|
18410
|
+
this._map.on("styledata", this._onStyleReady);
|
|
18411
|
+
this._map.on("style.load", this._onStyleReady);
|
|
18412
|
+
this._onStyleLoading = () => {
|
|
18413
|
+
this._styleReady = false;
|
|
18414
|
+
};
|
|
18415
|
+
this._map.on("styledataloading", this._onStyleLoading);
|
|
18387
18416
|
}
|
|
18388
|
-
|
|
18389
|
-
|
|
18417
|
+
const desired = this._layers;
|
|
18418
|
+
const desiredIds = new Set(desired.map((layer) => layer.id));
|
|
18419
|
+
for (const id of this._sources.keys()) if (!desiredIds.has(id)) this._sources.delete(id);
|
|
18390
18420
|
const mod = this._ensureModule();
|
|
18391
18421
|
if (!mod) return;
|
|
18422
|
+
for (const layer of desired) if (!layer.assets) this._ensureSource(layer, mod);
|
|
18423
|
+
if (!this._styleReady) if (this._map.isStyleLoaded()) this._styleReady = true;
|
|
18424
|
+
else return;
|
|
18392
18425
|
this._ensureProtocol();
|
|
18393
|
-
const desired = this._layers;
|
|
18394
|
-
const desiredIds = new Set(desired.map((l) => l.id));
|
|
18395
18426
|
for (const id of [...this._registry.keys()]) if (!desiredIds.has(id)) this._dropLayer(id);
|
|
18396
18427
|
for (const layer of desired) this._applyLayer(layer, mod);
|
|
18397
18428
|
this._reorder(desired);
|
|
@@ -23193,4 +23224,4 @@ var RasterControl = class {
|
|
|
23193
23224
|
//#endregion
|
|
23194
23225
|
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 };
|
|
23195
23226
|
|
|
23196
|
-
//# sourceMappingURL=RasterControl-
|
|
23227
|
+
//# sourceMappingURL=RasterControl-CYfq9zmh.js.map
|