@gisatcz/deckgl-geolib 1.12.0-dev.4 → 2.0.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 (48) hide show
  1. package/README.md +67 -64
  2. package/dist/cjs/index.js +631 -641
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/index.min.js +3 -3
  5. package/dist/cjs/index.min.js.map +1 -1
  6. package/dist/{esm/types/cogtiles/cogtiles.d.ts → cjs/types/core/CogTiles.d.ts} +12 -9
  7. package/dist/cjs/types/{geoimage/geoimage.d.ts → core/GeoImage.d.ts} +6 -6
  8. package/dist/cjs/types/core/index.d.ts +2 -0
  9. package/dist/cjs/types/index.d.ts +2 -11
  10. package/dist/{esm/types/cogbitmaplayer → cjs/types/layers}/CogBitmapLayer.d.ts +3 -5
  11. package/dist/cjs/types/{cogterrainlayer → layers}/CogTerrainLayer.d.ts +13 -8
  12. package/dist/cjs/types/layers/index.d.ts +2 -0
  13. package/dist/esm/index.js +628 -641
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/index.min.js +3 -3
  16. package/dist/esm/index.min.js.map +1 -1
  17. package/dist/{cjs/types/cogtiles/cogtiles.d.ts → esm/types/core/CogTiles.d.ts} +12 -9
  18. package/dist/esm/types/{geoimage/geoimage.d.ts → core/GeoImage.d.ts} +6 -6
  19. package/dist/esm/types/core/index.d.ts +2 -0
  20. package/dist/esm/types/index.d.ts +2 -11
  21. package/dist/{cjs/types/cogbitmaplayer → esm/types/layers}/CogBitmapLayer.d.ts +3 -5
  22. package/dist/esm/types/{cogterrainlayer → layers}/CogTerrainLayer.d.ts +13 -8
  23. package/dist/esm/types/layers/index.d.ts +2 -0
  24. package/package.json +40 -4
  25. package/.eslintignore +0 -2
  26. package/.eslintrc.cjs +0 -3
  27. package/CHANGELOG.md +0 -166
  28. package/rollup.config.mjs +0 -77
  29. package/src/cogbitmaplayer/CogBitmapLayer.ts +0 -337
  30. package/src/cogbitmaplayer/README.md +0 -113
  31. package/src/cogterrainlayer/CogTerrainLayer.ts +0 -445
  32. package/src/cogterrainlayer/README.md +0 -118
  33. package/src/cogtiles/README.md +0 -72
  34. package/src/cogtiles/cogtiles.ts +0 -420
  35. package/src/cogtiles/lzw.js +0 -256
  36. package/src/geoimage/README.md +0 -129
  37. package/src/geoimage/delatin/index.ts +0 -495
  38. package/src/geoimage/geoimage.ts +0 -599
  39. package/src/geoimage/helpers/skirt.ts +0 -171
  40. package/src/index.ts +0 -11
  41. package/src/utilities/tileurls.ts +0 -21
  42. package/tsconfig.json +0 -6
  43. /package/dist/cjs/types/{geoimage → core}/delatin/index.d.ts +0 -0
  44. /package/dist/cjs/types/{geoimage → core}/helpers/skirt.d.ts +0 -0
  45. /package/dist/cjs/types/{utilities → utils}/tileurls.d.ts +0 -0
  46. /package/dist/esm/types/{geoimage → core}/delatin/index.d.ts +0 -0
  47. /package/dist/esm/types/{geoimage → core}/helpers/skirt.d.ts +0 -0
  48. /package/dist/esm/types/{utilities → utils}/tileurls.d.ts +0 -0
