@gisatcz/deckgl-geolib 1.11.0-dev.1 → 1.11.0-dev.3
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.
- package/dist/cjs/index.js +173 -48
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +3 -3
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/types/cogbitmaplayer/CogBitmapLayer.d.ts +78 -32
- package/dist/esm/index.js +173 -48
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +4 -4
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/types/cogbitmaplayer/CogBitmapLayer.d.ts +78 -32
- package/package.json +1 -1
- package/src/cogbitmaplayer/CogBitmapLayer.ts +309 -78
|
@@ -1,42 +1,88 @@
|
|
|
1
|
-
import { CompositeLayer } from '@deck.gl/core';
|
|
2
|
-
import { TileLayer } from '@deck.gl/geo-layers';
|
|
1
|
+
import { CompositeLayer, CompositeLayerProps, DefaultProps, TextureSource, UpdateParameters } from '@deck.gl/core';
|
|
2
|
+
import { _Tile2DHeader as Tile2DHeader, _TileLoadProps as TileLoadProps, GeoBoundingBox, NonGeoBoundingBox, TileLayer, TileLayerProps } from '@deck.gl/geo-layers';
|
|
3
3
|
import { BitmapLayer } from '@deck.gl/layers';
|
|
4
|
-
import {
|
|
5
|
-
import CogTiles from '../cogtiles/cogtiles.ts';
|
|
4
|
+
import type { MeshAttributes } from '@loaders.gl/schema';
|
|
6
5
|
import { GeoImageOptions } from '../geoimage/geoimage.ts';
|
|
7
|
-
|
|
6
|
+
export type TileBoundingBox = NonGeoBoundingBox | GeoBoundingBox;
|
|
7
|
+
export type ZRange = [minZ: number, maxZ: number];
|
|
8
|
+
export type Bounds = [minX: number, minY: number, maxX: number, maxY: number];
|
|
9
|
+
export type URLTemplate = string | string[] | null;
|
|
10
|
+
export declare const urlType: {
|
|
11
|
+
type: "object";
|
|
12
|
+
value: URLTemplate;
|
|
13
|
+
validate: (value: any, propType: any) => boolean;
|
|
14
|
+
equal: (value1: any, value2: any) => boolean;
|
|
15
|
+
};
|
|
16
|
+
export type ClampToTerrainOptions = {
|
|
17
|
+
terrainDrawMode?: string;
|
|
18
|
+
};
|
|
19
|
+
type MeshAndTexture = [MeshAttributes | null, TextureSource | null];
|
|
20
|
+
/** All properties supported by CogBitmapLayer */
|
|
21
|
+
export type CogBitmapLayerProps = _CogBitmapLayerProps & TileLayerProps<MeshAndTexture> & CompositeLayerProps;
|
|
22
|
+
/** Props added by the CogBitmapLayer */
|
|
23
|
+
type _CogBitmapLayerProps = {
|
|
24
|
+
/** Image url that encodes raster data. * */
|
|
25
|
+
rasterData: URLTemplate;
|
|
26
|
+
/** Bounding box of the bitmap image, [minX, minY, maxX, maxY] in world coordinates. * */
|
|
27
|
+
bounds: Bounds | null;
|
|
28
|
+
/** Whether the rendered texture should be blurred or not - effects minFilter and maxFilter * */
|
|
29
|
+
blurredTexture?: boolean;
|
|
30
|
+
/** Weather visualise the entire image with specified opacity (0-1) * */
|
|
31
|
+
opacity?: number;
|
|
32
|
+
/** Whether the rendered texture should be clamped to terrain * */
|
|
33
|
+
clampToTerrain?: ClampToTerrainOptions | boolean;
|
|
34
|
+
/**
|
|
35
|
+
* TODO
|
|
36
|
+
*/
|
|
37
|
+
cogBitmapOptions: GeoImageOptions;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `loadOptions.terrain.workerUrl` instead
|
|
40
|
+
*/
|
|
41
|
+
workerUrl?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Render bitmap texture from cog raster images. */
|
|
44
|
+
export default class CogBitmapLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<ExtraPropsT & Required<_CogBitmapLayerProps & Required<TileLayerProps<MeshAndTexture>>>> {
|
|
45
|
+
static defaultProps: DefaultProps<CogBitmapLayerProps>;
|
|
8
46
|
static layerName: string;
|
|
9
|
-
|
|
10
|
-
url: string;
|
|
11
|
-
static displayName: string;
|
|
12
|
-
cogTiles: CogTiles;
|
|
13
|
-
tileSize: number;
|
|
47
|
+
rasterUrl: string;
|
|
14
48
|
minZoom: number;
|
|
15
49
|
maxZoom: number;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
50
|
+
state: {
|
|
51
|
+
isTiled?: boolean;
|
|
52
|
+
terrain?: MeshAttributes;
|
|
53
|
+
zRange?: ZRange | null;
|
|
54
|
+
};
|
|
55
|
+
initializeState(context: any): Promise<void>;
|
|
56
|
+
init(rasterUrl: string): Promise<void>;
|
|
57
|
+
updateState({ props, oldProps }: UpdateParameters<this>): void;
|
|
58
|
+
getTiledBitmapData(tile: TileLoadProps): Promise<TextureSource>;
|
|
59
|
+
renderSubLayers(props: TileLayerProps<TextureSource> & {
|
|
60
|
+
id: string;
|
|
61
|
+
data: TextureSource;
|
|
62
|
+
tile: Tile2DHeader<TextureSource>;
|
|
63
|
+
}): BitmapLayer<{}>;
|
|
20
64
|
renderLayers(): TileLayer<any, {
|
|
21
|
-
|
|
22
|
-
|
|
65
|
+
getTileData: any;
|
|
66
|
+
renderSubLayers: any;
|
|
67
|
+
updateTriggers: {
|
|
68
|
+
getTileData: {
|
|
69
|
+
rasterData: string;
|
|
70
|
+
blurredTexture: boolean;
|
|
71
|
+
opacity: number;
|
|
72
|
+
clampToTerrain: boolean | ClampToTerrainOptions;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
extent: any;
|
|
76
|
+
tileSize: number;
|
|
23
77
|
minZoom: number;
|
|
24
78
|
maxZoom: number;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
bounds: [any, any, any, any];
|
|
33
|
-
opacity: number;
|
|
34
|
-
textureParameters: {
|
|
35
|
-
minFilter: "linear" | "nearest";
|
|
36
|
-
magFilter: "linear" | "nearest";
|
|
37
|
-
};
|
|
38
|
-
extensions: TerrainExtension[];
|
|
39
|
-
}>;
|
|
79
|
+
maxRequests: number;
|
|
80
|
+
onTileLoad: (tile: Tile2DHeader<MeshAndTexture>) => void;
|
|
81
|
+
onTileUnload: (tile: Tile2DHeader<MeshAndTexture>) => void;
|
|
82
|
+
onTileError: (err: any, tile?: any) => void;
|
|
83
|
+
maxCacheSize: number;
|
|
84
|
+
maxCacheByteSize: number;
|
|
85
|
+
refinementStrategy: import("node_modules/@deck.gl/geo-layers/dist/tileset-2d/tileset-2d.js").RefinementStrategy;
|
|
40
86
|
}>;
|
|
41
87
|
}
|
|
42
|
-
export
|
|
88
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -15467,68 +15467,193 @@ class CogTiles {
|
|
|
15467
15467
|
}
|
|
15468
15468
|
}
|
|
15469
15469
|
|
|
15470
|
-
|
|
15471
|
-
|
|
15470
|
+
const urlType$1 = {
|
|
15471
|
+
type: 'object',
|
|
15472
|
+
value: null,
|
|
15473
|
+
validate: (value, propType) => (propType.optional && value === null)
|
|
15474
|
+
|| typeof value === 'string'
|
|
15475
|
+
|| (Array.isArray(value) && value.every((url) => typeof url === 'string')),
|
|
15476
|
+
equal: (value1, value2) => {
|
|
15477
|
+
if (value1 === value2) {
|
|
15478
|
+
return true;
|
|
15479
|
+
}
|
|
15480
|
+
if (!Array.isArray(value1) || !Array.isArray(value2)) {
|
|
15481
|
+
return false;
|
|
15482
|
+
}
|
|
15483
|
+
const len = value1.length;
|
|
15484
|
+
if (len !== value2.length) {
|
|
15485
|
+
return false;
|
|
15486
|
+
}
|
|
15487
|
+
for (let i = 0; i < len; i++) {
|
|
15488
|
+
if (value1[i] !== value2[i]) {
|
|
15489
|
+
return false;
|
|
15490
|
+
}
|
|
15491
|
+
}
|
|
15492
|
+
return true;
|
|
15493
|
+
},
|
|
15494
|
+
};
|
|
15495
|
+
const defaultProps$1 = Object.assign(Object.assign({}, TileLayer.defaultProps), {
|
|
15496
|
+
// Image url that encodes height data
|
|
15497
|
+
// elevationData: urlType,
|
|
15498
|
+
// Image url to use as texture
|
|
15499
|
+
// texture: { ...urlType, optional: true },
|
|
15500
|
+
// Martini error tolerance in meters, smaller number -> more detailed mesh
|
|
15501
|
+
// meshMaxError: { type: 'number', value: 4.0 },
|
|
15502
|
+
// Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates
|
|
15503
|
+
bounds: {
|
|
15504
|
+
type: 'array', value: null, optional: true, compare: true,
|
|
15505
|
+
}, rasterData: urlType$1,
|
|
15506
|
+
// Color to use if texture is unavailable
|
|
15507
|
+
// color: { type: 'color', value: [255, 255, 255] },
|
|
15508
|
+
blurredTexture: true, opacity: 1, clampToTerrain: false,
|
|
15509
|
+
// Object to decode height data, from (r, g, b) to height in meters
|
|
15510
|
+
// elevationDecoder: {
|
|
15511
|
+
// type: 'object',
|
|
15512
|
+
// value: {
|
|
15513
|
+
// rScaler: 1,
|
|
15514
|
+
// gScaler: 0,
|
|
15515
|
+
// bScaler: 0,
|
|
15516
|
+
// offset: 0,
|
|
15517
|
+
// },
|
|
15518
|
+
// },
|
|
15519
|
+
// Supply url to local terrain worker bundle. Only required if running offline and cannot access CDN.
|
|
15520
|
+
workerUrl: '' });
|
|
15521
|
+
// Turns array of templates into a single string to work around shallow change
|
|
15522
|
+
function urlTemplateToUpdateTrigger$1(template) {
|
|
15523
|
+
if (Array.isArray(template)) {
|
|
15524
|
+
return template.join(';');
|
|
15525
|
+
}
|
|
15526
|
+
return template || '';
|
|
15527
|
+
}
|
|
15528
|
+
/** Render bitmap texture from cog raster images. */
|
|
15472
15529
|
class CogBitmapLayer extends CompositeLayer {
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
|
|
15477
|
-
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
// this.init(url);
|
|
15487
|
-
// }, 500);
|
|
15488
|
-
}
|
|
15489
|
-
initializeState() {
|
|
15490
|
-
this.state = {
|
|
15491
|
-
initialized: false,
|
|
15492
|
-
};
|
|
15493
|
-
this.init(this.url);
|
|
15494
|
-
}
|
|
15495
|
-
init(url) {
|
|
15530
|
+
// private _isLoaded: boolean;
|
|
15531
|
+
// id = '';
|
|
15532
|
+
// url: string;
|
|
15533
|
+
// static displayName: string;
|
|
15534
|
+
// cogTiles: CogTiles;
|
|
15535
|
+
//
|
|
15536
|
+
// tileSize: number;
|
|
15537
|
+
//
|
|
15538
|
+
// blurredTexture: boolean;
|
|
15539
|
+
initializeState(context) {
|
|
15540
|
+
const _super = Object.create(null, {
|
|
15541
|
+
initializeState: { get: () => super.initializeState }
|
|
15542
|
+
});
|
|
15496
15543
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15497
|
-
|
|
15498
|
-
this.setState({
|
|
15499
|
-
|
|
15500
|
-
|
|
15544
|
+
_super.initializeState.call(this, context);
|
|
15545
|
+
this.setState({
|
|
15546
|
+
bitmapCogTiles: new CogTiles(this.props.cogBitmapOptions),
|
|
15547
|
+
initialized: false,
|
|
15548
|
+
});
|
|
15549
|
+
yield this.init(this.rasterUrl);
|
|
15550
|
+
});
|
|
15551
|
+
}
|
|
15552
|
+
init(rasterUrl) {
|
|
15553
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15554
|
+
const cog = yield this.state.bitmapCogTiles.initializeCog(this.props.rasterData);
|
|
15555
|
+
// this.tileSize = this.terrainCogTiles.getTileSize(cog);
|
|
15556
|
+
const zoomRange = this.state.bitmapCogTiles.getZoomRange(cog);
|
|
15501
15557
|
[this.minZoom, this.maxZoom] = zoomRange;
|
|
15558
|
+
this.setState({ initialized: true });
|
|
15559
|
+
});
|
|
15560
|
+
}
|
|
15561
|
+
updateState({ props, oldProps }) {
|
|
15562
|
+
const rasterDataChanged = props.rasterData !== oldProps.rasterData;
|
|
15563
|
+
if (rasterDataChanged) {
|
|
15564
|
+
const { rasterData } = props;
|
|
15565
|
+
const isTiled = rasterData
|
|
15566
|
+
&& (Array.isArray(rasterData)
|
|
15567
|
+
|| (rasterData.includes('{x}') && rasterData.includes('{y}'))) || this.props.isTiled;
|
|
15568
|
+
this.setState({ isTiled });
|
|
15569
|
+
}
|
|
15570
|
+
// Reloading for single terrain mesh
|
|
15571
|
+
const shouldReload = rasterDataChanged
|
|
15572
|
+
// || props.meshMaxError !== oldProps.meshMaxError
|
|
15573
|
+
// || props.elevationDecoder !== oldProps.elevationDecoder
|
|
15574
|
+
|| props.bounds !== oldProps.bounds;
|
|
15575
|
+
if (!this.state.isTiled && shouldReload) ;
|
|
15576
|
+
// TODO - remove in v9
|
|
15577
|
+
// @ts-ignore
|
|
15578
|
+
if (props.workerUrl) {
|
|
15579
|
+
log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
|
|
15580
|
+
}
|
|
15581
|
+
}
|
|
15582
|
+
getTiledBitmapData(tile) {
|
|
15583
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15584
|
+
// const {
|
|
15585
|
+
// rasterData, fetch,
|
|
15586
|
+
// } = this.props;
|
|
15587
|
+
const { viewport } = this.context;
|
|
15588
|
+
let bottomLeft = [0, 0];
|
|
15589
|
+
let topRight = [0, 0];
|
|
15590
|
+
if (viewport.isGeospatial) {
|
|
15591
|
+
const bbox = tile.bbox;
|
|
15592
|
+
bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
|
|
15593
|
+
topRight = viewport.projectFlat([bbox.east, bbox.north]);
|
|
15594
|
+
}
|
|
15595
|
+
else {
|
|
15596
|
+
const bbox = tile.bbox;
|
|
15597
|
+
bottomLeft = [bbox.left, bbox.bottom];
|
|
15598
|
+
topRight = [bbox.right, bbox.top];
|
|
15599
|
+
}
|
|
15600
|
+
[bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
|
|
15601
|
+
// TODO - pass signal to getTile
|
|
15602
|
+
// abort request if signal is aborted
|
|
15603
|
+
return yield this.state.bitmapCogTiles.getTile(tile.index.x, tile.index.y, tile.index.z);
|
|
15502
15604
|
});
|
|
15503
15605
|
}
|
|
15606
|
+
renderSubLayers(props) {
|
|
15607
|
+
const SubLayerClass = this.getSubLayerClass('image', BitmapLayer);
|
|
15608
|
+
const { blurredTexture, opacity, clampToTerrain } = this.props;
|
|
15609
|
+
const data = props.data;
|
|
15610
|
+
if (!data) {
|
|
15611
|
+
return null;
|
|
15612
|
+
}
|
|
15613
|
+
const { bbox: { west, south, east, north, }, } = props.tile;
|
|
15614
|
+
return new SubLayerClass(Object.assign(Object.assign({}, props), { tileSize: 256 }), Object.assign({ data: null, image: data, _instanced: false, bounds: [west, south, east, north], opacity, textureParameters: {
|
|
15615
|
+
minFilter: blurredTexture ? 'linear' : 'nearest',
|
|
15616
|
+
magFilter: blurredTexture ? 'linear' : 'nearest',
|
|
15617
|
+
},
|
|
15618
|
+
// TODO check if works!!!
|
|
15619
|
+
extensions: clampToTerrain ? [new _TerrainExtension()] : [] }, ((clampToTerrain === null || clampToTerrain === void 0 ? void 0 : clampToTerrain.terrainDrawMode)
|
|
15620
|
+
? { terrainDrawMode: clampToTerrain.terrainDrawMode }
|
|
15621
|
+
: {})));
|
|
15622
|
+
}
|
|
15504
15623
|
renderLayers() {
|
|
15505
|
-
|
|
15506
|
-
|
|
15507
|
-
|
|
15508
|
-
|
|
15624
|
+
const { rasterData, blurredTexture, opacity, clampToTerrain, tileSize, maxRequests, onTileLoad, onTileUnload, onTileError, maxCacheSize, maxCacheByteSize, refinementStrategy, } = this.props;
|
|
15625
|
+
if (this.state.isTiled && this.state.initialized) {
|
|
15626
|
+
return new TileLayer(this.getSubLayerProps({
|
|
15627
|
+
id: 'tiles',
|
|
15628
|
+
}), {
|
|
15629
|
+
getTileData: this.getTiledBitmapData.bind(this),
|
|
15630
|
+
renderSubLayers: this.renderSubLayers.bind(this),
|
|
15631
|
+
updateTriggers: {
|
|
15632
|
+
getTileData: {
|
|
15633
|
+
rasterData: urlTemplateToUpdateTrigger$1(rasterData),
|
|
15634
|
+
blurredTexture,
|
|
15635
|
+
opacity,
|
|
15636
|
+
clampToTerrain,
|
|
15637
|
+
},
|
|
15638
|
+
},
|
|
15639
|
+
extent: this.state.bitmapCogTiles.cog ? this.state.bitmapCogTiles.getBoundsAsLatLon(this.state.bitmapCogTiles.cog) : null,
|
|
15640
|
+
tileSize,
|
|
15509
15641
|
minZoom: this.minZoom,
|
|
15510
15642
|
maxZoom: this.maxZoom,
|
|
15511
|
-
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
minFilter: this.blurredTexture ? 'linear' : 'nearest',
|
|
15519
|
-
magFilter: this.blurredTexture ? 'linear' : 'nearest',
|
|
15520
|
-
}, extensions: ((_b = (_a = this.cogTiles) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.clampToTerrain) ? [new _TerrainExtension()] : [] }, (((_e = (_d = (_c = this.cogTiles) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.clampToTerrain) === null || _e === void 0 ? void 0 : _e.terrainDrawMode)
|
|
15521
|
-
? { terrainDrawMode: (_g = (_f = this.cogTiles) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.clampToTerrain.terrainDrawMode }
|
|
15522
|
-
: {})));
|
|
15523
|
-
},
|
|
15643
|
+
maxRequests,
|
|
15644
|
+
onTileLoad,
|
|
15645
|
+
onTileUnload,
|
|
15646
|
+
onTileError,
|
|
15647
|
+
maxCacheSize,
|
|
15648
|
+
maxCacheByteSize,
|
|
15649
|
+
refinementStrategy,
|
|
15524
15650
|
});
|
|
15525
|
-
return layer;
|
|
15526
15651
|
}
|
|
15527
15652
|
return null;
|
|
15528
15653
|
}
|
|
15529
15654
|
}
|
|
15655
|
+
CogBitmapLayer.defaultProps = defaultProps$1;
|
|
15530
15656
|
CogBitmapLayer.layerName = 'CogBitmapLayer';
|
|
15531
|
-
CogBitmapLayer.displayName = 'CogBitmapLayer';
|
|
15532
15657
|
|
|
15533
15658
|
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
15534
15659
|
//
|