@gisatcz/deckgl-geolib 1.12.0-dev.0 → 1.12.0-dev.11

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.
@@ -1,326 +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
- const cog = await this.state.bitmapCogTiles.initializeCog(this.props.rasterData);
185
-
186
- const zoomRange = this.state.bitmapCogTiles.getZoomRange(cog);
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
- // TODO - remove in v9
216
- // @ts-ignore
217
- if (props.workerUrl) {
218
- log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
219
- }
220
- }
221
-
222
- async getTiledBitmapData(tile: TileLoadProps): Promise<TextureSource> {
223
- // TODO - pass signal to getTile
224
- // abort request if signal is aborted
225
- const tileData = await this.state.bitmapCogTiles.getTile(
226
- tile.index.x,
227
- tile.index.y,
228
- tile.index.z,
229
- // bounds,
230
- // this.props.meshMaxError,
231
- );
232
- return tileData;
233
- }
234
-
235
- renderSubLayers(
236
- props: TileLayerProps<TextureSource> & {
237
- id: string;
238
- data: TextureSource;
239
- tile: Tile2DHeader<TextureSource>;
240
- },
241
- ) {
242
- const SubLayerClass = this.getSubLayerClass('image', BitmapLayer);
243
- const { blurredTexture } = this.state.bitmapCogTiles.options;
244
-
245
- const { opacity, clampToTerrain } = this.props;
246
-
247
- const { data } = props;
248
-
249
- if (!data) {
250
- return null;
251
- }
252
-
253
- const {
254
- bbox: {
255
- west, south, east, north,
256
- },
257
- } = props.tile;
258
-
259
- return new SubLayerClass({ ...props, tileSize: this.state.bitmapCogTiles.tileSize }, {
260
- data: null,
261
- image: data,
262
- _instanced: false,
263
- bounds: [west, south, east, north],
264
- opacity,
265
- textureParameters: {
266
- minFilter: blurredTexture ? 'linear' : 'nearest',
267
- magFilter: blurredTexture ? 'linear' : 'nearest',
268
- },
269
- // TODO check if works!!!
270
- extensions: clampToTerrain ? [new TerrainExtension()] : [],
271
- ...(clampToTerrain?.terrainDrawMode
272
- ? { terrainDrawMode: clampToTerrain.terrainDrawMode }
273
- : {}),
274
- });
275
- }
276
-
277
- renderLayers() {
278
- const {
279
- rasterData,
280
- blurredTexture,
281
- opacity,
282
- clampToTerrain,
283
- // tileSize,
284
- maxRequests,
285
- onTileLoad,
286
- onTileUnload,
287
- onTileError,
288
- maxCacheSize,
289
- maxCacheByteSize,
290
- refinementStrategy,
291
- cogBitmapOptions,
292
- } = this.props;
293
- if (this.state.isTiled && this.state.initialized) {
294
- const { tileSize } = this.state.bitmapCogTiles;
295
-
296
- return new TileLayer(this.getSubLayerProps({
297
- id: 'tiles',
298
- }), {
299
- getTileData: this.getTiledBitmapData.bind(this),
300
- renderSubLayers: this.renderSubLayers.bind(this),
301
- updateTriggers: {
302
- getTileData: {
303
- // rasterData: urlTemplateToUpdateTrigger(rasterData),
304
- // blurredTexture,
305
- // opacity,
306
- // cogBitmapOptions,
307
- clampToTerrain,
308
- },
309
- },
310
- extent: this.state.bitmapCogTiles.cog
311
- ? this.state.bitmapCogTiles.getBoundsAsLatLon(this.state.bitmapCogTiles.cog) : null,
312
- tileSize,
313
- minZoom: this.state.minZoom,
314
- maxZoom: this.state.maxZoom,
315
- maxRequests,
316
- onTileLoad,
317
- onTileUnload,
318
- onTileError,
319
- maxCacheSize,
320
- maxCacheByteSize,
321
- refinementStrategy,
322
- });
323
- }
324
- return null;
325
- }
326
- }
@@ -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
- ```