@gisatcz/deckgl-geolib 2.5.0-dev.1 → 2.5.0-dev.2

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/dist/cjs/index.js CHANGED
@@ -4878,7 +4878,7 @@ const DefaultGeoImageOptions = {
4878
4878
  planarConfig: undefined,
4879
4879
  // --- Mesh generation (terrain only) ---
4880
4880
  tesselator: 'martini',
4881
- terrainColor: [133, 133, 133, 255],
4881
+ terrainColor: [200, 200, 200, 255],
4882
4882
  terrainSkirtHeight: 100,
4883
4883
  // Default fallback for invalid/nodata elevations. Should be configured based on the dataset's actual range.
4884
4884
  terrainMinValue: 0,
@@ -5617,6 +5617,22 @@ class BitmapGenerator {
5617
5617
  * Key: colorScale config + range, Value: pre-computed RGBA LUT
5618
5618
  */
5619
5619
  static _swissColorLUTCache = new Map();
5620
+ /**
5621
+ * Cache for 8-bit (256-entry) color LUTs.
5622
+ * Shared process-wide across all tiles and datasets when options are fixed (i.e. !useAutoRange).
5623
+ * Key: serialised coloring options, Value: pre-computed 256×RGBA LUT
5624
+ */
5625
+ static _8bitLUTCache = new Map();
5626
+ /**
5627
+ * Cache for float/16-bit (1024-entry) heatmap LUTs.
5628
+ * Shared process-wide across all tiles and datasets when !useAutoRange.
5629
+ * Key: serialised coloring options + range, Value: pre-computed 1024×RGBA LUT
5630
+ */
5631
+ static _floatLUTCache = new Map();
5632
+ /** Build a cache key that captures all options affecting LUT colour output. */
5633
+ static getLUTCacheKey(options, rangeMin, rangeMax, optAlpha) {
5634
+ return `${rangeMin}_${rangeMax}_${optAlpha}_${JSON.stringify(options.colorScale)}_${options.useSingleColor}_${JSON.stringify(options.color)}_${options.useColorClasses}_${JSON.stringify(options.colorClasses)}_${options.useColorsBasedOnValues}_${JSON.stringify(options.colorsBasedOnValues)}_${options.useHeatMap}_${options.clipLow ?? ''}_${options.clipHigh ?? ''}_${JSON.stringify(options.clippedColor)}_${JSON.stringify(options.nullColor)}_${JSON.stringify(options.unidentifiedColor)}`;
5635
+ }
5620
5636
  /**
5621
5637
  * Main entry point: Generates an ImageBitmap from raw raster data.
5622
5638
  */
@@ -5797,17 +5813,25 @@ class BitmapGenerator {
5797
5813
  return colorsArray;
5798
5814
  }
5799
5815
  // 2. 8-BIT COMPREHENSIVE LUT
5800
- // Single-band 8-bit (grayscale or indexed): use LUT for fast mapping
5816
+ // Single-band 8-bit (grayscale or indexed): use LUT for fast mapping.
5817
+ // The LUT covers all 256 possible values and is fixed for a given set of coloring options,
5818
+ // so cache it across tiles (skip cache only when useAutoRange recomputes the range per tile).
5801
5819
  if (is8Bit && !options.useDataForOpacity) {
5802
- const lut = new Uint8ClampedArray(256 * 4);
5803
- for (let i = 0; i < 256; i++) {
5804
- if ((options.clipLow != null && i <= options.clipLow) ||
5805
- (options.clipHigh != null && i >= options.clipHigh)) {
5806
- lut.set(options.clippedColor, i * 4);
5807
- }
5808
- else {
5809
- lut.set(this.calculateSingleColor(i, colorScale, options, optAlpha), i * 4);
5820
+ const cacheKey = !options.useAutoRange ? this.getLUTCacheKey(options, rangeMin, rangeMax, optAlpha) : null;
5821
+ let lut = cacheKey ? (this._8bitLUTCache.get(cacheKey) ?? null) : null;
5822
+ if (!lut) {
5823
+ lut = new Uint8ClampedArray(256 * 4);
5824
+ for (let i = 0; i < 256; i++) {
5825
+ if ((options.clipLow != null && i <= options.clipLow) ||
5826
+ (options.clipHigh != null && i >= options.clipHigh)) {
5827
+ lut.set(options.clippedColor, i * 4);
5828
+ }
5829
+ else {
5830
+ lut.set(this.calculateSingleColor(i, colorScale, options, optAlpha), i * 4);
5831
+ }
5810
5832
  }
5833
+ if (cacheKey)
5834
+ this._8bitLUTCache.set(cacheKey, lut);
5811
5835
  }
5812
5836
  for (let i = 0, sampleIndex = (options.useChannelIndex ?? 0); i < arrayLength; i += 4, sampleIndex += samplesPerPixel) {
5813
5837
  const lutIdx = primaryBuffer[sampleIndex] * 4;
@@ -5819,23 +5843,32 @@ class BitmapGenerator {
5819
5843
  return colorsArray;
5820
5844
  }
5821
5845
  // 3. FLOAT / 16-BIT LUT (HEATMAP ONLY)
5822
- if (isFloatOrWide && options.useHeatMap && !options.useDataForOpacity) {
5846
+ // Guard: only activate when heatmap is the highest-priority active mode.
5847
+ // If a more specific mode (useSingleColor, useColorClasses, useColorsBasedOnValues) is set,
5848
+ // fall through to the general loop so calculateSingleColor can honour the priority chain.
5849
+ if (isFloatOrWide && options.useHeatMap && !options.useSingleColor && !options.useColorClasses && !options.useColorsBasedOnValues && !options.useDataForOpacity) {
5823
5850
  const LUT_SIZE = 1024;
5824
- const lut = new Uint8ClampedArray(LUT_SIZE * 4);
5825
5851
  const rangeSpan = (rangeMax - rangeMin) || 1;
5826
- for (let i = 0; i < LUT_SIZE; i++) {
5827
- const domainVal = rangeMin + (i / (LUT_SIZE - 1)) * rangeSpan;
5828
- if ((options.clipLow != null && domainVal <= options.clipLow) ||
5829
- (options.clipHigh != null && domainVal >= options.clipHigh)) {
5830
- lut.set(options.clippedColor, i * 4);
5831
- }
5832
- else {
5833
- const rgb = colorScale(domainVal).rgb();
5834
- lut[i * 4] = rgb[0];
5835
- lut[i * 4 + 1] = rgb[1];
5836
- lut[i * 4 + 2] = rgb[2];
5837
- lut[i * 4 + 3] = optAlpha;
5852
+ const cacheKey = !options.useAutoRange ? this.getLUTCacheKey(options, rangeMin, rangeMax, optAlpha) : null;
5853
+ let lut = cacheKey ? (this._floatLUTCache.get(cacheKey) ?? null) : null;
5854
+ if (!lut) {
5855
+ lut = new Uint8ClampedArray(LUT_SIZE * 4);
5856
+ for (let i = 0; i < LUT_SIZE; i++) {
5857
+ const domainVal = rangeMin + (i / (LUT_SIZE - 1)) * rangeSpan;
5858
+ if ((options.clipLow != null && domainVal <= options.clipLow) ||
5859
+ (options.clipHigh != null && domainVal >= options.clipHigh)) {
5860
+ lut.set(options.clippedColor, i * 4);
5861
+ }
5862
+ else {
5863
+ const rgb = colorScale(domainVal).rgb();
5864
+ lut[i * 4] = rgb[0];
5865
+ lut[i * 4 + 1] = rgb[1];
5866
+ lut[i * 4 + 2] = rgb[2];
5867
+ lut[i * 4 + 3] = optAlpha;
5868
+ }
5838
5869
  }
5870
+ if (cacheKey)
5871
+ this._floatLUTCache.set(cacheKey, lut);
5839
5872
  }
5840
5873
  for (let i = 0, sampleIndex = (options.useChannelIndex ?? 0); i < arrayLength; i += 4, sampleIndex += samplesPerPixel) {
5841
5874
  const val = primaryBuffer[sampleIndex];
@@ -6512,7 +6545,7 @@ class GeoImage {
6512
6545
  this.data = data;
6513
6546
  }
6514
6547
  async getMap(input, options, meshMaxError) {
6515
- const mergedOptions = { ...DefaultGeoImageOptions, ...options };
6548
+ const mergedOptions = GeoImage.resolveVisualizationMode({ ...DefaultGeoImageOptions, ...options }, options);
6516
6549
  switch (mergedOptions.type) {
6517
6550
  case 'image':
6518
6551
  return this.getBitmap(input, mergedOptions);
@@ -6522,6 +6555,56 @@ class GeoImage {
6522
6555
  return null;
6523
6556
  }
6524
6557
  }
6558
+ /**
6559
+ * Resolves the active visualization (coloring) mode after merging user options with defaults.
6560
+ *
6561
+ * Solves three key issues:
6562
+ *
6563
+ * 1. **Mutual exclusivity**: `DefaultGeoImageOptions` sets `useHeatMap: true`. If a user
6564
+ * explicitly enables a coloring mode without explicitly setting `useHeatMap: false`,
6565
+ * enforce that only the explicitly-enabled modes are active (all others forced to false).
6566
+ * This prevents the default `useHeatMap: true` from interfering with user-chosen modes.
6567
+ *
6568
+ * 2. **Bitmap default**: for `type === 'image'` with no user-specified coloring mode,
6569
+ * keep `useHeatMap: true` from defaults. This provides sensible data-driven visualization.
6570
+ *
6571
+ * 3. **Terrain default**: for `type === 'terrain'` with no user-specified coloring mode and
6572
+ * no kernel-texture mode (`useSwissRelief` / `useSlope` / `useHillshade`), enable
6573
+ * `useSingleColor` with `color = terrainColor`. This renders the mesh in the documented
6574
+ * default colour (grey) without a data-driven texture overlay. When a kernel mode IS
6575
+ * present but no coloring mode is specified, keep `useHeatMap: true` so the kernel output
6576
+ * is still colourised.
6577
+ */
6578
+ static resolveVisualizationMode(mergedOptions, userOptions) {
6579
+ const coloringModes = ['useSingleColor', 'useColorClasses', 'useColorsBasedOnValues', 'useHeatMap'];
6580
+ const userExplicitColoringModes = coloringModes.filter(m => userOptions[m] === true);
6581
+ const resolved = { ...mergedOptions };
6582
+ if (userExplicitColoringModes.length > 0) {
6583
+ // Enforce mutual exclusivity: disable all coloring modes, then enable only those
6584
+ // explicitly set by the user. This prevents the default useHeatMap from interfering.
6585
+ for (const mode of coloringModes) {
6586
+ resolved[mode] = false;
6587
+ }
6588
+ for (const mode of userExplicitColoringModes) {
6589
+ resolved[mode] = true;
6590
+ }
6591
+ }
6592
+ else if (mergedOptions.type === 'terrain') {
6593
+ // Terrain with no explicit coloring mode.
6594
+ const hasKernelMode = userOptions.useSwissRelief || userOptions.useSlope || userOptions.useHillshade;
6595
+ if (!hasKernelMode) {
6596
+ // No kernel mode: enable useSingleColor with terrainColor as the default.
6597
+ // This renders the mesh in the documented colour without a data-driven texture.
6598
+ resolved.useHeatMap = false;
6599
+ resolved.useSingleColor = true;
6600
+ resolved.color = mergedOptions.terrainColor;
6601
+ }
6602
+ // When a kernel mode is present without an explicit coloring mode, keep
6603
+ // useHeatMap: true from defaults so the kernel output is colourised.
6604
+ }
6605
+ // For 'image' with no explicit coloring mode: keep useHeatMap: true from DefaultGeoImageOptions.
6606
+ return resolved;
6607
+ }
6525
6608
  // GetHeightmap uses only "useChannel" and "multiplier" options
6526
6609
  async getHeightmap(input, options, meshMaxError) {
6527
6610
  let rasters = [];