-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import * as THREE from 'three'; | ||
import assert from 'assert'; | ||
import { updateLayeredMaterialNodeImagery } from '../../src/Process/LayeredMaterialNodeProcessing'; | ||
import processTiledGeometryNode from '../../src/Process/TiledNodeProcessing'; | ||
import TileMesh from '../../src/Core/TileMesh'; | ||
import Extent from '../../src/Core/Geographic/Extent'; | ||
import OBB from '../../src/Renderer/ThreeExtended/OBB'; | ||
import LayeredMaterial from '../../src/Renderer/LayeredMaterial'; | ||
import DataSourceProvider, { supportedFetchers } from '../../src/Provider/DataSourceProvider'; | ||
import WMTSSource from '../../src/Source/WMTSSource'; | ||
import WMSSource from '../../src/Source/WMSSource'; | ||
import ColorLayer from '../../src/Layer/ColorLayer'; | ||
import GlobeLayer from '../../src/Core/Prefab/Globe/GlobeLayer'; | ||
|
||
supportedFetchers.set('image/png', () => Promise.resolve(new THREE.Texture())); | ||
|
||
describe('updateLayeredMaterialNodeImagery', function () { | ||
// Misc var to initialize a TileMesh instance | ||
const geom = new THREE.Geometry(); | ||
geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1)); | ||
|
||
// Mock scheduler | ||
const context = { | ||
view: { | ||
notifyChange: () => true, | ||
}, | ||
scheduler: { | ||
commands: [], | ||
execute: (cmd) => { | ||
context.scheduler.commands.push(cmd); | ||
return new Promise(() => { /* no-op */ }); | ||
}, | ||
}, | ||
}; | ||
|
||
const colorlayer = new ColorLayer(); | ||
const globelayer = new GlobeLayer('globe', new THREE.Group()); | ||
|
||
beforeEach('reset state', function () { | ||
// clear commands array | ||
context.scheduler.commands = []; | ||
}); | ||
|
||
it('should download wmts texture with correct extent', () => { | ||
colorlayer.source = new WMTSSource({ | ||
url: 'http://', | ||
name: 'name', | ||
protocol: 'wmts', | ||
format: 'image/png', | ||
tileMatrixSet: 'WGS84G', | ||
zoom: { | ||
min: 0, | ||
max: 8, | ||
}, | ||
}); | ||
const zoom = 4; | ||
const tile = new TileMesh( | ||
colorlayer, | ||
geom, | ||
new LayeredMaterial(), | ||
new Extent('EPSG:4326', 0, 10, 0, 10), | ||
zoom); | ||
tile.material.visible = true; | ||
tile.parent = { }; | ||
tile.material.indexOfColorLayer = () => 0; | ||
tile.material.isColorLayerDownscaled = () => true; | ||
tile.material.getColorLayerLevelById = () => 1; | ||
tile.material.getLayerTextures = () => [{}]; | ||
|
||
updateLayeredMaterialNodeImagery(context, colorlayer, tile); | ||
updateLayeredMaterialNodeImagery(context, colorlayer, tile); | ||
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((texture) => { | ||
assert.equal(texture[0].coords.zoom, zoom); | ||
assert.equal(texture[0].coords.row, 7); | ||
assert.equal(texture[0].coords.col, 16); | ||
}); | ||
}); | ||
it('should download wms texture with correct extent', () => { | ||
colorlayer.source = new WMSSource({ | ||
url: 'http://', | ||
name: 'name', | ||
protocol: 'wms', | ||
format: 'image/png', | ||
extent: [-90, 90, -45, 45], | ||
projection: 'EPSG:4326', | ||
zoom: { | ||
min: 0, | ||
max: 8, | ||
}, | ||
}); | ||
const zoom = 4; | ||
const tile = new TileMesh( | ||
colorlayer, | ||
geom, | ||
new LayeredMaterial(), | ||
new Extent('EPSG:4326', 0, 10, 0, 10), | ||
zoom); | ||
tile.material.visible = true; | ||
tile.parent = { material: { indexOfColorLayer: () => 0 } }; | ||
tile.material.indexOfColorLayer = () => 0; | ||
tile.material.isColorLayerDownscaled = () => true; | ||
tile.material.getColorLayerLevelById = () => 1; | ||
tile.material.getLayerTextures = () => [{}]; | ||
|
||
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent); | ||
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent); | ||
DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((texture) => { | ||
assert.equal(texture[0].coords.zoom, zoom); | ||
assert.equal(texture[0].coords.west(), tile.extent.west()); | ||
assert.equal(texture[0].coords.east(), tile.extent.east()); | ||
assert.equal(texture[0].coords.north(), tile.extent.north()); | ||
assert.equal(texture[0].coords.south(), tile.extent.west()); | ||
}); | ||
}); | ||
|
||
it('should download wms texture with correct extent', () => { | ||
context.elevationLayers = []; | ||
context.colorLayers = [colorlayer]; | ||
const tileProcess = processTiledGeometryNode(null, () => true); | ||
const tile = new TileMesh( | ||
colorlayer, | ||
geom, | ||
new LayeredMaterial(), | ||
new Extent('EPSG:4326', 0, 10, 0, 10), | ||
4); | ||
tile.material.visible = true; | ||
tile.parent = { | ||
pendingSubdivision: false }; | ||
tile.material.isColorLayerLoaded = () => true; | ||
tileProcess(context, globelayer, tile); | ||
}); | ||
}); |