maplibre-gl-raster 0.1.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -0
  3. package/dist/LercDecode.es-CZm5toNk.js +442 -0
  4. package/dist/LercDecode.es-CZm5toNk.js.map +1 -0
  5. package/dist/RasterControl-B7XdXYSu.js +18838 -0
  6. package/dist/RasterControl-B7XdXYSu.js.map +1 -0
  7. package/dist/__vite-browser-external-BgMKmFg9.js +9 -0
  8. package/dist/__vite-browser-external-BgMKmFg9.js.map +1 -0
  9. package/dist/assets/LercDecode.es-Bvg6-wb5.js +442 -0
  10. package/dist/assets/LercDecode.es-Bvg6-wb5.js.map +1 -0
  11. package/dist/assets/__vite-browser-external-BgMKmFg9.js +9 -0
  12. package/dist/assets/__vite-browser-external-BgMKmFg9.js.map +1 -0
  13. package/dist/assets/chunk-FDOR9p9I.js +24 -0
  14. package/dist/assets/decode-BvR5vy7g.js +940 -0
  15. package/dist/assets/decode-BvR5vy7g.js.map +1 -0
  16. package/dist/assets/lerc-By2TvjAX.js +34 -0
  17. package/dist/assets/lerc-By2TvjAX.js.map +1 -0
  18. package/dist/assets/lzw-CQJJDca2.js +174 -0
  19. package/dist/assets/lzw-CQJJDca2.js.map +1 -0
  20. package/dist/assets/worker-C6cg9T3Y.js +51 -0
  21. package/dist/assets/worker-C6cg9T3Y.js.map +1 -0
  22. package/dist/assets/zstd-DBZv9xja.js +569 -0
  23. package/dist/assets/zstd-DBZv9xja.js.map +1 -0
  24. package/dist/chunk-FDOR9p9I.js +24 -0
  25. package/dist/decode-BMFOVF9X.js +1966 -0
  26. package/dist/decode-BMFOVF9X.js.map +1 -0
  27. package/dist/index.mjs +223 -0
  28. package/dist/index.mjs.map +1 -0
  29. package/dist/lerc-B7WY-v3y.js +34 -0
  30. package/dist/lerc-B7WY-v3y.js.map +1 -0
  31. package/dist/lzw-YEsReV21.js +174 -0
  32. package/dist/lzw-YEsReV21.js.map +1 -0
  33. package/dist/maplibre-gl-raster.css +670 -0
  34. package/dist/react.mjs +145 -0
  35. package/dist/react.mjs.map +1 -0
  36. package/dist/types/index.d.ts +649 -0
  37. package/dist/types/react.d.ts +477 -0
  38. package/dist/zstd-DBZv9xja.js +569 -0
  39. package/dist/zstd-DBZv9xja.js.map +1 -0
  40. package/package.json +125 -0
