@gisatcz/deckgl-geolib 1.10.2-dev.4 → 1.10.2-dev.6

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',
@@ -14789,22 +14790,21 @@ class GeoImage {
14789
14790
  this.data = data;
14790
14791
  });
14791
14792
  }
14792
- getMap(input, options) {
14793
+ getMap(input, options, meshMaxError) {
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);
14799
14799
  case 'terrain':
14800
- return this.getHeightmap(input, mergedOptions);
14800
+ return this.getHeightmap(input, mergedOptions, meshMaxError);
14801
14801
  default:
14802
14802
  return null;
14803
14803
  }
14804
14804
  });
14805
14805
  }
14806
14806
  // GetHeightmap uses only "useChannel" and "multiplier" options
14807
- getHeightmap(input, options) {
14807
+ getHeightmap(input, options, meshMaxError) {
14808
14808
  return __awaiter(this, void 0, void 0, function* () {
14809
14809
  let rasters = [];
14810
14810
  let width;
@@ -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,11 +14850,10 @@ 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':
14886
- mesh = getMartiniTileMesh(terrainSkirtHeight, width, terrain);
14856
+ mesh = getMartiniTileMesh(meshMaxError, width, terrain);
14887
14857
  break;
14888
14858
  case 'delatin':
14889
14859
  mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
@@ -14892,7 +14862,7 @@ class GeoImage {
14892
14862
  if (width === height && !(height && (width - 1))) {
14893
14863
  // fixme get terrain to separate method
14894
14864
  // terrain = getTerrain(data, width, height, elevationDecoder, 'martini');
14895
- mesh = getMartiniTileMesh(terrainSkirtHeight, width, terrain);
14865
+ mesh = getMartiniTileMesh(meshMaxError, width, terrain);
14896
14866
  }
14897
14867
  else {
14898
14868
  // fixme get terrain to separate method
@@ -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]);
@@ -15342,7 +15297,7 @@ class CogTiles {
15342
15297
  const cartographicPositionAdjusted = [cartographicPosition[0], -cartographicPosition[1]];
15343
15298
  return cartographicPositionAdjusted;
15344
15299
  }
15345
- getTile(x, y, z, bounds) {
15300
+ getTile(x, y, z, bounds, meshMaxError) {
15346
15301
  return __awaiter(this, void 0, void 0, function* () {
15347
15302
  const wantedMpp = this.getResolutionFromZoomLevel(this.tileSize, z);
15348
15303
  const img = this.cog.getImageByResolution(wantedMpp);
@@ -15440,7 +15395,7 @@ class CogTiles {
15440
15395
  width: this.tileSize,
15441
15396
  height: this.tileSize,
15442
15397
  bounds,
15443
- }, this.options);
15398
+ }, this.options, meshMaxError);
15444
15399
  // console.log(decompressed.length)
15445
15400
  return decompressed;
15446
15401
  }
@@ -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
15627
  this.setState({
15705
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
15636
  const cog = yield this.state.terrainCogTiles.initializeCog(this.props.elevationData);
15717
- console.log('xxx_LAYER INITIALIZE STATE', cog);
15718
15637
  // this.tileSize = this.terrainCogTiles.getTileSize(cog);
15719
15638
  const zoomRange = this.state.terrainCogTiles.getZoomRange(cog);
15720
- console.log('xxx_LAYER INITIALIZE STATE', zoomRange);
15721
15639
  [this.minZoom, this.maxZoom] = zoomRange;
15722
15640
  this.setState({ initialized: true });
15723
15641
  });
@@ -15736,11 +15654,7 @@ class TerrainLayer extends core.CompositeLayer {
15736
15654
  || props.meshMaxError !== oldProps.meshMaxError
15737
15655
  || props.elevationDecoder !== oldProps.elevationDecoder
15738
15656
  || props.bounds !== oldProps.bounds;
15739
- if (!this.state.isTiled && shouldReload) {
15740
- // When state.isTiled, elevationData cannot be an array
15741
- const terrain = this.loadTerrain(props);
15742
- this.setState({ terrain });
15743
- }
15657
+ if (!this.state.isTiled && shouldReload) ;
15744
15658
  // TODO - remove in v9
15745
15659
  // @ts-ignore
15746
15660
  if (props.workerUrl) {
@@ -15756,47 +15670,10 @@ class TerrainLayer extends core.CompositeLayer {
15756
15670
  meshMaxError,
15757
15671
  elevationDecoder }) });
15758
15672
  const { fetch } = this.props;
15759
- console.log('xxx_loaddata');
15760
15673
  return fetch(elevationData, {
15761
- propName: 'elevationData', layer: this, loadOptions, signal,
15674
+ propName: 'elevationData', layer: this, loadOptions, signal, loaders: [],
15762
15675
  });
15763
15676
  }
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
15677
  getTiledTerrainData(tile) {
15801
15678
  return __awaiter(this, void 0, void 0, function* () {
15802
15679
  this.props;
@@ -15805,7 +15682,6 @@ class TerrainLayer extends core.CompositeLayer {
15805
15682
  let topRight = [0, 0];
15806
15683
  if (viewport.isGeospatial) {
15807
15684
  const bbox = tile.bbox;
15808
- console.log('xxx_coords', bbox.west, bbox.south, bbox.east, bbox.north);
15809
15685
  bottomLeft = viewport.projectFlat([bbox.west, bbox.south]);
15810
15686
  topRight = viewport.projectFlat([bbox.east, bbox.north]);
15811
15687
  }
@@ -15815,18 +15691,9 @@ class TerrainLayer extends core.CompositeLayer {
15815
15691
  topRight = [bbox.right, bbox.top];
15816
15692
  }
15817
15693
  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.state.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
- // });
15694
+ // TODO - pass signal to getTile
15695
+ // abort request if signal is aborted
15696
+ const terrain = yield this.state.terrainCogTiles.getTile(tile.index.x, tile.index.y, tile.index.z, bounds, this.props.meshMaxError);
15830
15697
  return Promise.all([terrain]);
15831
15698
  });
15832
15699
  }
@@ -15871,19 +15738,16 @@ class TerrainLayer extends core.CompositeLayer {
15871
15738
  }
15872
15739
  const minZ = Math.min(...ranges.map((x) => x[0]));
15873
15740
  const maxZ = Math.max(...ranges.map((x) => x[1]));
15874
- console.log('xxx_ranges', ranges);
15875
15741
  if (!zRange || minZ < zRange[0] || maxZ > zRange[1]) {
15876
15742
  this.setState({ zRange: [Number.isFinite(minZ) ? minZ : 0, Number.isFinite(maxZ) ? maxZ : 0] });
15877
15743
  }
15878
15744
  }
15879
15745
  renderLayers() {
15880
15746
  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
15747
  if (this.state.isTiled && this.state.initialized) {
15883
15748
  return new geoLayers.TileLayer(this.getSubLayerProps({
15884
15749
  id: 'tiles',
15885
15750
  }), {
15886
- // XXX
15887
15751
  getTileData: this.getTiledTerrainData.bind(this),
15888
15752
  renderSubLayers: this.renderSubLayers.bind(this),
15889
15753
  updateTriggers: {