@openglobus/og 1.0.0-rc28 → 1.0.0-rc29

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/lib/Extent.d.ts CHANGED
@@ -81,6 +81,13 @@ export declare class Extent {
81
81
  * @return {Extent} Extent clone.
82
82
  */
83
83
  clone(): Extent;
84
+ /**
85
+ * Creates union of this extent and another extent.
86
+ * @public
87
+ * @param {Extent} extent - Other extent.
88
+ * @return {Extent} Union extent.
89
+ */
90
+ createUnion(extent: Extent): Extent;
84
91
  /**
85
92
  * Gets the center coordinate of the extent.
86
93
  * @public
@@ -3,7 +3,7 @@ import { Material } from "./Material";
3
3
  import { BaseTileMaterialLayer } from "./BaseTileMaterialLayer";
4
4
  import type { LayerEventsList } from "./Layer";
5
5
  import type { Segment } from "../segment/Segment";
6
- import { GeoTIFFReader, type IGeoTIFFLayerParams, type IGeoTIFFMetadata, type IGeoTIFFRenderOptions, type DecodedTileData } from "./geotiff";
6
+ import { type IGeoTIFFLayerParams, type IGeoTIFFMetadata, type IGeoTIFFReader, type IGeoTIFFRenderOptions, type IGeoTIFFSourceItem, type DecodedTileData } from "./geotiff";
7
7
  interface ICachedTile {
8
8
  image: ImageData;
9
9
  renderOptionsVersion: number;
@@ -20,7 +20,7 @@ type GeoTIFFEventsType = EventsHandler<GeoTIFFEventsList> & EventsHandler<LayerE
20
20
  */
21
21
  export declare class GeoTIFFLayer extends BaseTileMaterialLayer {
22
22
  events: GeoTIFFEventsType;
23
- protected _reader: GeoTIFFReader;
23
+ protected _reader: IGeoTIFFReader;
24
24
  protected _renderOptions: IGeoTIFFRenderOptions;
25
25
  protected _tileSize: number;
26
26
  protected _tileCache: Map<string, ICachedTile>;
@@ -37,9 +37,10 @@ export declare class GeoTIFFLayer extends BaseTileMaterialLayer {
37
37
  constructor(name: string | null, options?: IGeoTIFFLayerParams);
38
38
  static fromUrl(name: string, url: string, options?: IGeoTIFFLayerParams): Promise<GeoTIFFLayer>;
39
39
  static fromBlob(name: string, blob: Blob | File, options?: IGeoTIFFLayerParams): Promise<GeoTIFFLayer>;
40
+ static fromSources(name: string, sources: IGeoTIFFSourceItem[], options?: IGeoTIFFLayerParams): Promise<GeoTIFFLayer>;
40
41
  get instanceName(): string;
41
42
  get isIdle(): boolean;
42
- get reader(): GeoTIFFReader;
43
+ get reader(): IGeoTIFFReader;
43
44
  get metadata(): IGeoTIFFMetadata | null;
44
45
  get nodata(): number | null | undefined;
45
46
  set nodata(val: number | null | "nan" | "NaN" | undefined);
@@ -58,6 +59,7 @@ export declare class GeoTIFFLayer extends BaseTileMaterialLayer {
58
59
  redraw(): void;
59
60
  private _reapplyRenderOptions;
60
61
  private _initSource;
62
+ private _initSources;
61
63
  private _normalizeRenderOptions;
62
64
  private _updateReadSamples;
63
65
  loadMaterial(material: Material, forceLoading?: boolean): void;
@@ -1,10 +1,10 @@
1
1
  import { GeoTIFF, GeoTIFFImage, Pool } from "geotiff";
2
2
  import { Extent } from "../../Extent";
3
3
  import { Proj } from "../../proj/Proj";
4
- import type { DecodedTileData, IGeoTIFFLayerParams, IGeoTIFFMetadata, ProjFunc } from "./types";
4
+ import type { DecodedTileData, GeoTIFFSource, IGeoTIFFMetadata, IGeoTIFFReader, IGeoTIFFReaderParams, IGeoTIFFRenderOptions, ProjFunc } from "./types";
5
5
  export declare function parseCrsCode(crs?: number | string): number | undefined;
6
- export declare class GeoTIFFReader {
7
- options: IGeoTIFFLayerParams;
6
+ export declare class GeoTIFFReader implements IGeoTIFFReader {
7
+ options: IGeoTIFFReaderParams;
8
8
  source: GeoTIFF | null;
9
9
  images: GeoTIFFImage[];
10
10
  workerPool: Pool | null;
@@ -16,13 +16,19 @@ export declare class GeoTIFFReader {
16
16
  reverseY: boolean;
17
17
  requestLevels: number[];
18
18
  isReady: boolean;
19
- private _ownsWorkerPool;
19
+ private _poolHandle;
20
20
  private _projHelper;
21
- constructor(options?: IGeoTIFFLayerParams);
21
+ private _activeReads;
22
+ private _destroyed;
23
+ constructor(options?: IGeoTIFFReaderParams);
22
24
  /**
23
25
  * Initializes and parses the GeoTIFF source and its overview pyramid.
24
26
  */
25
- init(src: string | Blob | File | ArrayBuffer): Promise<IGeoTIFFMetadata>;
27
+ init(src: GeoTIFFSource): Promise<IGeoTIFFMetadata>;
28
+ /**
29
+ * Applies rendering options that affect decoding: nodata masking and the resampling method.
30
+ */
31
+ setRenderOptions(renderOptions: IGeoTIFFRenderOptions): void;
26
32
  /**
27
33
  * Reads raster data for a tile and warps it into the tile grid.
28
34
  *
@@ -35,7 +41,8 @@ export declare class GeoTIFFReader {
35
41
  * @param readSamples - Band indexes to read.
36
42
  * @param segmentProj - Projection of the segment the tile belongs to, EPSG:3857 by default.
37
43
  */
38
- readTileRasters(tileExtentLonLat: Extent, _zoomLevel: number, tileSize?: number, readSamples?: number[], segmentProj?: Proj): Promise<DecodedTileData | null>;
44
+ readTileRasters(tileExtentLonLat: Extent, zoomLevel: number, tileSize?: number, readSamples?: number[], segmentProj?: Proj): Promise<DecodedTileData | null>;
45
+ private _readTileRasters;
39
46
  /**
40
47
  * Projects a lon/lat point into the raster coordinates, normalized to 0..1.
41
48
  */
@@ -63,6 +70,7 @@ export declare class GeoTIFFReader {
63
70
  private _getEffectiveNoData;
64
71
  private _getFillValue;
65
72
  private _checkIfReversed;
73
+ private _releasePool;
66
74
  /**
67
75
  * Cleans up worker pool and cached images.
68
76
  */
@@ -0,0 +1,48 @@
1
+ import { Extent } from "../../Extent";
2
+ import type { Proj } from "../../proj/Proj";
3
+ import type { Pool } from "geotiff";
4
+ import { GeoTIFFReader } from "./GeoTIFFReader";
5
+ import type { DecodedTileData, IGeoTIFFMetadata, IGeoTIFFReader, IGeoTIFFReaderParams, IGeoTIFFRenderOptions, IGeoTIFFSourceItem } from "./types";
6
+ /**
7
+ * MultiGeoTIFFReader manages multiple Cloud-Optimized GeoTIFF (COG) sources,
8
+ * enabling multi-band compositing (e.g. RGB or NDVI across separate band files)
9
+ * and spatial mosaics (merging adjacent COG tiles into a unified layer).
10
+ */
11
+ export declare class MultiGeoTIFFReader implements IGeoTIFFReader {
12
+ options: IGeoTIFFReaderParams;
13
+ childReaders: GeoTIFFReader[];
14
+ sources: IGeoTIFFSourceItem[];
15
+ metadata: IGeoTIFFMetadata | null;
16
+ extentWgs84: Extent;
17
+ isReady: boolean;
18
+ crsCode: number;
19
+ workerPool: Pool | null;
20
+ private _poolHandle;
21
+ private _bandMappings;
22
+ private _activeReads;
23
+ private _destroyed;
24
+ constructor(options?: IGeoTIFFReaderParams);
25
+ /**
26
+ * Initializes all GeoTIFF sources and builds unified extent and band mappings.
27
+ */
28
+ init(sources?: IGeoTIFFSourceItem[]): Promise<IGeoTIFFMetadata>;
29
+ /**
30
+ * Union of the native bounding boxes of all sources, valid only when they share a CRS.
31
+ */
32
+ private _unionNativeBBox;
33
+ /**
34
+ * Applies rendering options to this reader and to every child reader.
35
+ */
36
+ setRenderOptions(renderOptions: IGeoTIFFRenderOptions): void;
37
+ /**
38
+ * Reads rasters for a tile from the underlying GeoTIFF sources.
39
+ */
40
+ readTileRasters(tileExtentLonLat: Extent, zoomLevel: number, tileSize?: number, readSamples?: number[], segmentProj?: Proj): Promise<DecodedTileData | null>;
41
+ private _readMultiBandTileRasters;
42
+ private _readMosaicTileRasters;
43
+ private _releasePool;
44
+ /**
45
+ * Cleans up child readers and shared worker pool.
46
+ */
47
+ destroy(): void;
48
+ }
@@ -1,3 +1,5 @@
1
1
  export * from "./types";
2
2
  export * from "./ColorScale";
3
3
  export * from "./GeoTIFFReader";
4
+ export * from "./MultiGeoTIFFReader";
5
+ export * from "./workerPool";
@@ -1,7 +1,18 @@
1
1
  import type { IBaseTileMaterialLayerParams } from "../BaseTileMaterialLayer";
2
2
  import type { Pool, TypedArray } from "geotiff";
3
+ import type { Extent } from "../../Extent";
4
+ import type { Proj } from "../../proj/Proj";
3
5
  export type ColorScaleName = "viridis" | "inferno" | "turbo" | "magma" | "plasma" | "rainbow" | "jet" | "hsv" | "hot" | "cool" | "spring" | "summer" | "autumn" | "winter" | "bone" | "copper" | "greys" | "ylgnbu" | "greens" | "ylorrd" | "bluered" | "rdbu" | "picnic" | "portland" | "blackbody" | "earth" | "electric" | "redblue" | "coolwarm";
4
6
  export type ColorStop = [stopValue: number, color: string];
7
+ /**
8
+ * GeoTIFF data source: a remote URL or a local binary.
9
+ */
10
+ export type GeoTIFFSource = string | Blob | File | ArrayBuffer;
11
+ export type NoDataValue = number | null | "nan" | "NaN";
12
+ export interface IBandStats {
13
+ min: number;
14
+ max: number;
15
+ }
5
16
  export interface ISingleBandRenderOptions {
6
17
  /** Band index (1-indexed), defaults to 1 */
7
18
  band?: number;
@@ -34,9 +45,9 @@ export interface IMultiBandRenderOptions {
34
45
  }
35
46
  export interface IGeoTIFFRenderOptions {
36
47
  /** NoData value (if not set, read from TIFF metadata). Set to null or NaN to disable nodata masking. */
37
- nodata?: number | null | "nan" | "NaN";
48
+ nodata?: NoDataValue;
38
49
  /** Alias for nodata */
39
- noData?: number | null | "nan" | "NaN";
50
+ noData?: NoDataValue;
40
51
  /** Treat 3-band/multi-band TIFF directly as RGB */
41
52
  convertToRGB?: boolean;
42
53
  /** Multi-band channel configuration */
@@ -62,27 +73,49 @@ export type ProjFunc = (code: number) => {
62
73
  project: (pos: number[]) => number[];
63
74
  unproject: (pos: number[]) => number[];
64
75
  } | undefined;
65
- export interface IGeoTIFFLayerParams extends IBaseTileMaterialLayerParams {
76
+ /**
77
+ * Options shared by a single GeoTIFF source and by the reader that opens it.
78
+ */
79
+ export interface IGeoTIFFSourceCommon {
66
80
  /** Remote URL or local Blob/File/ArrayBuffer */
67
- src?: string | Blob | File | ArrayBuffer;
81
+ src?: GeoTIFFSource;
68
82
  /** Alias for src when passing a URL */
69
83
  url?: string;
70
84
  /** Custom NoData value. Set to null or NaN to disable nodata masking. */
71
- nodata?: number | null | "nan" | "NaN";
85
+ nodata?: NoDataValue;
86
+ /** Alias for nodata */
87
+ noData?: NoDataValue;
72
88
  /** Optional CRS code or definition, e.g. 2193 or "EPSG:2193" */
73
89
  crs?: number | string;
74
- /** Alias for nodata */
75
- noData?: number | null | "nan" | "NaN";
76
- /** Rendering and band options */
77
- renderOptions?: IGeoTIFFRenderOptions;
78
90
  /** HTTP request options for geotiff.js range requests */
79
91
  requestOptions?: IGeoTIFFRequestOptions;
80
- /** Custom geotiff Worker Pool instance */
92
+ }
93
+ export interface IGeoTIFFSourceItem extends IGeoTIFFSourceCommon {
94
+ /** Specific band indexes to read from this source (1-indexed). Defaults to all bands. */
95
+ bands?: number[];
96
+ /** Min value for this source's bands (used for contrast stretching) */
97
+ min?: number;
98
+ /** Max value for this source's bands (used for contrast stretching) */
99
+ max?: number;
100
+ }
101
+ /**
102
+ * Options used by a GeoTIFF reader.
103
+ */
104
+ export interface IGeoTIFFReaderParams extends IGeoTIFFSourceCommon {
105
+ /** Multiple GeoTIFF/COG sources (like OpenLayers) */
106
+ sources?: IGeoTIFFSourceItem[];
107
+ /** When true, merges multiple sources spatially as a mosaic instead of stacking bands */
108
+ mosaic?: boolean;
109
+ /** Rendering and band options */
110
+ renderOptions?: IGeoTIFFRenderOptions;
111
+ /** Custom geotiff Worker Pool instance. It belongs to the caller and is never destroyed by a reader. */
81
112
  geotiffWorkerPool?: Pool;
82
- /** Number of Web Workers for decompression (default: navigator.hardwareConcurrency || 2) */
113
+ /** Number of decompression workers. Uses a shared pool if not set. */
83
114
  workerPoolSize?: number;
84
115
  /** Custom projection mapping function for non-standard CRS */
85
116
  projFunc?: ProjFunc;
117
+ }
118
+ export interface IGeoTIFFLayerParams extends IBaseTileMaterialLayerParams, IGeoTIFFReaderParams {
86
119
  /** Output tile size (default: 256) */
87
120
  tileSize?: number;
88
121
  /** Maximum tile cache size (default: 500) */
@@ -90,6 +123,21 @@ export interface IGeoTIFFLayerParams extends IBaseTileMaterialLayerParams {
90
123
  /** Auto-calculate maximumLevel from COG overview count */
91
124
  useImageCountAsMaximumLevel?: boolean;
92
125
  }
126
+ export interface IGeoTIFFReader {
127
+ options: IGeoTIFFReaderParams;
128
+ metadata: IGeoTIFFMetadata | null;
129
+ extentWgs84: Extent;
130
+ crsCode: number;
131
+ isReady: boolean;
132
+ workerPool: Pool | null;
133
+ init(src?: GeoTIFFSource | IGeoTIFFSourceItem[]): Promise<IGeoTIFFMetadata>;
134
+ /**
135
+ * Applies rendering options that affect decoding, such as nodata masking and the resampling method.
136
+ */
137
+ setRenderOptions(renderOptions: IGeoTIFFRenderOptions): void;
138
+ readTileRasters(tileExtentLonLat: Extent, zoomLevel: number, tileSize?: number, readSamples?: number[], segmentProj?: Proj): Promise<DecodedTileData | null>;
139
+ destroy(): void;
140
+ }
93
141
  export interface IGeoTIFFMetadata {
94
142
  bbox: [number, number, number, number];
95
143
  crsCode: number;
@@ -99,10 +147,7 @@ export interface IGeoTIFFMetadata {
99
147
  noData: number | null;
100
148
  isTiled: boolean;
101
149
  overviewCount: number;
102
- bands: Record<number, {
103
- min: number;
104
- max: number;
105
- }>;
150
+ bands: Record<number, IBandStats | undefined>;
106
151
  }
107
152
  export interface DecodedTileData {
108
153
  rasters: TypedArray[];
@@ -0,0 +1,23 @@
1
+ import { Pool } from "geotiff";
2
+ import type { IGeoTIFFReaderParams } from "./types";
3
+ export declare const MAX_WORKER_POOL_SIZE = 4;
4
+ /**
5
+ * A shared worker pool.
6
+ * Call release() when done.
7
+ * The pool is destroyed when no one uses it anymore.
8
+ */
9
+ export interface IWorkerPoolHandle {
10
+ pool: Pool | null;
11
+ release(): void;
12
+ }
13
+ export declare function defaultWorkerPoolSize(): number;
14
+ /**
15
+ * Gets a worker pool for a GeoTIFF reader.
16
+ *
17
+ * Uses the provided geotiffWorkerPool without destroying it.
18
+ * Creates a dedicated pool if workerPoolSize is set.
19
+ * Otherwise, shares a pool between readers.
20
+ *
21
+ * Returns null if workers are unavailable (decoding runs on the main thread).
22
+ */
23
+ export declare function acquireWorkerPool(options: IGeoTIFFReaderParams): IWorkerPoolHandle;