@gisatcz/deckgl-geolib 1.11.0-dev.1 → 1.11.0-dev.10

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