Skip to content

Commit

Permalink
demUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Dec 20, 2023
1 parent b8adf13 commit 749d412
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
Binary file added test/data/unitTest/dem/dem3_3_8.bil
Binary file not shown.
76 changes: 52 additions & 24 deletions test/unit/demutils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as THREE from 'three';
import fs from 'fs';
import ElevationLayer from 'Layer/ElevationLayer';
import WMTSSource from 'Source/WMTSSource';
import { supportedFetchers } from 'Source/Source';
import { HttpsProxyAgent } from 'https-proxy-agent';
import assert from 'assert';
import GlobeView from 'Core/Prefab/GlobeView';
Expand All @@ -12,39 +14,65 @@ import OBB from 'Renderer/OBB';
import LayerUpdateState from 'Layer/LayerUpdateState';
import DEMUtils from 'Utils/DEMUtils';
import { RasterElevationTile } from 'Renderer/RasterTile';
import sinon from 'sinon';
import Renderer from './bootstrap';

const dem338 = fs.readFileSync('./test/data/unitTest/dem/dem3_3_8.bil');

describe('DemUtils', function () {
const renderer = new Renderer();
const placement = { coord: new Coordinates('EPSG:4326', 1.5, 43), zoom: 10 };
const viewer = new GlobeView(renderer.domElement, placement, { renderer });

const source = new WMTSSource({
format: 'image/x-bil;bits=32',
crs: 'EPSG:4326',
url: 'https://wxs.ign.fr/altimetrie/geoportail/wmts',
name: 'ELEVATION.ELEVATIONGRIDCOVERAGE.SRTM3',
tileMatrixSet: 'WGS84G',
networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {
// referrerPolicy: 'origin-when-cross-origin',
crossOrigin: 'anonymous',
// referrer: 'http://localhost:8080/examples/view_3d_map.html',
},
});
source.url = 'https://github.com/iTowns/iTowns2-sample-data/blob/master/dem3_3_8.bil?raw=true';
const elevationlayer = new ElevationLayer('worldelevation', { source });
let elevationlayer;
let context;
let stubSuppFetcher;

before(function () {
stubSuppFetcher = sinon.stub(supportedFetchers, 'get')
.callsFake((format) => {
if (format === 'image/x-bil;bits=32') {
const floatArray = new Float32Array(dem338.buffer);
const texture = new THREE.DataTexture(floatArray, 256, 256, THREE.RedFormat, THREE.FloatType);
texture.internalFormat = 'R32F';
texture.needsUpdate = true;
return () => Promise.resolve(texture);
} else {
throw new Error(`format (${format}) non supported`);
}
});

const source = new WMTSSource({
format: 'image/x-bil;bits=32',
crs: 'EPSG:4326',
url: 'https://wxs.ign.fr/altimetrie/geoportail/wmts',
name: 'ELEVATION.ELEVATIONGRIDCOVERAGE.SRTM3',
tileMatrixSet: 'WGS84G',
networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {
// referrerPolicy: 'origin-when-cross-origin',
crossOrigin: 'anonymous',
// referrer: 'http://localhost:8080/examples/view_3d_map.html',
},
});
source.url = 'https://github.com/iTowns/iTowns2-sample-data/blob/master/dem3_3_8.bil?raw=true';
elevationlayer = new ElevationLayer('worldelevation', { source });

const context = {
camera: viewer.camera,
engine: viewer.mainLoop.gfxEngine,
scheduler: {
execute: (command) => {
const provider = viewer.mainLoop.scheduler.getProtocolProvider(command.layer.protocol);
return provider.executeCommand(command);
context = {
camera: viewer.camera,
engine: viewer.mainLoop.gfxEngine,
scheduler: {
execute: (command) => {
const provider = viewer.mainLoop.scheduler.getProtocolProvider(command.layer.protocol);
return provider.executeCommand(command);
},
},
},
view: viewer,
};
view: viewer,
};
});

after(() => {
stubSuppFetcher.restore();
});

it('add elevation layer', (done) => {
viewer.addLayer(elevationlayer)
Expand Down

0 comments on commit 749d412

Please sign in to comment.