@gisatcz/deckgl-geolib 1.10.2-dev.3 → 1.10.2-dev.5

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
@@ -14745,6 +14745,7 @@ function inCircle(ax, ay, bx, by, cx, cy, px, py) {
14745
14745
  }
14746
14746
 
14747
14747
  /* eslint 'max-len': [1, { code: 105, comments: 999, ignoreStrings: true, ignoreUrls: true }] */
14748
+ // FIXME - tesselator as a parameter
14748
14749
  const tesselator = 'martini';
14749
14750
  const DefaultGeoImageOptions = {
14750
14751
  type: 'image',
@@ -14792,7 +14793,6 @@ class GeoImage {
14792
14793
  getMap(input, options) {
14793
14794
  return __awaiter(this, void 0, void 0, function* () {
14794
14795
  const mergedOptions = Object.assign(Object.assign({}, DefaultGeoImageOptions), options);
14795
- console.log('xxx_mergedOptions', mergedOptions);
14796
14796
  switch (mergedOptions.type) {
14797
14797
  case 'image':
14798
14798
  return this.getBitmap(input, mergedOptions);
@@ -14828,18 +14828,8 @@ class GeoImage {
14828
14828
  channel = rasters[options.useChannel]; // length = 65536
14829
14829
  }
14830
14830
  }
14831
- // const canvas = document.createElement('canvas');
14832
- // canvas.width = width;
14833
- // canvas.height = height;
14834
- // // const c = canvas.getContext('2d');
14835
- // // const imageData = c!.createImageData(width, height);
14836
- // const terrain = new Float32Array((width + 1) * (height + 1));
14837
- const terrain = new Float32Array((width + 1) * (height + 1)); // length = 66049
14831
+ const terrain = new Float32Array((width + 1) * (height + 1));
14838
14832
  const numOfChannels = channel.length / (width * height);
14839
- // return mesh data
14840
- // const size: number = width * height * 4;
14841
- const size = width * height;
14842
- console.log('xxx_size', size);
14843
14833
  let pixel = options.useChannel === null ? 0 : options.useChannel;
14844
14834
  for (let i = 0, y = 0; y < height; y++) {
14845
14835
  for (let x = 0; x < width; x++, i++) {
@@ -14848,25 +14838,6 @@ class GeoImage {
14848
14838
  pixel += numOfChannels;
14849
14839
  }
14850
14840
  }
14851
- // for (let i = 0; i < size; i++) {
14852
- // // height image calculation based on:
14853
- // // https://deck.gl/docs/api-reference/geo-layers/terrain-layer
14854
- // const elevationValue = (options.noDataValue && channel[pixel] === options.noDataValue) ? options.terrainMinValue : channel[pixel] * options.multiplier!;
14855
- // terrain[i] = elevationValue;
14856
- // // const colorValue = Math.floor((elevationValue + 10000) / 0.1);
14857
- // // imageData.data[i] = Math.floor(colorValue / (256 * 256));
14858
- // // imageData.data[i + 1] = Math.floor((colorValue / 256) % 256);
14859
- // // imageData.data[i + 2] = colorValue % 256;
14860
- // // imageData.data[i + 3] = 255;
14861
- // pixel += numOfChannels;
14862
- // }
14863
- // c!.putImageData(imageData, 0, 0);
14864
- // const imageUrl = canvas.toDataURL('image/png');
14865
- // console.log('Heightmap generated.');
14866
- console.log('xxx_terrain', terrain);
14867
- if (terrain[0] > 0) {
14868
- debugger;
14869
- }
14870
14841
  {
14871
14842
  // backfill bottom border
14872
14843
  for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
@@ -14879,7 +14850,6 @@ class GeoImage {
14879
14850
  }
14880
14851
  // getMesh
14881
14852
  const { terrainSkirtHeight } = options;
14882
- console.log('xxx_bounds_0', input.bounds);
14883
14853
  let mesh;
14884
14854
  switch (tesselator) {
14885
14855
  case 'martini':
@@ -14910,8 +14880,6 @@ class GeoImage {
14910
14880
  let attributes = getMeshAttributes(vertices, terrain, width, height, input.bounds);
14911
14881
  // Compute bounding box before adding skirt so that z values are not skewed
14912
14882
  const boundingBox = schema.getMeshBoundingBox(attributes);
14913
- // FIXME uncomment and add skirt
14914
- console.log('xxx_skirtHeight', terrainSkirtHeight);
14915
14883
  if (terrainSkirtHeight) {
14916
14884
  const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangles, terrainSkirtHeight);
14917
14885
  attributes = newAttributes;
@@ -15212,7 +15180,6 @@ function getMeshAttributes(vertices, terrain, width, height, bounds) {
15212
15180
  const positions = new Float32Array(numOfVerticies * 3);
15213
15181
  // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
15214
15182
  const texCoords = new Float32Array(numOfVerticies * 2);
15215
- console.log('xxx_bounds', bounds);
15216
15183
  const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
15217
15184
  const xScale = (maxX - minX) / width;
15218
15185
  const yScale = (maxY - minY) / height;
@@ -15261,7 +15228,6 @@ class CogTiles {
15261
15228
  this.geo = new GeoImage();
15262
15229
  this.lzw = new LZWDecoder$1();
15263
15230
  this.options = options;
15264
- // this.testCog()
15265
15231
  }
15266
15232
  initializeCog(url) {
15267
15233
  return __awaiter(this, void 0, void 0, function* () {
@@ -15275,16 +15241,6 @@ class CogTiles {
15275
15241
  this.cog.images.forEach((image) => {
15276
15242
  image.loadGeoTiffTags();
15277
15243
  });
15278
- /*
15279
- console.log("---- START OF COG INFO DUMP ----")
15280
- this.cog.images[0].tags.forEach((tag) => {
15281
- //console.log(tag.value.name)
15282
- console.log(tag.name + ":")
15283
- console.log(tag.value)
15284
- })
15285
- console.log("---- END OF COG INFO DUMP ----")
15286
- */
15287
- // console.log(this.cog)
15288
15244
  this.tileSize = this.getTileSize(this.cog);
15289
15245
  this.lowestOriginTileOffset = this.getImageTileIndex(this.cog.images[this.cog.images.length - 1]);
15290
15246
  this.zoomRange = this.getZoomRange(this.cog);
@@ -15302,7 +15258,6 @@ class CogTiles {
15302
15258
  }
15303
15259
  getBoundsAsLatLon(cog) {
15304
15260
  const { bbox } = cog.images[cog.images.length - 1];
15305
- // console.log(bbox)
15306
15261
  const minX = Math.min(bbox[0], bbox[2]);
15307
15262
  const maxX = Math.max(bbox[0], bbox[2]);
15308
15263
  const minY = Math.min(bbox[1], bbox[3]);
@@ -15515,32 +15470,6 @@ class CogTiles {
15515
15470
  }
15516
15471
  return undefined;
15517
15472
  }
15518
- testCog() {
15519
- return __awaiter(this, void 0, void 0, function* () {
15520
- const url = 'https://gisat-gis.eu-central-1.linodeobjects.com/eman/versions/v2/Quadrants/Q3_Bolivia_ASTER_2002_RGB_COG_LZW.tif';
15521
- this.options = {
15522
- type: 'image', multiplier: 1.0, useChannel: 1, alpha: 180, clipLow: 1, clipHigh: Number.MAX_VALUE,
15523
- };
15524
- const c = yield this.initializeCog(url);
15525
- const middleImage = c.images[Math.floor(c.images.length / 2)];
15526
- console.log(middleImage);
15527
- const imageTileIndex = this.getImageTileIndex(middleImage);
15528
- console.log(imageTileIndex);
15529
- const x = Math.floor(middleImage.tileCount.x / 2);
15530
- const y = Math.floor(middleImage.tileCount.y / 2);
15531
- console.log(c.getTile(x, y, Math.floor(c.images.length / 2)));
15532
- const tileGlobalX = x + imageTileIndex[0];
15533
- const tileGlobalY = y + imageTileIndex[1];
15534
- const tileGlobalZ = imageTileIndex[2];
15535
- const tile = yield this.getTile(tileGlobalX, tileGlobalY, tileGlobalZ);
15536
- if (tile === false) {
15537
- console.log("couldn't retrieve tile");
15538
- }
15539
- else {
15540
- console.log(tile);
15541
- }
15542
- });
15543
- }
15544
15473
  }
15545
15474
 
15546
15475
  // let needsRerender: boolean = false;
@@ -15575,10 +15504,6 @@ class CogBitmapLayer extends core.CompositeLayer {
15575
15504
  this.tileSize = this.cogTiles.getTileSize(cog);
15576
15505
  const zoomRange = this.cogTiles.getZoomRange(cog);
15577
15506
  [this.minZoom, this.maxZoom] = zoomRange;
15578
- // console.log(zoomRange)
15579
- // extent = cogTiles.getBoundsAsLatLon(cog)
15580
- // console.log(extent)
15581
- // needsRerender = true;
15582
15507
  });
15583
15508
  }
15584
15509
  renderLayers() {
@@ -15688,36 +15613,29 @@ function urlTemplateToUpdateTrigger(template) {
15688
15613
  }
15689
15614
  return template || '';
15690
15615
  }
15616
+ // TODO remove elevationDecoder
15617
+ // TODO use meshMaxError
15618
+ // TODO - pass signal to getTile
15691
15619
  /** Render mesh surfaces from height map images. */
15692
15620
  class TerrainLayer extends core.CompositeLayer {
15693
- // constructor(props: TerrainLayerProps & ExtraPropsT, terrainOptions: GeoImageOptions) {
15694
- // super(props);
15695
- // console.log('xxx_terrainOptions', terrainOptions);
15696
- // }
15697
15621
  initializeState(context) {
15698
15622
  const _super = Object.create(null, {
15699
15623
  initializeState: { get: () => super.initializeState }
15700
15624
  });
15701
15625
  return __awaiter(this, void 0, void 0, function* () {
15702
15626
  _super.initializeState.call(this, context);
15703
- console.log('xxx_initializeState_terrain');
15704
- this.terrainCogTiles = new CogTiles(this.props.terrainOptions);
15705
15627
  this.setState({
15628
+ terrainCogTiles: new CogTiles(this.props.terrainOptions),
15706
15629
  initialized: false,
15707
15630
  });
15708
- // XXX
15709
15631
  yield this.init(this.terrainUrl);
15710
15632
  });
15711
15633
  }
15712
15634
  init(terrainUrl) {
15713
15635
  return __awaiter(this, void 0, void 0, function* () {
15714
- console.log('xxx_LAYER INITIALIZE STATE');
15715
- // XXX
15716
- const cog = yield this.terrainCogTiles.initializeCog(this.props.elevationData);
15717
- console.log('xxx_LAYER INITIALIZE STATE', cog);
15636
+ const cog = yield this.state.terrainCogTiles.initializeCog(this.props.elevationData);
15718
15637
  // this.tileSize = this.terrainCogTiles.getTileSize(cog);
15719
- const zoomRange = this.terrainCogTiles.getZoomRange(cog);
15720
- console.log('xxx_LAYER INITIALIZE STATE', zoomRange);
15638
+ const zoomRange = this.state.terrainCogTiles.getZoomRange(cog);
15721
15639
  [this.minZoom, this.maxZoom] = zoomRange;
15722
15640
  this.setState({ initialized: true });
15723
15641
  });
@@ -15756,47 +15674,10 @@ class TerrainLayer extends core.CompositeLayer {
15756
15674
  meshMaxError,
15757
15675
  elevationDecoder }) });
15758
15676
  const { fetch } = this.props;
15759
- console.log('xxx_loaddata');
15760
15677
  return fetch(elevationData, {
15761
15678
  propName: 'elevationData', layer: this, loadOptions, signal,
15762
15679
  });
15763
15680
  }
15764
- // OLD version
15765
- // getTiledTerrainData(tile: TileLoadProps): Promise<MeshAndTexture> {
15766
- // const {
15767
- // elevationData, fetch, texture, elevationDecoder, meshMaxError,
15768
- // } = this.props;
15769
- // const { viewport } = this.context;
15770
- // const dataUrl = getURLFromTemplate(elevationData, tile);
15771
- // const textureUrl = texture && getURLFromTemplate(texture, tile);
15772
- // const { signal } = tile;
15773
- // let bottomLeft = [0, 0] as [number, number];
15774
- // let topRight = [0, 0] as [number, number];
15775
- // if (viewport.isGeospatial) {
15776
- // const bbox = tile.bbox as GeoBoundingBox;
15777
- // bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
15778
- // topRight = viewport.projectFlat([bbox.east, bbox.north]);
15779
- // } else {
15780
- // const bbox = tile.bbox as Exclude<TileBoundingBox, GeoBoundingBox>;
15781
- // bottomLeft = [bbox.left, bbox.bottom];
15782
- // topRight = [bbox.right, bbox.top];
15783
- // }
15784
- // const bounds: Bounds = [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
15785
- // const terrain = this.loadTerrain({
15786
- // elevationData: dataUrl,
15787
- // bounds,
15788
- // elevationDecoder,
15789
- // meshMaxError,
15790
- // signal,
15791
- // });
15792
- // const surface = textureUrl
15793
- // ? // If surface image fails to load, the tile should still be displayed
15794
- // fetch(textureUrl, {
15795
- // propName: 'texture', layer: this, loaders: [], signal,
15796
- // }).catch((_) => null)
15797
- // : Promise.resolve(null);
15798
- // return Promise.all([terrain, surface]);
15799
- // }
15800
15681
  getTiledTerrainData(tile) {
15801
15682
  return __awaiter(this, void 0, void 0, function* () {
15802
15683
  this.props;
@@ -15805,7 +15686,6 @@ class TerrainLayer extends core.CompositeLayer {
15805
15686
  let topRight = [0, 0];
15806
15687
  if (viewport.isGeospatial) {
15807
15688
  const bbox = tile.bbox;
15808
- console.log('xxx_coords', bbox.west, bbox.south, bbox.east, bbox.north);
15809
15689
  bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
15810
15690
  topRight = viewport.projectFlat([bbox.east, bbox.north]);
15811
15691
  }
@@ -15815,18 +15695,9 @@ class TerrainLayer extends core.CompositeLayer {
15815
15695
  topRight = [bbox.right, bbox.top];
15816
15696
  }
15817
15697
  const bounds = [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
15818
- // const bounds: Bounds = [0, 100, 100, 100];
15819
- // const bounds: Bounds = [tile.bbox.west, tile.bbox.south, tile.bbox.east, tile.bbox.north];
15820
- // XXX
15821
- const terrain = yield this.terrainCogTiles.getTile(tile.index.x, tile.index.y, tile.index.z, bounds);
15822
- console.log('xxx_TILE', terrain, bounds);
15823
- // const terrain = this.loadTerrain({
15824
- // elevationData: dataUrl,
15825
- // bounds,
15826
- // elevationDecoder,
15827
- // meshMaxError,
15828
- // signal,
15829
- // });
15698
+ // TODO - pass signal to getTile
15699
+ // abort request if signal is aborted
15700
+ const terrain = yield this.state.terrainCogTiles.getTile(tile.index.x, tile.index.y, tile.index.z, bounds);
15830
15701
  return Promise.all([terrain]);
15831
15702
  });
15832
15703
  }
@@ -15871,19 +15742,16 @@ class TerrainLayer extends core.CompositeLayer {
15871
15742
  }
15872
15743
  const minZ = Math.min(...ranges.map((x) => x[0]));
15873
15744
  const maxZ = Math.max(...ranges.map((x) => x[1]));
15874
- console.log('xxx_ranges', ranges);
15875
15745
  if (!zRange || minZ < zRange[0] || maxZ > zRange[1]) {
15876
15746
  this.setState({ zRange: [Number.isFinite(minZ) ? minZ : 0, Number.isFinite(maxZ) ? maxZ : 0] });
15877
15747
  }
15878
15748
  }
15879
15749
  renderLayers() {
15880
15750
  const { color, material, elevationData, texture, wireframe, meshMaxError, elevationDecoder, tileSize, maxZoom, minZoom, extent, maxRequests, onTileLoad, onTileUnload, onTileError, maxCacheSize, maxCacheByteSize, refinementStrategy, } = this.props;
15881
- console.log('xxx_renderLayers', this.state.initialized);
15882
15751
  if (this.state.isTiled && this.state.initialized) {
15883
15752
  return new geoLayers.TileLayer(this.getSubLayerProps({
15884
15753
  id: 'tiles',
15885
15754
  }), {
15886
- // XXX
15887
15755
  getTileData: this.getTiledTerrainData.bind(this),
15888
15756
  renderSubLayers: this.renderSubLayers.bind(this),
15889
15757
  updateTriggers: {