@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,445 +0,0 @@
1
- // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
-
21
- import {
22
- Color,
23
- CompositeLayer,
24
- CompositeLayerProps,
25
- DefaultProps,
26
- Layer,
27
- LayersList,
28
- log,
29
- Material,
30
- TextureSource,
31
- UpdateParameters,
32
- COORDINATE_SYSTEM,
33
- } from '@deck.gl/core';
34
- import { SimpleMeshLayer } from '@deck.gl/mesh-layers';
35
- import type { MeshAttributes } from '@loaders.gl/schema';
36
- import {
37
- TileLayer, TileLayerProps, GeoBoundingBox, _TileLoadProps as TileLoadProps,
38
- _Tile2DHeader as Tile2DHeader, _getURLFromTemplate as getURLFromTemplate, NonGeoBoundingBox,
39
- } from '@deck.gl/geo-layers';
40
-
41
- import CogTiles from '../cogtiles/cogtiles.ts';
42
-
43
- export type Bounds = [minX: number, minY: number, maxX: number, maxY: number];
44
-
45
- export type TileBoundingBox = NonGeoBoundingBox | GeoBoundingBox;
46
-
47
- export type ZRange = [minZ: number, maxZ: number];
48
-
49
- export type URLTemplate = string | string[] | null;
50
-
51
- export const urlType = {
52
- type: 'object' as const,
53
- value: null as URLTemplate,
54
- validate: (value, propType) => (propType.optional && value === null)
55
- || typeof value === 'string'
56
- || (Array.isArray(value) && value.every((url) => typeof url === 'string')),
57
- equal: (value1, value2) => {
58
- if (value1 === value2) {
59
- return true;
60
- }
61
- if (!Array.isArray(value1) || !Array.isArray(value2)) {
62
- return false;
63
- }
64
- const len = value1.length;
65
- if (len !== value2.length) {
66
- return false;
67
- }
68
- for (let i = 0; i < len; i++) {
69
- if (value1[i] !== value2[i]) {
70
- return false;
71
- }
72
- }
73
- return true;
74
- },
75
- };
76
-
77
- const DUMMY_DATA = [1];
78
-
79
- const defaultProps: DefaultProps<TerrainLayerProps> = {
80
- ...TileLayer.defaultProps,
81
- // Image url that encodes height data
82
- elevationData: urlType,
83
- // Image url to use as texture
84
- texture: { ...urlType, optional: true },
85
- // Martini error tolerance in meters, smaller number -> more detailed mesh
86
- meshMaxError: { type: 'number', value: 4.0 },
87
- // Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates
88
- bounds: {
89
- type: 'array', value: null, optional: true, compare: true,
90
- },
91
- // Color to use if texture is unavailable
92
- color: { type: 'color', value: [255, 255, 255] },
93
- // Object to decode height data, from (r, g, b) to height in meters
94
- elevationDecoder: {
95
- type: 'object',
96
- value: {
97
- rScaler: 1,
98
- gScaler: 0,
99
- bScaler: 0,
100
- offset: 0,
101
- },
102
- },
103
- // Supply url to local terrain worker bundle. Only required if running offline and cannot access CDN.
104
- workerUrl: '',
105
- // Same as SimpleMeshLayer wireframe
106
- wireframe: false,
107
- material: true,
108
-
109
- // loaders: [TerrainLoader],
110
- };
111
-
112
- // Turns array of templates into a single string to work around shallow change
113
- function urlTemplateToUpdateTrigger(template: URLTemplate): string {
114
- if (Array.isArray(template)) {
115
- return template.join(';');
116
- }
117
- return template || '';
118
- }
119
-
120
- type ElevationDecoder = {rScaler: number; gScaler: number; bScaler: number; offset: number};
121
- type TerrainLoadProps = {
122
- bounds: Bounds;
123
- elevationData: string | null;
124
- elevationDecoder: ElevationDecoder;
125
- meshMaxError: number;
126
- signal?: AbortSignal;
127
- };
128
-
129
- type MeshAndTexture = [MeshAttributes | null, TextureSource | null];
130
-
131
- /** All properties supported by TerrainLayer */
132
- export type TerrainLayerProps = _TerrainLayerProps &
133
- TileLayerProps<MeshAndTexture> &
134
- CompositeLayerProps;
135
-
136
- /** Props added by the TerrainLayer */
137
- type _TerrainLayerProps = {
138
- /** Image url that encodes height data. * */
139
- elevationData: URLTemplate;
140
-
141
- /** Image url to use as texture. * */
142
- texture?: URLTemplate;
143
-
144
- /** Martini error tolerance in meters, smaller number -> more detailed mesh. * */
145
- meshMaxError?: number;
146
-
147
- /** Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates. * */
148
- bounds?: Bounds | null;
149
-
150
- /** Color to use if texture is unavailable. * */
151
- color?: Color;
152
-
153
- /** Object to decode height data, from (r, g, b) to height in meters. * */
154
- elevationDecoder?: ElevationDecoder;
155
-
156
- /** Whether to render the mesh in wireframe mode. * */
157
- wireframe?: boolean;
158
-
159
- /** Material props for lighting effect. * */
160
- material?: Material;
161
-
162
- /**
163
- * TODO
164
- */
165
- terrainOptions: Object
166
-
167
- /**
168
- * @deprecated Use `loadOptions.terrain.workerUrl` instead
169
- */
170
- workerUrl?: string;
171
- };
172
-
173
- // TODO remove elevationDecoder
174
- // TODO use meshMaxError
175
- // TODO - pass signal to getTile
176
-
177
- /** Render mesh surfaces from height map images. */
178
- export default class TerrainLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<
179
- ExtraPropsT & Required<_TerrainLayerProps & Required<TileLayerProps<MeshAndTexture>>>
180
- > {
181
- static defaultProps = defaultProps;
182
-
183
- static layerName = 'TerrainLayer';
184
-
185
- // terrainCogTiles: CogTiles;
186
-
187
- terrainUrl: string;
188
-
189
- state!: {
190
- isTiled?: boolean;
191
- terrain?: MeshAttributes;
192
- zRange?: ZRange | null;
193
- minZoom: number;
194
- maxZoom: number;
195
- };
196
-
197
- async initializeState(context: any) {
198
- super.initializeState(context);
199
-
200
- this.setState({
201
- terrainCogTiles: new CogTiles(this.props.terrainOptions),
202
- initialized: false,
203
- });
204
-
205
- await this.init(this.terrainUrl);
206
- }
207
-
208
- async init(terrainUrl: string) {
209
- const cog = await this.state.terrainCogTiles.initializeCog(this.props.elevationData);
210
- // this.tileSize = this.terrainCogTiles.getTileSize(cog);
211
-
212
- const zoomRange = this.state.terrainCogTiles.getZoomRange(cog);
213
-
214
- const [minZoom, maxZoom] = zoomRange;
215
-
216
- this.setState({ initialized: true, minZoom, maxZoom });
217
- }
218
-
219
- updateState({ props, oldProps }: UpdateParameters<this>): void {
220
- const elevationDataChanged = props.elevationData !== oldProps.elevationData;
221
- if (elevationDataChanged) {
222
- const { elevationData } = props;
223
- const isTiled = elevationData
224
- && (Array.isArray(elevationData)
225
- || (elevationData.includes('{x}') && elevationData.includes('{y}'))) || this.props.isTiled;
226
- this.setState({ isTiled });
227
- }
228
-
229
- // Reloading for single terrain mesh
230
- const shouldReload = elevationDataChanged
231
- || props.meshMaxError !== oldProps.meshMaxError
232
- || props.elevationDecoder !== oldProps.elevationDecoder
233
- || props.bounds !== oldProps.bounds;
234
-
235
- if (!this.state.isTiled && shouldReload) {
236
- // When state.isTiled, elevationData cannot be an array
237
- // const terrain = this.loadTerrain(props as TerrainLoadProps);
238
- // this.setState({ terrain });
239
- }
240
-
241
- // TODO - remove in v9
242
- // @ts-ignore
243
- if (props.workerUrl) {
244
- log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
245
- }
246
- }
247
-
248
- loadTerrain({
249
- elevationData,
250
- bounds,
251
- elevationDecoder,
252
- meshMaxError,
253
- signal,
254
- }: TerrainLoadProps): Promise<MeshAttributes> | null {
255
- if (!elevationData) {
256
- return null;
257
- }
258
- let loadOptions = this.getLoadOptions();
259
- loadOptions = {
260
- ...loadOptions,
261
- _workerType: 'test',
262
- terrain: {
263
- skirtHeight: this.state.isTiled ? meshMaxError * 2 : 0,
264
- ...loadOptions?.terrain,
265
- bounds,
266
- meshMaxError,
267
- elevationDecoder,
268
- },
269
- };
270
- const { fetch } = this.props;
271
-
272
- return fetch(elevationData, {
273
- propName: 'elevationData', layer: this, loadOptions, signal, loaders: [],
274
- });
275
- }
276
-
277
- async getTiledTerrainData(tile: TileLoadProps): Promise<MeshAndTexture> {
278
- const {
279
- elevationData, fetch, texture, elevationDecoder, meshMaxError,
280
- } = this.props;
281
- const { viewport } = this.context;
282
- // const dataUrl = getURLFromTemplate(elevationData, tile);
283
- // const textureUrl = texture && getURLFromTemplate(texture, tile);
284
-
285
- const { signal } = tile;
286
- let bottomLeft = [0, 0] as [number, number];
287
- let topRight = [0, 0] as [number, number];
288
- if (viewport.isGeospatial) {
289
- const bbox = tile.bbox as GeoBoundingBox;
290
-
291
- bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
292
- topRight = viewport.projectFlat([bbox.east, bbox.north]);
293
- } else {
294
- const bbox = tile.bbox as Exclude<TileBoundingBox, GeoBoundingBox>;
295
- bottomLeft = [bbox.left, bbox.bottom];
296
- topRight = [bbox.right, bbox.top];
297
- }
298
- const bounds: Bounds = [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
299
-
300
- // TODO - pass signal to getTile
301
- // abort request if signal is aborted
302
- const terrain = await this.state.terrainCogTiles.getTile(
303
- tile.index.x,
304
- tile.index.y,
305
- tile.index.z,
306
- bounds,
307
- this.props.meshMaxError,
308
- );
309
-
310
- return Promise.all([terrain]);
311
- }
312
-
313
- renderSubLayers(
314
- props: TileLayerProps<MeshAndTexture> & {
315
- id: string;
316
- data: MeshAndTexture;
317
- tile: Tile2DHeader<MeshAndTexture>;
318
- },
319
- ) {
320
- const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
321
-
322
- const { color, wireframe, material } = this.props;
323
- const { data } = props;
324
-
325
- if (!data) {
326
- return null;
327
- }
328
-
329
- // const [mesh, texture] = data;
330
- const [mesh] = data;
331
-
332
- return new SubLayerClass({ ...props, tileSize: 256 }, {
333
- data: DUMMY_DATA,
334
- mesh,
335
- // texture,
336
- _instanced: false,
337
- coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
338
- getPosition: (d) => [0, 0, 0],
339
- getColor: color,
340
- wireframe,
341
- material,
342
- });
343
- }
344
-
345
- // Update zRange of viewport
346
- onViewportLoad(tiles?: Tile2DHeader<MeshAndTexture>[]): void {
347
- if (!tiles) {
348
- return;
349
- }
350
-
351
- const { zRange } = this.state;
352
- const ranges = tiles
353
- .map((tile) => tile.content)
354
- .filter((x) => x && x[0])
355
- .map((arr) => {
356
- // @ts-ignore
357
- const bounds = arr[0]?.header?.boundingBox;
358
- return bounds?.map((bound) => bound[2]);
359
- });
360
- if (ranges.length === 0) {
361
- return;
362
- }
363
- const minZ = Math.min(...ranges.map((x) => x[0]));
364
- const maxZ = Math.max(...ranges.map((x) => x[1]));
365
-
366
- if (!zRange || minZ < zRange[0] || maxZ > zRange[1]) {
367
- this.setState({ zRange: [Number.isFinite(minZ) ? minZ : 0, Number.isFinite(maxZ) ? maxZ : 0] });
368
- }
369
- }
370
-
371
- renderLayers(): Layer | null | LayersList {
372
- const {
373
- color,
374
- material,
375
- elevationData,
376
- texture,
377
- wireframe,
378
- meshMaxError,
379
- elevationDecoder,
380
- tileSize,
381
- extent,
382
- maxRequests,
383
- onTileLoad,
384
- onTileUnload,
385
- onTileError,
386
- maxCacheSize,
387
- maxCacheByteSize,
388
- refinementStrategy,
389
- } = this.props;
390
-
391
- if (this.state.isTiled && this.state.initialized) {
392
- return new TileLayer<MeshAndTexture>(
393
- this.getSubLayerProps({
394
- id: 'tiles',
395
- }),
396
- {
397
- getTileData: this.getTiledTerrainData.bind(this),
398
- renderSubLayers: this.renderSubLayers.bind(this),
399
- updateTriggers: {
400
- getTileData: {
401
- elevationData: urlTemplateToUpdateTrigger(elevationData),
402
- // texture: urlTemplateToUpdateTrigger(texture),
403
- meshMaxError,
404
- elevationDecoder,
405
- },
406
- },
407
- onViewportLoad: this.onViewportLoad.bind(this),
408
- zRange: this.state.zRange || null,
409
- tileSize,
410
- minZoom: this.state.minZoom,
411
- maxZoom: this.state.maxZoom,
412
- extent,
413
- maxRequests,
414
- onTileLoad,
415
- onTileUnload,
416
- onTileError,
417
- maxCacheSize,
418
- maxCacheByteSize,
419
- refinementStrategy,
420
- },
421
- );
422
- }
423
-
424
- // if (!elevationData) {
425
- // return null;
426
- // }
427
-
428
- // const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
429
- // return new SubLayerClass(
430
- // this.getSubLayerProps({
431
- // id: 'mesh',
432
- // }),
433
- // {
434
- // data: DUMMY_DATA,
435
- // mesh: this.state.terrain,
436
- // texture,
437
- // _instanced: false,
438
- // getPosition: (d) => [0, 0, 0],
439
- // getColor: color,
440
- // material,
441
- // wireframe,
442
- // },
443
- // );
444
- }
445
- }
@@ -1,118 +0,0 @@
1
- # CogTerrainLayer
2
-
3
- A Deck.gl-compatible layer for loading and displaying tiled COG height data
4
-
5
- ## Features
6
-
7
- ### Tiled terrain rendering
8
- - Dynamically load and render tiled COG height data
9
- - Overlay another COG as a bitmap, or supply a tile service template url.
10
- ### Data visualization
11
- - Multiply terrain height
12
- - Clamp COG data on top of generated terrain
13
- - Set visualization styling, colors, use heatmap, set data bounds, and more
14
-
15
- ## Usage
16
- ### Initialize the layer
17
- To create CogTerrainLayer, you need an URL of your COG and also an object containing [geoimage](../geoimage/README.md) options for data processing.
18
- For this layer, only needed terrain options are `type`, and optionally `multiplier`, `terrainSkirtHeight`, `terrainMinValue`.
19
-
20
- You can also specify another COG as an overlay, and it's corresponding options, or just supply a tile service template url. Overlay options use all of [geoimage](../geoimage/README.md) options and work only with COG
21
-
22
- ### Example
23
- Import package into project and create terrain layer
24
-
25
- ```typescript
26
- import geolib from '@gisatcz/deckgl-geolib';
27
-
28
- const CogTerrainLayer = geolib.CogTerrainLayer;
29
- ```
30
- Display simple terrain
31
- ```typescript
32
- const cogLayer = new CogTerrainLayer(
33
- id: 'cog_terrain_name',
34
- elevationData: 'cog_terrain_data_url.tif',
35
- isTiled: true,
36
- tileSize: 256,
37
- operation: 'terrain+draw',
38
- terrainOptions: {
39
- type: 'terrain',
40
- }
41
- );
42
- ```
43
-
44
- <img src = "/images/cogTerrainLayer.jpg" width = "50%" alt="COG terrain visualization.">
45
-
46
- Display multiplied terrain with custom skirt height
47
- (height of individual tiles edges, so there are no white spaces between individual 3D tiles) and defined minimal terrain value.
48
- ```typescript
49
- const cogLayer = new CogTerrainLayer(
50
- id: 'cog_terrain_name',
51
- elevationData: 'cog_terrain_data_url.tif',
52
- isTiled: true,
53
- tileSize: 256,
54
- operation: 'terrain+draw',
55
- terrainOptions: {
56
- type: 'terrain',
57
- multiplier: 1,
58
- terrainSkirtHeight: 1,
59
- terrainMinValue: 200,
60
- }
61
- );
62
- ```
63
- Adjust `meshMaxError`: Martini error tolerance in meters, smaller number -> more detailed mesh, **(default 4.0)**.
64
- ```typescript
65
- const cogLayer = new CogTerrainLayer(
66
- id: 'cog_terrain_name',
67
- elevationData: 'cog_terrain_data_url.tif',
68
- isTiled: true,
69
- useChannel: null,
70
- tileSize: 256,
71
- meshMaxError: 1,
72
- operation: 'terrain+draw',
73
- terrainOptions: {
74
- type: 'terrain',
75
- }
76
- );
77
- ```
78
-
79
- [//]: # (TODO check if useChannel works properly)
80
- Adjust `opacity` and display second channel.
81
- ```typescript
82
- const cogLayer = new CogTerrainLayer(
83
- id: 'cog_terrain_name',
84
- elevationData: 'cog_terrain_data_url.tif',
85
- opacity: 0.5,
86
- isTiled: true,
87
- useChannel: 1,
88
- tileSize: 256,
89
- meshMaxError: 1,
90
- operation: 'terrain+draw',
91
- terrainOptions: {
92
- type: 'terrain',
93
- }
94
- );
95
- ```
96
-
97
- [//]: # (TODO update overlay generation)
98
-
99
- Display terrain with tile service overlay
100
- ```typescript
101
- const cogLayer = new CogTerrainLayer(
102
- 'cog_data_url.tif',
103
- {type:'terrain'},
104
- 'tile-service.com/{z}/{x}/{y}.png'
105
- )
106
- ```
107
-
108
- <img src = "/images/cogTerrainLayer_overlay.jpg" width = "50%" alt="COG terrain visualization with satellite imagery overlay.">
109
-
110
- Display terrain with stylized COG overlay
111
- ```typescript
112
- const cogLayer = new CogTerrainLayer(
113
- 'cog.tif',
114
- {type:'terrain'},
115
- 'cog-overlay.tif',
116
- {type:'image', useHeatMap:true, useChannel:2}
117
- )
118
- ```
@@ -1,72 +0,0 @@
1
- # COG Tiles
2
-
3
-
4
-
5
- ##### A Javascript library for easier tile functionality with COG files
6
-
7
-
8
-
9
- ### Features
10
-
11
- Class allows using CogTiff files with Deck.gl TileLayer.
12
-
13
- Provides extra functionality for CogTiff files
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- ### Methods
24
-
25
-
26
-
27
- `async initializeCog(url : string)`- returns a cog from a given URL and initializes object variables
28
-
29
-
30
-
31
- `async getTile(x: number, y: number, z: number)` - returns a promise, when resolved returns a tile. `x, y, z ` are coordinates in tile grid
32
-
33
-
34
-
35
- `getTileSize(CogTiff)` - returns `number` containing the width of a single tile
36
-
37
-
38
-
39
- `getZoomRange(cog:CogTiff)` - returns` [minZoom, maxZoom]`
40
-
41
-
42
-
43
- `getBoundsAsLatLon(cog:CogTiff)` - returns image bounds as `[left, bottom, right, top]`
44
-
45
-
46
-
47
- `getOriginAsLatLon(cog:CogTiff)`- returns origin of COG as `[x, y]`
48
-
49
-
50
-
51
- `getImageTileIndex(img:CogTiffImage)` - returns index of an image from COG in tile system as`[x, y, z]`
52
-
53
-
54
-
55
- `getResolutionFromZoomLevel`- returns `number` in meters per pixel
56
-
57
-
58
-
59
- `getZoomLevelFromResolution(tileSize: number, resolution: number)` returns `number` zoom level calculated from `resolution` (the size of one pixel in meters) and `tileSize` (width of a tile)
60
-
61
-
62
-
63
- `getLatLon` - returns `[latitude, longitude]` from offset in meters
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-