@developmentseed/deck.gl-geotiff 0.5.0-beta.1 → 0.5.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.
@@ -0,0 +1,301 @@
1
+ import type { CompositeLayerProps, Layer, LayersList, UpdateParameters } from "@deck.gl/core";
2
+ import { CompositeLayer } from "@deck.gl/core";
3
+ import type { _Tile2DHeader as Tile2DHeader, TileLayerProps, _TileLoadProps as TileLoadProps } from "@deck.gl/geo-layers";
4
+ import { TileLayer } from "@deck.gl/geo-layers";
5
+ import type { Corners, MultiTilesetDescriptor, RasterModule, UvTransform } from "@developmentseed/deck.gl-raster";
6
+ import type { DecoderPool, GeoTIFF } from "@developmentseed/geotiff";
7
+ import type { TileMatrixSet } from "@developmentseed/morecantile";
8
+ import type { EpsgResolver } from "@developmentseed/proj";
9
+ import { epsgResolver as defaultEpsgResolver } from "@developmentseed/proj";
10
+ import type { ReprojectionFns } from "@developmentseed/raster-reproject";
11
+ import type { Texture } from "@luma.gl/core";
12
+ /** Data returned per band from tile fetching. */
13
+ interface BandTileData {
14
+ /** GPU texture containing the band's raster data. */
15
+ texture: Texture;
16
+ /** UV transform for aligning this band's texture to the primary tile. */
17
+ uvTransform: UvTransform;
18
+ /** Width of the texture in pixels. */
19
+ width: number;
20
+ /** Height of the texture in pixels. */
21
+ height: number;
22
+ /** Byte length of the underlying texture data. */
23
+ byteLength: number;
24
+ }
25
+ /** Debug metadata for a secondary band, collected during tile fetching. */
26
+ interface BandDebugInfo {
27
+ /** CRS corners of each secondary tile fetched (for drawing outlines). */
28
+ secondaryTileCorners: Corners[];
29
+ /** Secondary zoom level index selected. */
30
+ secondaryZ: number;
31
+ /** UV transform applied to this band. */
32
+ uvTransform: UvTransform;
33
+ /** Stitched texture width in pixels. */
34
+ stitchedWidth: number;
35
+ /** Stitched texture height in pixels. */
36
+ stitchedHeight: number;
37
+ /** Number of secondary tiles fetched. */
38
+ tileCount: number;
39
+ /** Meters per pixel at the selected secondary level. */
40
+ metersPerPixel: number;
41
+ }
42
+ /** Debug info for all bands of a single primary tile. */
43
+ interface MultiTileDebugInfo {
44
+ /** Per-band debug metadata, keyed by source name. Only secondary bands. */
45
+ bands: Map<string, BandDebugInfo>;
46
+ }
47
+ /** Result of {@link MultiCOGLayer._getTileData} -- all band textures plus reprojection functions. */
48
+ interface MultiTileResult {
49
+ /** Per-band texture data, keyed by source name. */
50
+ bands: Map<string, BandTileData>;
51
+ /** Forward transform from pixel coordinates to CRS coordinates. */
52
+ forwardTransform: (x: number, y: number) => [number, number];
53
+ /** Inverse transform from CRS coordinates to pixel coordinates. */
54
+ inverseTransform: (x: number, y: number) => [number, number];
55
+ /** Width of the primary tile in pixels. */
56
+ width: number;
57
+ /** Height of the primary tile in pixels. */
58
+ height: number;
59
+ /** Byte length of all band textures, required for deck.gl TileLayer cache management. */
60
+ byteLength: number;
61
+ /** Only present when `debug: true`. */
62
+ debugInfo?: MultiTileDebugInfo;
63
+ }
64
+ /**
65
+ * Configuration for a single COG source within a {@link MultiCOGLayer}.
66
+ */
67
+ export interface MultiCOGSourceConfig {
68
+ /**
69
+ * URL or ArrayBuffer of the COG.
70
+ *
71
+ * @see {@link fetchGeoTIFF} for supported input types.
72
+ */
73
+ url: string | URL | ArrayBuffer;
74
+ }
75
+ /** Internal state for a single opened COG source. */
76
+ interface SourceState {
77
+ geotiff: GeoTIFF;
78
+ tms: TileMatrixSet;
79
+ }
80
+ /**
81
+ * Props accepted by {@link MultiCOGLayer}.
82
+ *
83
+ * Extends {@link CompositeLayerProps} with multi-source COG configuration and
84
+ * optional tile-layer tuning knobs forwarded to the underlying
85
+ * {@link TileLayerProps | TileLayer}.
86
+ *
87
+ * @see {@link MultiCOGLayer}
88
+ * @see {@link MultiCOGSourceConfig}
89
+ */
90
+ export type MultiCOGLayerProps = CompositeLayerProps & Pick<TileLayerProps, "debounceTime" | "maxCacheSize" | "maxCacheByteSize" | "maxRequests" | "refinementStrategy"> & {
91
+ /**
92
+ * Named sources -- each key becomes a band name used when compositing.
93
+ *
94
+ * @see {@link MultiCOGSourceConfig}
95
+ */
96
+ sources: Record<string, MultiCOGSourceConfig>;
97
+ /**
98
+ * Map source bands to RGB(A) output channels.
99
+ *
100
+ * @see {@link buildCompositeBandsProps}
101
+ */
102
+ composite?: {
103
+ r: string;
104
+ g?: string;
105
+ b?: string;
106
+ a?: string;
107
+ };
108
+ /**
109
+ * Post-processing render pipeline modules applied after compositing.
110
+ *
111
+ * @see {@link RasterModule}
112
+ */
113
+ renderPipeline?: RasterModule[];
114
+ /**
115
+ * EPSG code resolver used to look up projection definitions for numeric
116
+ * CRS codes found in GeoTIFF metadata.
117
+ *
118
+ * @default defaultEpsgResolver
119
+ * @see {@link EpsgResolver}
120
+ */
121
+ epsgResolver?: EpsgResolver;
122
+ /**
123
+ * Decoder pool for parallel image chunk decompression.
124
+ *
125
+ * @see {@link DecoderPool}
126
+ */
127
+ pool?: DecoderPool;
128
+ /**
129
+ * Maximum reprojection error in pixels for mesh refinement.
130
+ * Lower values create denser meshes with higher accuracy.
131
+ *
132
+ * @default 0.125
133
+ */
134
+ maxError?: number;
135
+ /**
136
+ * AbortSignal to cancel loading of all sources.
137
+ */
138
+ signal?: AbortSignal;
139
+ /**
140
+ * Called once all configured sources have been opened and the
141
+ * {@link MultiTilesetDescriptor} has been built.
142
+ *
143
+ * `geographicBounds` is computed from the primary (finest-resolution)
144
+ * source and reprojected to WGS84; it matches the shape returned by
145
+ * {@link COGLayerProps.onGeoTIFFLoad} and is suitable for passing to
146
+ * MapLibre's `fitBounds`.
147
+ */
148
+ onGeoTIFFLoad?: (sources: Map<string, GeoTIFF>, options: {
149
+ primaryKey: string;
150
+ geographicBounds: {
151
+ west: number;
152
+ south: number;
153
+ east: number;
154
+ north: number;
155
+ };
156
+ }) => void;
157
+ /**
158
+ * Enable debug overlay showing tile boundaries and metadata labels
159
+ * for all tilesets.
160
+ *
161
+ * @default false
162
+ */
163
+ debug?: boolean;
164
+ /**
165
+ * Opacity of the reprojection mesh debug overlay. Only used when
166
+ * `debug` is `true`. Forwarded to the underlying {@link RasterLayer}.
167
+ *
168
+ * @default 0.5
169
+ */
170
+ debugOpacity?: number;
171
+ /**
172
+ * Controls how much detail is shown in debug text labels.
173
+ *
174
+ * - `1`: tile index and resolution only
175
+ * - `2`: adds UV transform and tile count
176
+ * - `3`: adds stitched dimensions and meters/pixel
177
+ *
178
+ * @default 1
179
+ */
180
+ debugLevel?: 1 | 2 | 3;
181
+ };
182
+ /**
183
+ * A deck.gl {@link CompositeLayer} that opens multiple Cloud-Optimized GeoTIFFs
184
+ * (COGs) in parallel, builds a {@link TilesetDescriptor} for each, and groups
185
+ * them into a single {@link MultiTilesetDescriptor}.
186
+ *
187
+ * The finest-resolution source is automatically selected as the primary
188
+ * tileset, which drives the tile grid. Secondary sources are sampled at the
189
+ * closest matching resolution.
190
+ *
191
+ * @see {@link MultiCOGLayerProps} for accepted props.
192
+ * @see {@link createMultiTilesetDescriptor} for the grouping logic.
193
+ * @see {@link TileMatrixSetAdaptor} for the per-source tileset adapter.
194
+ */
195
+ export declare class MultiCOGLayer extends CompositeLayer<MultiCOGLayerProps> {
196
+ static layerName: string;
197
+ static defaultProps: {
198
+ epsgResolver: {
199
+ type: "accessor";
200
+ value: typeof defaultEpsgResolver;
201
+ };
202
+ maxError: {
203
+ type: "number";
204
+ value: number;
205
+ };
206
+ debug: {
207
+ type: "boolean";
208
+ value: boolean;
209
+ };
210
+ debugOpacity: {
211
+ type: "number";
212
+ value: number;
213
+ };
214
+ debugLevel: {
215
+ type: "number";
216
+ value: number;
217
+ };
218
+ };
219
+ state: {
220
+ sources: Map<string, SourceState> | null;
221
+ multiDescriptor: MultiTilesetDescriptor | null;
222
+ forwardTo4326: ReprojectionFns["forwardReproject"] | null;
223
+ inverseFrom4326: ReprojectionFns["inverseReproject"] | null;
224
+ forwardTo3857: ReprojectionFns["forwardReproject"] | null;
225
+ inverseFrom3857: ReprojectionFns["inverseReproject"] | null;
226
+ };
227
+ initializeState(): void;
228
+ updateState({ changeFlags, props, oldProps, }: UpdateParameters<this>): void;
229
+ /**
230
+ * Open all configured COG sources in parallel, compute shared projection
231
+ * functions, and build the {@link MultiTilesetDescriptor}.
232
+ *
233
+ * All sources are assumed to share the same CRS; the projection of the
234
+ * first source is used for the shared coordinate converters.
235
+ *
236
+ * @returns Resolves when all sources have been opened and state has been set.
237
+ */
238
+ _parseAllSources(): Promise<void>;
239
+ /**
240
+ * Fetch tile data for all configured sources at the given tile index.
241
+ *
242
+ * Primary-grid sources are fetched directly at (x, y, z). Secondary
243
+ * sources are resolved to covering tiles at the closest matching zoom
244
+ * level, fetched (potentially multiple tiles), stitched if necessary,
245
+ * and returned with the appropriate UV transform.
246
+ *
247
+ * @param tile - Tile load props from the TileLayer, containing index and signal.
248
+ * @returns Per-band textures, UV transforms, and reprojection functions.
249
+ */
250
+ _getTileData(tile: TileLoadProps): Promise<MultiTileResult>;
251
+ /**
252
+ * Fetch a single tile for a source that shares the primary tile grid.
253
+ *
254
+ * @returns A `[name, BandTileData, null]` tuple with identity UV transform
255
+ * and no debug info (primary bands don't need it).
256
+ */
257
+ private _fetchPrimaryBand;
258
+ /**
259
+ * Fetch covering tiles for a secondary source and stitch them into a
260
+ * single texture using {@link assembleTiles}.
261
+ *
262
+ * @returns A `[name, BandTileData, BandDebugInfo | null]` tuple with the
263
+ * computed UV transform and optional debug metadata.
264
+ */
265
+ private _fetchSecondaryBand;
266
+ /**
267
+ * Create sub-layers for a single loaded tile.
268
+ *
269
+ * Builds a {@link RasterLayer} with reprojection functions and a render
270
+ * pipeline that starts with a {@link CompositeBands} module binding all
271
+ * band textures, followed by any user-provided pipeline modules.
272
+ */
273
+ _renderSubLayers(props: TileLayerProps<MultiTileResult> & {
274
+ id: string;
275
+ data?: MultiTileResult;
276
+ _offset: number;
277
+ tile: Tile2DHeader<MultiTileResult>;
278
+ }, forwardTo4326: ReprojectionFns["forwardReproject"], inverseFrom4326: ReprojectionFns["inverseReproject"], forwardTo3857: ReprojectionFns["forwardReproject"], inverseFrom3857: ReprojectionFns["inverseReproject"]): Layer | LayersList | null;
279
+ /**
280
+ * Render debug overlay layers for a single tile: colored outlines for
281
+ * primary and secondary tile boundaries, and tiered text labels.
282
+ *
283
+ * @param tileId - Base id for sub-layer naming.
284
+ * @param tile - The tile header with index info.
285
+ * @param data - The fetched multi-tile result containing debug info.
286
+ * @param forwardTo4326 - Projection function for converting CRS corners to WGS84.
287
+ * @returns Array of PathLayer and TextLayer sub-layers.
288
+ */
289
+ private _renderDebugLayers;
290
+ /**
291
+ * Build the tile layer that drives tile traversal and rendering.
292
+ *
293
+ * Creates a {@link RasterTileset2D} factory from the primary tileset,
294
+ * then returns a {@link TileLayer} wired up with tile fetching and
295
+ * sub-layer rendering.
296
+ */
297
+ renderTileLayer(multiDescriptor: MultiTilesetDescriptor, forwardTo4326: ReprojectionFns["forwardReproject"], inverseFrom4326: ReprojectionFns["inverseReproject"], forwardTo3857: ReprojectionFns["forwardReproject"], inverseFrom3857: ReprojectionFns["inverseReproject"]): TileLayer;
298
+ renderLayers(): Layer | LayersList | null;
299
+ }
300
+ export {};
301
+ //# sourceMappingURL=multi-cog-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-cog-layer.d.ts","sourceRoot":"","sources":["../src/multi-cog-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,KAAK,EAEL,UAAU,EACV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqB,cAAc,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EACV,aAAa,IAAI,YAAY,EAC7B,cAAc,EACd,cAAc,IAAI,aAAa,EAEhC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,KAAK,EACV,OAAO,EACP,sBAAsB,EACtB,YAAY,EAGZ,WAAW,EACZ,MAAM,iC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