@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 CHANGED
@@ -15469,68 +15469,193 @@ class CogTiles {
15469
15469
  }
15470
15470
  }
15471
15471
 
15472
- // let needsRerender: boolean = false;
15473
- // let extent = [0, 0, 0, 0]
15472
+ const urlType$1 = {
15473
+ type: 'object',
15474
+ value: null,
15475
+ validate: (value, propType) => (propType.optional && value === null)
15476
+ || typeof value === 'string'
15477
+ || (Array.isArray(value) && value.every((url) => typeof url === 'string')),
15478
+ equal: (value1, value2) => {
15479
+ if (value1 === value2) {
15480
+ return true;
15481
+ }
15482
+ if (!Array.isArray(value1) || !Array.isArray(value2)) {
15483
+ return false;
15484
+ }
15485
+ const len = value1.length;
15486
+ if (len !== value2.length) {
15487
+ return false;
15488
+ }
15489
+ for (let i = 0; i < len; i++) {
15490
+ if (value1[i] !== value2[i]) {
15491
+ return false;
15492
+ }
15493
+ }
15494
+ return true;
15495
+ },
15496
+ };
15497
+ const defaultProps$1 = Object.assign(Object.assign({}, geoLayers.TileLayer.defaultProps), {
15498
+ // Image url that encodes height data
15499
+ // elevationData: urlType,
15500
+ // Image url to use as texture
15501
+ // texture: { ...urlType, optional: true },
15502
+ // Martini error tolerance in meters, smaller number -> more detailed mesh
15503
+ // meshMaxError: { type: 'number', value: 4.0 },
15504
+ // Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates
15505
+ bounds: {
15506
+ type: 'array', value: null, optional: true, compare: true,
15507
+ }, rasterData: urlType$1,
15508
+ // Color to use if texture is unavailable
15509
+ // color: { type: 'color', value: [255, 255, 255] },
15510
+ blurredTexture: true, opacity: 1, clampToTerrain: false,
15511
+ // Object to decode height data, from (r, g, b) to height in meters
15512
+ // elevationDecoder: {
15513
+ // type: 'object',
15514
+ // value: {
15515
+ // rScaler: 1,
15516
+ // gScaler: 0,
15517
+ // bScaler: 0,
15518
+ // offset: 0,
15519
+ // },
15520
+ // },
15521
+ // Supply url to local terrain worker bundle. Only required if running offline and cannot access CDN.
15522
+ workerUrl: '' });
15523
+ // Turns array of templates into a single string to work around shallow change
15524
+ function urlTemplateToUpdateTrigger$1(template) {
15525
+ if (Array.isArray(template)) {
15526
+ return template.join(';');
15527
+ }
15528
+ return template || '';
15529
+ }
15530
+ /** Render bitmap texture from cog raster images. */
15474
15531
  class CogBitmapLayer extends core.CompositeLayer {
15475
- constructor(id, url, options) {
15476
- super({});
15477
- // private _isLoaded: boolean;
15478
- this.id = '';
15479
- this.id = id;
15480
- // this.state = {
15481
- // initialized: false,
15482
- // };
15483
- // this._isLoaded = false;
15484
- this.cogTiles = new CogTiles(options);
15485
- this.blurredTexture = options.blurredTexture;
15486
- this.url = url;
15487
- // setTimeout(() => {
15488
- // this.init(url);
15489
- // }, 500);
15490
- }
15491
- initializeState() {
15492
- this.state = {
15493
- initialized: false,
15494
- };
15495
- this.init(this.url);
15496
- }
15497
- init(url) {
15532
+ // private _isLoaded: boolean;
15533
+ // id = '';
15534
+ // url: string;
15535
+ // static displayName: string;
15536
+ // cogTiles: CogTiles;
15537
+ //
15538
+ // tileSize: number;
15539
+ //
15540
+ // blurredTexture: boolean;
15541
+ initializeState(context) {
15542
+ const _super = Object.create(null, {
15543
+ initializeState: { get: () => super.initializeState }
15544
+ });
15498
15545
  return __awaiter(this, void 0, void 0, function* () {
15499
- const cog = yield this.cogTiles.initializeCog(url);
15500
- this.setState({ initialized: true });
15501
- this.tileSize = this.cogTiles.getTileSize(cog);
15502
- const zoomRange = this.cogTiles.getZoomRange(cog);
15546
+ _super.initializeState.call(this, context);
15547
+ this.setState({
15548
+ bitmapCogTiles: new CogTiles(this.props.cogBitmapOptions),
15549
+ initialized: false,
15550
+ });
15551
+ yield this.init(this.rasterUrl);
15552
+ });
15553
+ }
15554
+ init(rasterUrl) {
15555
+ return __awaiter(this, void 0, void 0, function* () {
15556
+ const cog = yield this.state.bitmapCogTiles.initializeCog(this.props.rasterData);
15557
+ // this.tileSize = this.terrainCogTiles.getTileSize(cog);
15558
+ const zoomRange = this.state.bitmapCogTiles.getZoomRange(cog);
15503
15559
  [this.minZoom, this.maxZoom] = zoomRange;
15560
+ this.setState({ initialized: true });
15561
+ });
15562
+ }
15563
+ updateState({ props, oldProps }) {
15564
+ const rasterDataChanged = props.rasterData !== oldProps.rasterData;
15565
+ if (rasterDataChanged) {
15566
+ const { rasterData } = props;
15567
+ const isTiled = rasterData
15568
+ && (Array.isArray(rasterData)
15569
+ || (rasterData.includes('{x}') && rasterData.includes('{y}'))) || this.props.isTiled;
15570
+ this.setState({ isTiled });
15571
+ }
15572
+ // Reloading for single terrain mesh
15573
+ const shouldReload = rasterDataChanged
15574
+ // || props.meshMaxError !== oldProps.meshMaxError
15575
+ // || props.elevationDecoder !== oldProps.elevationDecoder
15576
+ || props.bounds !== oldProps.bounds;
15577
+ if (!this.state.isTiled && shouldReload) ;
15578
+ // TODO - remove in v9
15579
+ // @ts-ignore
15580
+ if (props.workerUrl) {
15581
+ core.log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
15582
+ }
15583
+ }
15584
+ getTiledBitmapData(tile) {
15585
+ return __awaiter(this, void 0, void 0, function* () {
15586
+ // const {
15587
+ // rasterData, fetch,
15588
+ // } = this.props;
15589
+ const { viewport } = this.context;
15590
+ let bottomLeft = [0, 0];
15591
+ let topRight = [0, 0];
15592
+ if (viewport.isGeospatial) {
15593
+ const bbox = tile.bbox;
15594
+ bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
15595
+ topRight = viewport.projectFlat([bbox.east, bbox.north]);
15596
+ }
15597
+ else {
15598
+ const bbox = tile.bbox;
15599
+ bottomLeft = [bbox.left, bbox.bottom];
15600
+ topRight = [bbox.right, bbox.top];
15601
+ }
15602
+ [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
15603
+ // TODO - pass signal to getTile
15604
+ // abort request if signal is aborted
15605
+ return yield this.state.bitmapCogTiles.getTile(tile.index.x, tile.index.y, tile.index.z);
15504
15606
  });
15505
15607
  }
15608
+ renderSubLayers(props) {
15609
+ const SubLayerClass = this.getSubLayerClass('image', layers.BitmapLayer);
15610
+ const { blurredTexture, opacity, clampToTerrain } = this.props;
15611
+ const data = props.data;
15612
+ if (!data) {
15613
+ return null;
15614
+ }
15615
+ const { bbox: { west, south, east, north, }, } = props.tile;
15616
+ 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: {
15617
+ minFilter: blurredTexture ? 'linear' : 'nearest',
15618
+ magFilter: blurredTexture ? 'linear' : 'nearest',
15619
+ },
15620
+ // TODO check if works!!!
15621
+ extensions: clampToTerrain ? [new extensions._TerrainExtension()] : [] }, ((clampToTerrain === null || clampToTerrain === void 0 ? void 0 : clampToTerrain.terrainDrawMode)
15622
+ ? { terrainDrawMode: clampToTerrain.terrainDrawMode }
15623
+ : {})));
15624
+ }
15506
15625
  renderLayers() {
15507
- if (this.cogTiles.cog) {
15508
- const layer = new geoLayers.TileLayer({
15509
- id: `${this.id}-${String(performance.now())}`,
15510
- getTileData: (tileData) => this.cogTiles.getTile(tileData.index.x, tileData.index.y, tileData.index.z),
15626
+ const { rasterData, blurredTexture, opacity, clampToTerrain, tileSize, maxRequests, onTileLoad, onTileUnload, onTileError, maxCacheSize, maxCacheByteSize, refinementStrategy, } = this.props;
15627
+ if (this.state.isTiled && this.state.initialized) {
15628
+ return new geoLayers.TileLayer(this.getSubLayerProps({
15629
+ id: 'tiles',
15630
+ }), {
15631
+ getTileData: this.getTiledBitmapData.bind(this),
15632
+ renderSubLayers: this.renderSubLayers.bind(this),
15633
+ updateTriggers: {
15634
+ getTileData: {
15635
+ rasterData: urlTemplateToUpdateTrigger$1(rasterData),
15636
+ blurredTexture,
15637
+ opacity,
15638
+ clampToTerrain,
15639
+ },
15640
+ },
15641
+ extent: this.state.bitmapCogTiles.cog ? this.state.bitmapCogTiles.getBoundsAsLatLon(this.state.bitmapCogTiles.cog) : null,
15642
+ tileSize,
15511
15643
  minZoom: this.minZoom,
15512
15644
  maxZoom: this.maxZoom,
15513
- tileSize: this.tileSize,
15514
- maxRequests: 6,
15515
- extent: this.cogTiles.cog ? this.cogTiles.getBoundsAsLatLon(this.cogTiles.cog) : null,
15516
- renderSubLayers: (props) => {
15517
- var _a, _b, _c, _d, _e, _f, _g;
15518
- const { bbox: { west, south, east, north, }, } = props.tile;
15519
- return new layers.BitmapLayer(props, Object.assign({ data: null, image: props.data, bounds: [west, south, east, north], opacity: 1, textureParameters: {
15520
- minFilter: this.blurredTexture ? 'linear' : 'nearest',
15521
- magFilter: this.blurredTexture ? 'linear' : 'nearest',
15522
- }, extensions: ((_b = (_a = this.cogTiles) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.clampToTerrain) ? [new extensions._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)
15523
- ? { terrainDrawMode: (_g = (_f = this.cogTiles) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.clampToTerrain.terrainDrawMode }
15524
- : {})));
15525
- },
15645
+ maxRequests,
15646
+ onTileLoad,
15647
+ onTileUnload,
15648
+ onTileError,
15649
+ maxCacheSize,
15650
+ maxCacheByteSize,
15651
+ refinementStrategy,
15526
15652
  });
15527
- return layer;
15528
15653
  }
15529
15654
  return null;
15530
15655
  }
15531
15656
  }
15657
+ CogBitmapLayer.defaultProps = defaultProps$1;
15532
15658
  CogBitmapLayer.layerName = 'CogBitmapLayer';
15533
- CogBitmapLayer.displayName = 'CogBitmapLayer';
15534
15659
 
15535
15660
  // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
15536
15661
  //