@@ -1,337 +0,0 @@
1
- import {
2
- CompositeLayer, CompositeLayerProps, DefaultProps, log, TextureSource, UpdateParameters,
3
- } from '@deck.gl/core';
4
- import {
5
- _Tile2DHeader as Tile2DHeader,
6
- _TileLoadProps as TileLoadProps,
7
- GeoBoundingBox,
8
- NonGeoBoundingBox,
9
- TileLayer,
10
- TileLayerProps,
11
- } from '@deck.gl/geo-layers';
12
- import { BitmapLayer } from '@deck.gl/layers';
13
- import { _TerrainExtension as TerrainExtension } from '@deck.gl/extensions';
14
- // import { GL } from '@luma.gl/constants';
15
- // import GL from '@luma.gl/constants';
16
- // GL.GL.CLIP_DISTANCE0_WEBGL
17
- import type { MeshAttributes } from '@loaders.gl/schema';
18
- import CogTiles from '../cogtiles/cogtiles.ts';
19
-
20
- import { GeoImageOptions } from '../geoimage/geoimage.ts';
21
- // import { TileBoundingBox, ZRange } from '../cogterrainlayer/CogTerrainLayer.js';
22
- export type TileBoundingBox = NonGeoBoundingBox | GeoBoundingBox;
23
-
24
- export type ZRange = [minZ: number, maxZ: number];
25
-
26
- // let needsRerender: boolean = false;
27
- // let extent = [0, 0, 0, 0]
28
- export type Bounds = [minX: number, minY: number, maxX: number, maxY: number];
29
-
30
- export type URLTemplate = string | string[] | null;
31
-
32
- export const urlType = {
33
- type: 'object' as const,
34
- value: null as URLTemplate,
35
- validate: (value, propType) => (propType.optional && value === null)
36
- || typeof value === 'string'
37
- || (Array.isArray(value) && value.every((url) => typeof url === 'string')),
38
- equal: (value1, value2) => {
39
- if (value1 === value2) {
40
- return true;
41
- }
42
- if (!Array.isArray(value1) || !Array.isArray(value2)) {
43
- return false;
44
- }
45
- const len = value1.length;
46
- if (len !== value2.length) {
47
- return false;
48
- }
49
- for (let i = 0; i < len; i++) {
50
- if (value1[i] !== value2[i]) {
51
- return false;
52
- }
53
- }
54
- return true;
55
- },
56
- };
57
-
58
- export type ClampToTerrainOptions = {
59
- terrainDrawMode?: string
60
- }
61
-
62
- const defaultProps: DefaultProps<CogBitmapLayerProps> = {
63
- ...TileLayer.defaultProps,
64
- // Image url that encodes height data
65
- // elevationData: urlType,
66
- // Image url to use as texture
67
- // texture: { ...urlType, optional: true },
68
- // Martini error tolerance in meters, smaller number -> more detailed mesh
69
- // meshMaxError: { type: 'number', value: 4.0 },
70
- // Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates
71
- bounds: {
72
- type: 'array', value: null, optional: true, compare: true,
73
- },
74
- rasterData: urlType,
75
- // Color to use if texture is unavailable
76
- // color: { type: 'color', value: [255, 255, 255] },
77
- blurredTexture: true,
78
- opacity: 1,
79
- clampToTerrain: false,
80
- // Object to decode height data, from (r, g, b) to height in meters
81
- // elevationDecoder: {
82
- // type: 'object',
83
- // value: {
84
- // rScaler: 1,
85
- // gScaler: 0,
86
- // bScaler: 0,
87
- // offset: 0,
88
- // },
89
- // },
90
- // Supply url to local terrain worker bundle. Only required if running offline and cannot access CDN.
91
- workerUrl: '',
92
- // Same as SimpleMeshLayer wireframe
93
- // wireframe: false,
94
- // material: true,
95
-
96
- // loaders: [TerrainLoader],
97
- };
98
-
99
- // Turns array of templates into a single string to work around shallow change
100
- function urlTemplateToUpdateTrigger(template: URLTemplate): string {
101
- if (Array.isArray(template)) {
102
- return template.join(';');
103
- }
104
- return template || '';
105
- }
106
-
107
- type MeshAndTexture = [MeshAttributes | null, TextureSource | null];
108
-
109
- /** Props added by the CogBitmapLayer */
110
- type _CogBitmapLayerProps = {
111
- /** Image url that encodes raster data. * */
112
- rasterData: URLTemplate;
113
-
114
- /** Bounding box of the bitmap image, [minX, minY, maxX, maxY] in world coordinates. * */
115
- bounds: Bounds | null;
116
-
117
- /** Weather visualise the entire image with specified opacity (0-1) * */
118
- opacity?: number;
119
-
120
- /** Whether the rendered texture should be clamped to terrain * */
121
- clampToTerrain?: ClampToTerrainOptions | boolean, // terrainDrawMode: 'drape',
122
-
123
- /**
124
- * TODO
125
- */
126
- cogBitmapOptions: GeoImageOptions;
127
-
128
- isTiled: boolean;
129
-
130
- /**
131
- * @deprecated Use `loadOptions.terrain.workerUrl` instead
132
- */
133
- workerUrl?: string;
134
- };
135
-
136
- /** All properties supported by CogBitmapLayer */
137
- export type CogBitmapLayerProps = _CogBitmapLayerProps &
138
- TileLayerProps<MeshAndTexture> &
139
- CompositeLayerProps;
140
-
141
- /** Render bitmap texture from cog raster images. */
142
- export default class CogBitmapLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<
143
- ExtraPropsT & Required<_CogBitmapLayerProps & Required<TileLayerProps<MeshAndTexture>>>
144
- > {
145
- static defaultProps = defaultProps;
146
-
147
- static layerName = 'CogBitmapLayer';
148
-
149
- state!: {
150
- initialized: boolean;
151
- isTiled?: boolean;
152
- terrain?: MeshAttributes;
153
- zRange?: ZRange | null;
154
- bitmapCogTiles: any;
155
- minZoom: number;
156
- maxZoom: number;
157
- };
158
-
159
- // private _isLoaded: boolean;
160
-
161
- // id = '';
162
-
163
- // url: string;
164
-
165
- // static displayName: string;
166
-
167
- // cogTiles: CogTiles;
168
- //
169
- // tileSize: number;
170
- //
171
-
172
- async initializeState(context: any) {
173
- super.initializeState(context);
174
-
175
- this.setState({
176
- bitmapCogTiles: new CogTiles(this.props.cogBitmapOptions),
177
- initialized: false,
178
- });
179
-
180
- await this.init();
181
- }
182
-
183
- async init() {
184
- await this.state.bitmapCogTiles.initializeCog(this.props.rasterData);
185
-
186
- const zoomRange = this.state.bitmapCogTiles.getZoomRange();
187
-
188
- const [minZoom, maxZoom] = zoomRange;
189
-
190
- this.setState({ initialized: true, minZoom, maxZoom });
191
- }
192
-
193
- updateState({ props, oldProps }: UpdateParameters<this>): void {
194
- const rasterDataChanged = props.rasterData !== oldProps.rasterData;
195
- if (rasterDataChanged) {
196
- const { rasterData } = props;
197
- const isTiled = rasterData
198
- && ((Array.isArray(rasterData)
199
- || (rasterData.includes('{x}') && rasterData.includes('{y}'))) || this.props.isTiled);
200
- this.setState({ isTiled });
201
- }
202
-
203
- // Reloading for single terrain mesh
204
- const shouldReload = rasterDataChanged
205
- // || props.meshMaxError !== oldProps.meshMaxError
206
- // || props.elevationDecoder !== oldProps.elevationDecoder
207
- || props.bounds !== oldProps.bounds;
208
-
209
- if (!this.state.isTiled && shouldReload) {
210
- // When state.isTiled, elevationData cannot be an array
211
- // const terrain = this.loadTerrain(props as TerrainLoadProps);
212
- // this.setState({ terrain });
213
- }
214
-
215
- // Update the useChannel option for bitmapCogTiles when cogBitmapOptions.useChannel changes.
216
- // This ensures that the correct channel is used for rendering, but directly modifying the state
217
- // object in this way is not ideal and may need refactoring in the future to follow a more
218
- // declarative state management approach. Consider revisiting this if additional properties
219
- // need to be synchronized or if the state structure changes.
220
- if (props?.cogBitmapOptions?.useChannel && (props.cogBitmapOptions?.useChannel !== oldProps.cogBitmapOptions?.useChannel)) {
221
- this.state.bitmapCogTiles.options.useChannel = props.cogBitmapOptions.useChannel;
222
- }
223
-
224
- // TODO - remove in v9
225
- // @ts-ignore
226
- if (props.workerUrl) {
227
- log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
228
- }
229
- }
230
-
231
- async getTiledBitmapData(tile: TileLoadProps): Promise<TextureSource> {
232
- // TODO - pass signal to getTile
233
- // abort request if signal is aborted
234
- const tileData = await this.state.bitmapCogTiles.getTile(
235
- tile.index.x,
236
- tile.index.y,
237
- tile.index.z,
238
- // bounds,
239
- // this.props.meshMaxError,
240
- );
241
- return tileData;
242
- }
243
-
244
- renderSubLayers(
245
- props: TileLayerProps<TextureSource> & {
246
- id: string;
247
- data: TextureSource;
248
- tile: Tile2DHeader<TextureSource>;
249
- },
250
- ) {
251
-
252
- const SubLayerClass = this.getSubLayerClass('image', BitmapLayer);
253
- const { blurredTexture } = this.state.bitmapCogTiles.options;
254
-
255
- const { opacity, clampToTerrain } = this.props;
256
-
257
- const { data } = props;
258
-
259
- if (!data) {
260
- return null;
261
- }
262
-
263
- const {
264
- bbox: {
265
- west, south, east, north,
266
- },
267
- } = props.tile;
268
-
269
- return new SubLayerClass({ ...props, tileSize: this.state.bitmapCogTiles.tileSize }, {
270
- data: null,
271
- image: data,
272
- _instanced: false,
273
- bounds: [west, south, east, north],
274
- opacity,
275
- textureParameters: {
276
- minFilter: blurredTexture ? 'linear' : 'nearest',
277
- magFilter: blurredTexture ? 'linear' : 'nearest',
278
- },
279
- // TODO check if works!!!
280
- extensions: clampToTerrain ? [new TerrainExtension()] : [],
281
- ...(clampToTerrain?.terrainDrawMode
282
- ? { terrainDrawMode: clampToTerrain.terrainDrawMode }
283
- : {}),
284
- });
285
- }
286
-
287
- renderLayers() {
288
- const {
289
- rasterData,
290
- blurredTexture,
291
- opacity,
292
- clampToTerrain,
293
- // tileSize,
294
- maxRequests,
295
- onTileLoad,
296
- onTileUnload,
297
- onTileError,
298
- maxCacheSize,
299
- maxCacheByteSize,
300
- refinementStrategy,
301
- cogBitmapOptions,
302
- } = this.props;
303
- if (this.state.isTiled && this.state.initialized) {
304
- const { tileSize } = this.state.bitmapCogTiles;
305
-
306
- return new TileLayer(this.getSubLayerProps({
307
- id: 'tiles',
308
- }), {
309
- getTileData: this.getTiledBitmapData.bind(this),
310
- renderSubLayers: this.renderSubLayers.bind(this),
311
- updateTriggers: {
312
- getTileData: [
313
- // rasterData: urlTemplateToUpdateTrigger(rasterData),
314
- // blurredTexture,
315
- // opacity,
316
- // cogBitmapOptions,
317
- clampToTerrain,
318
- cogBitmapOptions.useChannel,
319
- ],
320
- // renderSubLayers: [cogBitmapOptions],
321
- },
322
- extent: this.state.bitmapCogTiles.getBoundsAsLatLon(),
323
- tileSize,
324
- minZoom: this.state.minZoom,
325
- maxZoom: this.state.maxZoom,
326
- maxRequests,
327
- onTileLoad,
328
- onTileUnload,
329
- onTileError,
330
- maxCacheSize,
331
- maxCacheByteSize,
332
- refinementStrategy,
333
- });
334
- }
335
- return null;
336
- }
337
- }
@@ -1,113 +0,0 @@
1
- # CogBitmapLayer
2
-
3
- A Deck.gl-compatible layer for loading and displaying tiled COG image data
4
-
5
- ## Features
6
- ### Tiled data rendering
7
- - Dynamically load and render tiled COG image data
8
- ### Data visualization
9
- - Set visualization styling, colors, use heatmap, set data bounds, and more
10
- ### Compression support
11
- - Supports DEFLATE data compression methods
12
-
13
- [//]: # (- Supports JPEG, LZW nad DEFLATE data compression methods)
14
- ## Usage
15
- ### Initialize the layer
16
- To create CogBitmapLayer, you need an id name, URL of your COG, declare that data is tiled,
17
- and also an object containing [geoimage](../geoimage/README.md) options for data processing.
18
-
19
- ### Examples
20
- > **Note**: The examples below showcase only a subset of available rendering options.
21
- > To view all configurable options for `CogBitmapLayer`,
22
- > refer to the [geoimage](../geoimage/README.md) library documentation.
23
-
24
- Import package into project and create bitmap layer
25
-
26
- ```typescript
27
- import geolib from '@gisatcz/deckgl-geolib';
28
-
29
- const CogBitmapLayer = geolib.CogBitmapLayer;
30
- ```
31
- Display simple rgb image. If you don't specify a channel to process, it defaults to grayscale, RGB, or RGBA depending on the channel count
32
- ```typescript
33
- const cogLayer = new CogBitmapLayer(
34
- id: 'cog_bitmap_name',
35
- rasterData: 'cog_bitmap_data_url.tif',
36
- isTiled: true,
37
- cogBitmapOptions: {
38
- type: 'image',
39
- }
40
- );
41
- ```
42
-
43
- <img src = "/images/cogBitmapLayer_rgb.jpg" width = "50%" alt="COG bitmap RGB image.">
44
-
45
- Display the second channel as a heatmap with data from 0 to 1000
46
- - Currently, when `useAutoRange` is `true`, min and max data value for each image is calculated separately, thus it is recommended to set min and max values in `colorScaleValueRange`.
47
-
48
- ```typescript
49
- const cogLayer = new CogBitmapLayer(
50
- id: 'cog_bitmap_name',
51
- rasterData: 'cog_bitmap_data_url.tif',
52
- isTiled: true,
53
- cogBitmapOptions: {
54
- type: 'image',
55
- // useAutoRange: true,
56
- colorScaleValueRange: [0,1000]
57
- useChannel: 1,
58
- }
59
- );
60
- ```
61
- <a name='custom-heatmap-color-scale'></a>
62
- Display the second channel as a heatmap with data from 0 to 1000 with custom color scale
63
-
64
- ```typescript
65
- const cogLayer = new CogBitmapLayer(
66
- id: 'cog_bitmap_name',
67
- rasterData: 'cog_bitmap_data_url.tif',
68
- isTiled: true,
69
- cogBitmapOptions: {
70
- type: 'image',
71
- colorScaleValueRange: [100, 200, 300]
72
- useChannel: 1,
73
- useHeatmap: true,
74
- colorScale: ['yellow', '#20908d', [68, 1, 84]]
75
- }
76
- );
77
- ```
78
- <img src = "/images/cogBitmapLayer_customColor.jpg" width = "50%" alt="COG bitmap image with custom color scale.">
79
-
80
- Display the third channel as a green color and only show data from 100 to 200, the clipped data should be visualized with yellow color
81
- ```typescript
82
- const cogLayer = new CogBitmapLayer(
83
- id: 'cog_bitmap_name',
84
- rasterData: 'cog_bitmap_data_url.tif',
85
- isTiled: true,
86
- cogBitmapOptions: {
87
- type: 'image',
88
- useChannel: 2,
89
- useSingleColor: true,
90
- clipLow: 100,
91
- clipHigh: 200,
92
- color: [32, 144, 81, 255],
93
- clippedColor: 'yellow'
94
- }
95
- );
96
- ```
97
- <img src = "/images/cogBitmapLayer_clip.jpg" width = "50%" alt="COG bitmap image with clipped areas.">
98
-
99
- <a name='assigning-color-to-specific-data-value'></a>
100
- Assign color to specific data values
101
- ```typescript
102
- const cogLayer = new CogBitmapLayer(
103
- id: 'cog_bitmap_name',
104
- rasterData: 'cog_bitmap_data_url.tif',
105
- isTiled: true,
106
- cogBitmapOptions: {
107
- type: 'image',
108
- useChannel: 20,
109
- useColorsBasedOnValues: true,
110
- colorsBasedOnValues: [[1, 'red'], [2, [0, 0, 255]], [3, '#00FF00']]
111
- }
112
- );
113
- ```