@@ -0,0 +1,477 @@
1
+ import { Dispatch } from 'react';
2
+ import { IControl } from 'maplibre-gl';
3
+ import { Map as Map_2 } from 'maplibre-gl';
4
+ import { SetStateAction } from 'react';
5
+
6
+ /**
7
+ * Options for {@link AddRasterOptions} consumers (RasterControl.addRaster).
8
+ */
9
+ export declare interface AddRasterOptions {
10
+ /** Layer id; auto-generated when omitted. */
11
+ id?: string;
12
+ /** Display name; derived from the URL / file name when omitted. */
13
+ name?: string;
14
+ /** Initial visualization state overrides (mode/bands default from the
15
+ * loaded band count). */
16
+ state?: Partial<RasterLayerState>;
17
+ /** Fit the map to the raster's bounds once loaded. @default true */
18
+ zoomTo?: boolean;
19
+ /** Id of an existing map style layer to insert the raster beneath (e.g. a
20
+ * symbol layer so labels stay readable). Drawn on top when omitted or when
21
+ * the layer does not exist. */
22
+ beforeId?: string;
23
+ }
24
+
25
+ /**
26
+ * A MapLibre GL control for visualizing local and remote raster datasets
27
+ * (GeoTIFF / Cloud Optimized GeoTIFF). A collapsible button expands into a
28
+ * panel with an "Add data" section (URL or local file), a layer list, and
29
+ * per-layer rendering settings (bands, rescale histograms, colormaps,
30
+ * nodata, stretch, gamma, opacity). Rendering uses a deck.gl COGLayer
31
+ * pipeline on a shared MapboxOverlay.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const control = new RasterControl({ collapsed: false });
36
+ * map.addControl(control, 'top-right');
37
+ * await control.addRaster('https://example.com/data/cog.tif');
38
+ * ```
39
+ */
40
+ export declare class RasterControl implements IControl {
41
+ private _map?;
42
+ private _mapContainer?;
43
+ private _container?;
44
+ private _panel?;
45
+ private _options;
46
+ private _state;
47
+ private _eventHandlers;
48
+ private _layerManager?;
49
+ private _panelUI?;
50
+ private _onReady;
51
+ private _resizeHandler;
52
+ private _mapResizeHandler;
53
+ private _clickOutsideHandler;
54
+ /**
55
+ * Creates a new RasterControl instance.
56
+ *
57
+ * @param options - Configuration options for the control
58
+ */
59
+ constructor(options?: Partial<RasterControlOptions>);
60
+ /**
61
+ * Called when the control is added to the map.
62
+ * Implements the IControl interface.
63
+ *
64
+ * @param map - The MapLibre GL map instance
65
+ * @returns The control's container element
66
+ */
67
+ onAdd(map: Map_2): HTMLElement;
68
+ /**
69
+ * Called when the control is removed from the map.
70
+ * Implements the IControl interface.
71
+ */
72
+ onRemove(): void;
73
+ /**
74
+ * Gets the current state of the control.
75
+ *
76
+ * @returns The current plugin state
77
+ */
78
+ getState(): RasterControlState;
79
+ /**
80
+ * Updates the control state.
81
+ *
82
+ * @param newState - Partial state to merge with current state
83
+ */
84
+ setState(newState: Partial<RasterControlState>): void;
85
+ /**
86
+ * Toggles the collapsed state of the control panel.
87
+ */
88
+ toggle(): void;
89
+ /**
90
+ * Expands the control panel.
91
+ */
92
+ expand(): void;
93
+ /**
94
+ * Collapses the control panel.
95
+ */
96
+ collapse(): void;
97
+ /**
98
+ * Registers an event handler.
99
+ *
100
+ * @param event - The event type to listen for
101
+ * @param handler - The callback function
102
+ */
103
+ on(event: RasterControlEvent, handler: RasterControlEventHandler): void;
104
+ /**
105
+ * Removes an event handler.
106
+ *
107
+ * @param event - The event type
108
+ * @param handler - The callback function to remove
109
+ */
110
+ off(event: RasterControlEvent, handler: RasterControlEventHandler): void;
111
+ /**
112
+ * Gets the map instance.
113
+ *
114
+ * @returns The MapLibre GL map instance or undefined if not added to a map
115
+ */
116
+ getMap(): Map_2 | undefined;
117
+ /**
118
+ * Gets the control container element.
119
+ *
120
+ * @returns The container element or undefined if not added to a map
121
+ */
122
+ getContainer(): HTMLElement | undefined;
123
+ /**
124
+ * Adds a raster layer from a remote COG URL or a local GeoTIFF File.
125
+ *
126
+ * The returned promise resolves with the layer id once the GeoTIFF header
127
+ * loads (waiting for the control to be added to a map first, if needed)
128
+ * and rejects when loading fails.
129
+ *
130
+ * @param source - COG URL or a local GeoTIFF File
131
+ * @param options - Id/name/state overrides and zoom behavior
132
+ * @returns The new layer's id
133
+ */
134
+ addRaster(source: string | File, options?: AddRasterOptions): Promise<string>;
135
+ /**
136
+ * Removes a raster layer.
137
+ *
138
+ * @param id - The layer id
139
+ */
140
+ removeRaster(id: string): void;
141
+ /**
142
+ * Gets a snapshot of one raster layer.
143
+ *
144
+ * @param id - The layer id
145
+ * @returns Layer info, or undefined when unknown
146
+ */
147
+ getRaster(id: string): RasterLayerInfo | undefined;
148
+ /**
149
+ * Gets snapshots of all raster layers in draw order (first = bottom).
150
+ *
151
+ * @returns Layer info array
152
+ */
153
+ getRasters(): RasterLayerInfo[];
154
+ /**
155
+ * Merges a partial visualization state into a layer (bands, rescale,
156
+ * colormap, nodata, opacity, gamma, stretch, visible).
157
+ *
158
+ * @param id - The layer id
159
+ * @param patch - State fields to update
160
+ */
161
+ setRasterState(id: string, patch: Partial<RasterLayerState>): void;
162
+ /**
163
+ * Shows or hides a raster layer.
164
+ *
165
+ * @param id - The layer id
166
+ * @param visible - Whether the layer should render
167
+ */
168
+ setVisible(id: string, visible: boolean): void;
169
+ /**
170
+ * Selects the layer whose settings the panel edits.
171
+ *
172
+ * @param id - The layer id, or null to clear the selection
173
+ */
174
+ selectRaster(id: string | null): void;
175
+ /**
176
+ * Fits the map view to a layer's bounds.
177
+ *
178
+ * @param id - The layer id
179
+ */
180
+ zoomToRaster(id: string): void;
181
+ /**
182
+ * Moves a layer to a new position in the draw order.
183
+ *
184
+ * @param id - The layer id
185
+ * @param toIndex - Target index (0 = bottom)
186
+ */
187
+ reorderRaster(id: string, toIndex: number): void;
188
+ /** Re-emits LayerManager events through the control's event system. */
189
+ private _forwardLayerManagerEvents;
190
+ /**
191
+ * Emits an event to all registered handlers.
192
+ *
193
+ * @param event - The event type to emit
194
+ * @param extra - Optional layerId/error payload for raster events
195
+ */
196
+ private _emit;
197
+ /**
198
+ * Creates the main container element for the control.
199
+ * Contains a toggle button (29x29) matching navigation control size.
200
+ *
201
+ * @returns The container element
202
+ */
203
+ private _createContainer;
204
+ /**
205
+ * Creates the panel element with header and content areas.
206
+ * Panel is positioned as a dropdown below the toggle button.
207
+ *
208
+ * @returns The panel element
209
+ */
210
+ private _createPanel;
211
+ /**
212
+ * Setup event listeners for panel positioning and click-outside behavior.
213
+ */
214
+ private _setupEventListeners;
215
+ /**
216
+ * Detect which corner the control is positioned in.
217
+ *
218
+ * @returns The position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
219
+ */
220
+ private _getControlPosition;
221
+ /**
222
+ * Update the panel position based on button location and control corner.
223
+ * Positions the panel next to the button, expanding in the appropriate direction.
224
+ */
225
+ private _updatePanelPosition;
226
+ }
227
+
228
+ /**
229
+ * Event types emitted by the raster control
230
+ */
231
+ export declare type RasterControlEvent = 'collapse' | 'expand' | 'statechange' | 'rasteradd' | 'rasterremove' | 'rasterchange' | 'rasterselect' | 'error';
232
+
233
+ /**
234
+ * Event payload passed to registered handlers.
235
+ */
236
+ export declare interface RasterControlEventData {
237
+ type: RasterControlEvent;
238
+ state: RasterControlState;
239
+ /** Affected layer id for raster* events. */
240
+ layerId?: string;
241
+ /** Error detail for 'error' events. */
242
+ error?: Error;
243
+ }
244
+
245
+ /**
246
+ * Event handler function type
247
+ */
248
+ export declare type RasterControlEventHandler = (event: RasterControlEventData) => void;
249
+
250
+ /**
251
+ * Options for configuring the RasterControl
252
+ */
253
+ export declare interface RasterControlOptions {
254
+ /**
255
+ * Whether the control panel should start collapsed (showing only the toggle button)
256
+ * @default true
257
+ */
258
+ collapsed?: boolean;
259
+ /**
260
+ * Position of the control on the map
261
+ * @default 'top-right'
262
+ */
263
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
264
+ /**
265
+ * Title displayed in the control header
266
+ * @default 'Raster'
267
+ */
268
+ title?: string;
269
+ /**
270
+ * Width of the control panel in pixels
271
+ * @default 360
272
+ */
273
+ panelWidth?: number;
274
+ /**
275
+ * Custom CSS class name for the control container
276
+ */
277
+ className?: string;
278
+ /**
279
+ * Render the deck.gl overlay interleaved with the basemap's layers.
280
+ * @default true
281
+ */
282
+ interleaved?: boolean;
283
+ /**
284
+ * Prefills the "Add data" URL input with this COG URL. The raster is only
285
+ * loaded automatically when {@link autoLoad} is true; otherwise the user
286
+ * still clicks Load.
287
+ * @default ''
288
+ */
289
+ defaultUrl?: string;
290
+ /**
291
+ * When true and {@link defaultUrl} is set, the raster is loaded as soon as
292
+ * the control is added to the map (instead of prefilling the URL input).
293
+ * @default false
294
+ */
295
+ autoLoad?: boolean;
296
+ }
297
+
298
+ /**
299
+ * React wrapper component for RasterControl.
300
+ *
301
+ * This component manages the lifecycle of a RasterControl instance,
302
+ * adding it to the map on mount and removing it on unmount.
303
+ *
304
+ * @example
305
+ * ```tsx
306
+ * import { RasterControlReact } from 'maplibre-gl-raster/react';
307
+ *
308
+ * function MyMap() {
309
+ * const [map, setMap] = useState<Map | null>(null);
310
+ *
311
+ * return (
312
+ * <>
313
+ * <div ref={mapContainer} />
314
+ * {map && (
315
+ * <RasterControlReact
316
+ * map={map}
317
+ * collapsed={false}
318
+ * onReady={(control) => control.addRaster('https://example.com/cog.tif')}
319
+ * />
320
+ * )}
321
+ * </>
322
+ * );
323
+ * }
324
+ * ```
325
+ *
326
+ * @param props - Component props including map instance and control options
327
+ * @returns null - This component renders nothing directly
328
+ */
329
+ export declare function RasterControlReact({ map, onStateChange, onReady, ...options }: RasterControlReactProps): null;
330
+
331
+ /**
332
+ * Props for the React wrapper component
333
+ */
334
+ export declare interface RasterControlReactProps extends RasterControlOptions {
335
+ /**
336
+ * MapLibre GL map instance
337
+ */
338
+ map: Map_2;
339
+ /**
340
+ * Callback fired when the control state changes
341
+ */
342
+ onStateChange?: (state: RasterControlState) => void;
343
+ /**
344
+ * Callback fired once the control is added to the map, with the control
345
+ * instance — use it to call imperative methods like addRaster().
346
+ */
347
+ onReady?: (control: RasterControl) => void;
348
+ }
349
+
350
+ /**
351
+ * Internal state of the plugin control
352
+ */
353
+ export declare interface RasterControlState {
354
+ /**
355
+ * Whether the control panel is currently collapsed
356
+ */
357
+ collapsed: boolean;
358
+ /**
359
+ * Current panel width in pixels
360
+ */
361
+ panelWidth: number;
362
+ /**
363
+ * Any custom state data
364
+ */
365
+ data?: Record<string, unknown>;
366
+ }
367
+
368
+ /**
369
+ * Public, read-only snapshot of a raster layer.
370
+ */
371
+ export declare interface RasterLayerInfo {
372
+ /** Stable layer id. */
373
+ id: string;
374
+ /** Display name shown in the layer list. */
375
+ name: string;
376
+ /** Data source. */
377
+ source: RasterLayerSource;
378
+ /** Band count, known once the GeoTIFF header loads. */
379
+ bandCount: number | null;
380
+ /** 1-indexed band names parsed from GDAL_METADATA, when present. */
381
+ bandNames: globalThis.Map<number, string> | null;
382
+ /** Map style layer id the raster is inserted beneath, when set. */
383
+ beforeId: string | null;
384
+ /** Current visualization state. */
385
+ state: RasterLayerState;
386
+ }
387
+
388
+ /** Where a raster layer's data came from. */
389
+ export declare type RasterLayerSource = {
390
+ kind: 'url';
391
+ url: string;
392
+ } | {
393
+ kind: 'file';
394
+ fileName: string;
395
+ objectUrl: string;
396
+ };
397
+
398
+ /**
399
+ * Per-layer visualization state.
400
+ */
401
+ export declare interface RasterLayerState {
402
+ /** Rendering mode. */
403
+ mode: RasterMode;
404
+ /** 1-indexed band selection: [r, g, b] in RGB mode, [band] in single mode. */
405
+ bands: number[];
406
+ /** Per-channel [min, max] rescale windows; null = auto (2-98% percentile
407
+ * from computed stats). */
408
+ rescale: [number, number][] | null;
409
+ /** Colormap name (single-band mode only). 'palette' uses the image's
410
+ * embedded color table; defaults to 'gray'. */
411
+ colormap: string;
412
+ /** Nodata handling. */
413
+ nodata: RasterNodata;
414
+ /** Layer transparency, 0 (invisible) to 1 (fully opaque). */
415
+ opacity: number;
416
+ /** Power-law gamma correction (1.0 = off). */
417
+ gamma: number;
418
+ /** Curve applied to rescaled values. */
419
+ stretch: RasterStretch;
420
+ /** Whether the layer is drawn on the map. */
421
+ visible: boolean;
422
+ }
423
+
424
+ /** Rendering mode: RGB composite (one band per channel) or single band
425
+ * through a colormap. */
426
+ export declare type RasterMode = 'rgb' | 'single';
427
+
428
+ /** Nodata handling: 'auto' reads the value declared by the COG (and treats
429
+ * NaN as nodata for float data), a number overrides it in source units, and
430
+ * 'off' renders every pixel. */
431
+ export declare type RasterNodata = number | 'off' | 'auto';
432
+
433
+ /** Curve applied to the rescaled [0, 1] value before gamma / colormap.
434
+ * "log" expands the low-value range (useful for skewed data with most
435
+ * variation near zero); "sqrt" is a gentler version. */
436
+ export declare type RasterStretch = 'linear' | 'log' | 'sqrt';
437
+
438
+ /**
439
+ * Custom hook for managing plugin state in React applications.
440
+ *
441
+ * This hook provides a simple way to track and update the state
442
+ * of a RasterControl from React components.
443
+ *
444
+ * @example
445
+ * ```tsx
446
+ * function MyComponent() {
447
+ * const { state, setCollapsed, setData, reset } = useRasterState();
448
+ *
449
+ * return (
450
+ * <div>
451
+ * <button onClick={() => setCollapsed(!state.collapsed)}>
452
+ * {state.collapsed ? 'Expand' : 'Collapse'}
453
+ * </button>
454
+ * <RasterControlReact
455
+ * map={map}
456
+ * collapsed={state.collapsed}
457
+ * onStateChange={(newState) => setState(newState)}
458
+ * />
459
+ * </div>
460
+ * );
461
+ * }
462
+ * ```
463
+ *
464
+ * @param initialState - Optional initial state values
465
+ * @returns Object containing state and update functions
466
+ */
467
+ export declare function useRasterState(initialState?: Partial<RasterControlState>): {
468
+ state: RasterControlState;
469
+ setState: Dispatch<SetStateAction<RasterControlState>>;
470
+ setCollapsed: (collapsed: boolean) => void;
471
+ setPanelWidth: (panelWidth: number) => void;
472
+ setData: (data: Record<string, unknown>) => void;
473
+ reset: () => void;
474
+ toggle: () => void;
475
+ };
476
+
477
+ export { }