@gisatcz/deckgl-geolib 1.6.0-dev.0 → 1.7.0

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/esm/index.js CHANGED
@@ -15019,24 +15019,20 @@ class GeoImage {
15019
15019
  canvas.height = height;
15020
15020
  const c = canvas.getContext('2d');
15021
15021
  const imageData = c.createImageData(width, height);
15022
- const channelCount = channel.length / (width * height);
15023
- const s = width * height * 4;
15024
- let pixel = 0;
15025
- if (options.useChannel != null) {
15026
- pixel = options.useChannel;
15027
- }
15028
- // console.time("heightmap generated in");
15029
- for (let i = 0; i < s; i += 4) {
15030
- channel[pixel] *= options.multiplier;
15031
- const multiplied = 100000 + channel[pixel] * 10;
15032
- imageData.data[i] = Math.trunc(multiplied * 0.00001525878);
15033
- imageData.data[i + 1] = Math.trunc(multiplied * 0.00390625) - imageData.data[i] * 256;
15034
- imageData.data[i + 2] = Math.trunc(multiplied) - imageData.data[i] * 65536
15035
- - imageData.data[i + 1] * 256;
15022
+ const numOfChannels = channel.length / (width * height);
15023
+ const size = width * height * 4;
15024
+ let pixel = options.useChannel === null ? 0 : options.useChannel;
15025
+ for (let i = 0; i < size; i += 4) {
15026
+ // height image calculation based on:
15027
+ // https://deck.gl/docs/api-reference/geo-layers/terrain-layer
15028
+ const elevationValue = channel[pixel] * options.multiplier;
15029
+ const colorValue = Math.floor((elevationValue + 10000) / 0.1);
15030
+ imageData.data[i] = Math.floor(colorValue / (256 * 256));
15031
+ imageData.data[i + 1] = Math.floor((colorValue / 256) % 256);
15032
+ imageData.data[i + 2] = colorValue % 256;
15036
15033
  imageData.data[i + 3] = 255;
15037
- pixel += channelCount;
15034
+ pixel += numOfChannels;
15038
15035
  }
15039
- // console.timeEnd("heightmap generated in");
15040
15036
  c.putImageData(imageData, 0, 0);
15041
15037
  const imageUrl = canvas.toDataURL('image/png');
15042
15038
  // console.log('Heightmap generated.');