@gisatcz/deckgl-geolib 1.11.0-dev.0 → 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
@@ -15077,7 +15077,9 @@ class GeoImage {
15077
15077
  }) : undefined;
15078
15078
  for (let i = 0; i < arrayLength; i += 4) {
15079
15079
  let pixelColor = options.nullColor;
15080
- if (options.noDataValue === undefined || dataArray[pixel] !== options.noDataValue) {
15080
+ // FIXME
15081
+ // eslint-disable-next-line max-len
15082
+ if ((!Number.isNaN(dataArray[pixel])) && (options.noDataValue === undefined || dataArray[pixel] !== options.noDataValue)) {
15081
15083
  if ((options.clipLow != null && dataArray[pixel] <= options.clipLow)
15082
15084
  || (options.clipHigh != null && dataArray[pixel] >= options.clipHigh)) {
15083
15085
  pixelColor = options.clippedColor;
@@ -15113,10 +15115,6 @@ class GeoImage {
15113
15115
  pixelColor[3] = this.scale(dataArray[pixel], options.colorScaleValueRange[0], options.colorScaleValueRange.slice(-1)[0], 0, 255);
15114
15116
  }
15115
15117
  }
15116
- // If pixel has null value
15117
- }
15118
- else if (Number.isNaN(dataArray[pixel])) {
15119
- pixelColor = [0, 0, 0, 0];
15120
15118
  }
15121
15119
  // FIXME
15122
15120
  // eslint-disable-next-line
@@ -15218,6 +15216,9 @@ function getDelatinTileMesh(meshMaxError, width, height, terrain) {
15218
15216
 
15219
15217
  const EARTH_CIRCUMFERENCE = 40075000.0;
15220
15218
  const EARTH_HALF_CIRCUMFERENCE = 20037500.0;
15219
+ const CogTilesGeoImageOptionsDefaults = {
15220
+ blurredTexture: true,
15221
+ };
15221
15222
  class CogTiles {
15222
15223
  constructor(options) {
15223
15224
  this.zoomRange = [0, 0];
@@ -15226,7 +15227,7 @@ class CogTiles {
15226
15227
  this.loaded = false;
15227
15228
  this.geo = new GeoImage();
15228
15229
  this.lzw = new LZWDecoder$1();
15229
- this.options = options;
15230
+ this.options = Object.assign(Object.assign({}, CogTilesGeoImageOptionsDefaults), options);
15230
15231
  }
15231
15232
  initializeCog(url) {
15232
15233
  return __awaiter(this, void 0, void 0, function* () {
@@ -15471,68 +15472,174 @@ class CogTiles {
15471
15472
  }
15472
15473
  }
15473
15474
 
15474
- // let needsRerender: boolean = false;
15475
- // 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. */
15476
15527
  class CogBitmapLayer extends core.CompositeLayer {
15477
- constructor(id, url, options) {
15478
- super({});
15479
- // private _isLoaded: boolean;
15480
- this.id = '';
15481
- this.id = id;
15482
- // this.state = {
15483
- // initialized: false,
15484
- // };
15485
- // this._isLoaded = false;
15486
- this.cogTiles = new CogTiles(options);
15487
- this.blurredTexture = options.blurredTexture;
15488
- this.url = url;
15489
- // setTimeout(() => {
15490
- // this.init(url);
15491
- // }, 500);
15492
- }
15493
- initializeState() {
15494
- this.state = {
15495
- initialized: false,
15496
- };
15497
- this.init(this.url);
15498
- }
15499
- 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
+ });
15500
15540
  return __awaiter(this, void 0, void 0, function* () {
15501
- const cog = yield this.cogTiles.initializeCog(url);
15502
- this.setState({ initialized: true });
15503
- this.tileSize = this.cogTiles.getTileSize(cog);
15504
- const zoomRange = this.cogTiles.getZoomRange(cog);
15505
- [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;
15506
15584
  });
15507
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
+ }
15508
15604
  renderLayers() {
15509
- if (this.cogTiles.cog) {
15510
- const layer = new geoLayers.TileLayer({
15511
- id: `${this.id}-${String(performance.now())}`,
15512
- getTileData: (tileData) => this.cogTiles.getTile(tileData.index.x, tileData.index.y, tileData.index.z),
15513
- minZoom: this.minZoom,
15514
- maxZoom: this.maxZoom,
15515
- tileSize: this.tileSize,
15516
- maxRequests: 6,
15517
- extent: this.cogTiles.cog ? this.cogTiles.getBoundsAsLatLon(this.cogTiles.cog) : null,
15518
- renderSubLayers: (props) => {
15519
- var _a, _b, _c, _d, _e, _f, _g;
15520
- const { bbox: { west, south, east, north, }, } = props.tile;
15521
- return new layers.BitmapLayer(props, Object.assign({ data: null, image: props.data, bounds: [west, south, east, north], opacity: 1, textureParameters: {
15522
- minFilter: this.blurredTexture ? 'linear' : 'nearest',
15523
- magFilter: this.blurredTexture ? 'linear' : 'nearest',
15524
- }, 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)
15525
- ? { terrainDrawMode: (_g = (_f = this.cogTiles) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.clampToTerrain.terrainDrawMode }
15526
- : {})));
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
+ },
15527
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,
15528
15636
  });
15529
- return layer;
15530
15637
  }
15531
15638
  return null;
15532
15639
  }
15533
15640
  }
15641
+ CogBitmapLayer.defaultProps = defaultProps$1;
15534
15642
  CogBitmapLayer.layerName = 'CogBitmapLayer';
15535
- CogBitmapLayer.displayName = 'CogBitmapLayer';
15536
15643
 
15537
15644
  // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
15538
15645
  //