From b9f3b77607145f973c9291b3b0df1e180287d946 Mon Sep 17 00:00:00 2001 From: gchoqueux Date: Mon, 29 Jul 2019 13:40:51 +0200 Subject: [PATCH] fix(test): core breaking changes after refactor TMS/Extent --- test/data/geojson/holesPoints.geojson.json | 108 ++++++++++++++ test/functional/globe.js | 6 +- test/unit/dataSourceProvider.js | 161 ++++++++++++--------- test/unit/extent.js | 47 +++--- test/unit/layeredmaterial.js | 2 +- test/unit/layeredmaterialnodeprocessing.js | 13 +- test/unit/obb.js | 4 +- test/unit/provider_url.js | 2 +- test/unit/source.js | 11 +- 9 files changed, 249 insertions(+), 105 deletions(-) create mode 100644 test/data/geojson/holesPoints.geojson.json diff --git a/test/data/geojson/holesPoints.geojson.json b/test/data/geojson/holesPoints.geojson.json new file mode 100644 index 0000000000..94351faa15 --- /dev/null +++ b/test/data/geojson/holesPoints.geojson.json @@ -0,0 +1,108 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 0, + 0 + ], + [ + 0, + 1 + ], + [ + 2, + 1 + ], + [ + 2, + 0 + ] + ] + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 0.2, + 0.3 + ], + [ + 0.2, + 0.7 + ], + [ + 1.4, + 0.7 + ], + [ + 1.4, + 0.3 + ] + ] + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 0, + 0 + ], + [ + 0, + 1 + ], + [ + 2, + 1 + ], + [ + 2, + 0 + ] + ], + [ + [ + 0.2, + 0.3 + ], + [ + 0.2, + 0.7 + ], + [ + 1.4, + 0.7 + ], + [ + 1.4, + 0.3 + ] + ] + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "point", + "coordinates": [0.5, 0.5] + } + } + ] +} diff --git a/test/functional/globe.js b/test/functional/globe.js index 9609e4eb96..dd228d10dd 100644 --- a/test/functional/globe.js +++ b/test/functional/globe.js @@ -43,9 +43,9 @@ describe('globe', function _() { const limit = maxColorSamplerUnitsCount - colorSamplerUnitsCount; // add layers just below the capacity limit - const underLimit = await page.evaluate(maxLayersCount => itowns.Fetcher.json('./layers/JSONLayers/OrthosCRS.json').then((params) => { + const underLimit = await page.evaluate(maxLayersCount => itowns.Fetcher.json('./layers/JSONLayers/OPENSM.json').then((params) => { // eslint-disable-next-line no-param-reassign - params.source = new itowns.WMTSSource(params.source); + params.source = new itowns.TMSSource(params.source); const promises = []; for (let i = 0; i < maxLayersCount; i++) { const layer = new itowns.ColorLayer(`${params.id}_${i}`, params); @@ -56,7 +56,7 @@ describe('globe', function _() { // add one layer just over the capacity limit // verify if the error is handled - const errorOverLimit = await page.evaluate(() => itowns.Fetcher.json('./layers/JSONLayers/OrthosCRS.json').then((params) => { + const errorOverLimit = await page.evaluate(() => itowns.Fetcher.json('./layers/JSONLayers/OPENSM.json').then((params) => { const layerParams = Object.assign({}, params); layerParams.id = 'max'; return view.addLayer(layerParams).then(() => false).catch(() => true); diff --git a/test/unit/dataSourceProvider.js b/test/unit/dataSourceProvider.js index 2ef24dff77..d3091b4f57 100644 --- a/test/unit/dataSourceProvider.js +++ b/test/unit/dataSourceProvider.js @@ -3,7 +3,7 @@ import assert from 'assert'; import { updateLayeredMaterialNodeImagery, updateLayeredMaterialNodeElevation } from 'Process/LayeredMaterialNodeProcessing'; import FeatureProcessing from 'Process/FeatureProcessing'; import TileMesh from 'Core/TileMesh'; -import Extent from 'Core/Geographic/Extent'; +import Extent, { globalExtentTMS } from 'Core/Geographic/Extent'; import OBB from 'Renderer/OBB'; import DataSourceProvider, { supportedFetchers } from 'Provider/DataSourceProvider'; import TileProvider from 'Provider/TileProvider'; @@ -14,12 +14,11 @@ import LayerUpdateState from 'Layer/LayerUpdateState'; import ColorLayer from 'Layer/ColorLayer'; import ElevationLayer from 'Layer/ElevationLayer'; import GeometryLayer from 'Layer/GeometryLayer'; -import GlobeLayer from 'Core/Prefab/Globe/GlobeLayer'; -import textureConverter from 'Converter/textureConverter'; +import PlanarLayer from 'Core/Prefab/Planar/PlanarLayer'; import Feature2Mesh from 'Converter/Feature2Mesh'; import LayeredMaterial from 'Renderer/LayeredMaterial'; -const holes = require('../data/geojson/holes.geojson.json'); +const holes = require('../data/geojson/holesPoints.geojson.json'); supportedFetchers.set('image/png', () => Promise.resolve(new THREE.Texture())); supportedFetchers.set('application/json', () => Promise.resolve(holes)); @@ -46,8 +45,11 @@ describe('Provide in Sources', 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)); - const extent = new Extent('EPSG:4326', 0, 10, 0, 10); - const zoom = 4; + const globalExtent = globalExtentTMS.get('EPSG:3857'); + const zoom = 10; + const sizeTile = globalExtent.dimensions().x / 2 ** zoom; + const extent = new Extent('EPSG:3857', 0, sizeTile, 0, sizeTile); + // const zoom = 4; const material = new LayeredMaterial(); // Mock scheduler @@ -64,12 +66,12 @@ describe('Provide in Sources', function () { }, }; - const globelayer = new GlobeLayer('globe', new THREE.Group()); - const colorlayer = new ColorLayer('color'); - const elevationlayer = new ElevationLayer('elevation'); + const planarlayer = new PlanarLayer('globe', globalExtent, new THREE.Group()); + const colorlayer = new ColorLayer('color', { projection: 'WMTS:PM' }); + const elevationlayer = new ElevationLayer('elevation', { projection: 'WMTS:PM' }); - globelayer.attach(colorlayer); - globelayer.attach(elevationlayer); + planarlayer.attach(colorlayer); + planarlayer.attach(elevationlayer); material.addLayer(colorlayer); material.addLayer(elevationlayer); @@ -77,7 +79,6 @@ describe('Provide in Sources', function () { const nodeLayer = material.getLayer(colorlayer.id); const nodeLayerElevation = material.getLayer(elevationlayer.id); - const featureLayer = new GeometryLayer('geom', new THREE.Group()); featureLayer.update = FeatureProcessing.update; featureLayer.projection = 'EPSG:4978'; @@ -94,12 +95,13 @@ describe('Provide in Sources', function () { url: 'http://', typeName: 'name', format: 'application/json', - extent: [-90, 90, -45, 45], - projection: 'EPSG:4326', + extent: globalExtent, + projection: 'EPSG:3857', + zoom: { min: zoom, max: zoom }, }); featureLayer.convert = Feature2Mesh.convert({ color, extrude }); - globelayer.attach(featureLayer); + planarlayer.attach(featureLayer); context.elevationLayers = [elevationlayer]; context.colorLayers = [colorlayer]; @@ -114,14 +116,16 @@ describe('Provide in Sources', function () { url: 'http://', name: 'name', format: 'image/png', - tileMatrixSet: 'WGS84G', + tileMatrixSet: 'PM', + projection: 'EPSG:3857', + extent: globalExtent, zoom: { min: 0, - max: 8, + max: 12, }, }); - const tile = new TileMesh(geom, material, colorlayer, extent, zoom); + const tile = new TileMesh(geom, material, planarlayer, extent); material.visible = true; nodeLayer.level = 0; tile.parent = { }; @@ -130,50 +134,51 @@ describe('Provide in Sources', function () { updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => { assert.equal(textures[0].coords.zoom, zoom); - assert.equal(textures[0].coords.row, 7); - assert.equal(textures[0].coords.col, 16); + assert.equal(textures[0].coords.row, 511); + assert.equal(textures[0].coords.col, 512); }); }); - it('should get wmts texture elevation with DataSourceProvider', () => { + it('should get wmts texture elevation with DataSourceProvider', (done) => { elevationlayer.source = new WMTSSource({ url: 'http://', name: 'name', format: 'image/png', - tileMatrixSet: 'WGS84G', + tileMatrixSet: 'PM', + projection: 'EPSG:3857', zoom: { min: 0, - max: 8, + max: 12, }, }); - const tile = new TileMesh(geom, material, colorlayer, extent, zoom); + const tile = new TileMesh(geom, material, planarlayer, extent, zoom); material.visible = true; nodeLayerElevation.level = 0; tile.parent = {}; - updateLayeredMaterialNodeElevation(context, colorlayer, tile, tile.parent); - updateLayeredMaterialNodeElevation(context, colorlayer, tile, tile.parent); + updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent); + updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => { - // console.log('textures', textures); assert.equal(textures[0].coords.zoom, zoom); - assert.equal(textures[0].coords.row, 7); - assert.equal(textures[0].coords.col, 16); + assert.equal(textures[0].coords.row, 511); + assert.equal(textures[0].coords.col, 512); + done(); }); }); - it('should get wms texture with DataSourceProvider', () => { + it('should get wms texture with DataSourceProvider', (done) => { colorlayer.source = new WMSSource({ url: 'http://', name: 'name', format: 'image/png', - extent: [-90, 90, -45, 45], - projection: 'EPSG:4326', + extent: globalExtent, + projection: 'EPSG:3857', zoom: { min: 0, - max: 8, + max: 12, }, }); - const tile = new TileMesh(geom, material, colorlayer, extent, zoom); + const tile = new TileMesh(geom, material, planarlayer, extent, zoom); material.visible = true; nodeLayer.level = 0; tile.parent = { }; @@ -181,76 +186,100 @@ describe('Provide in Sources', function () { updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent); updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => { - assert.equal(textures[0].coords.zoom, zoom); - assert.equal(textures[0].coords.west, tile.extent.west); - assert.equal(textures[0].coords.east, tile.extent.east); - assert.equal(textures[0].coords.north, tile.extent.north); - assert.equal(textures[0].coords.south, tile.extent.south); + const e = textures[0].coords.as(tile.extent.crs); + assert.equal(e.zoom, zoom); + assert.equal(e.west, tile.extent.west); + assert.equal(e.east, tile.extent.east); + assert.equal(e.north, tile.extent.north); + assert.equal(e.south, tile.extent.south); + done(); }); }); - it('should get 4 TileMesh from TileProvider', () => { - const tile = new TileMesh(geom, material, globelayer, extent, zoom); + it('should get 4 TileMesh from TileProvider', (done) => { + const tile = new TileMesh(geom, material, planarlayer, extent, zoom); material.visible = true; nodeLayer.level = 0; tile.parent = { }; - globelayer.subdivideNode(context, tile); + planarlayer.subdivideNode(context, tile); TileProvider.executeCommand(context.scheduler.commands[0]).then((tiles) => { assert.equal(tiles.length, 4); - assert.equal(tiles[0].extent.west, tile.extent.west); - assert.equal(tiles[0].extent.east, tile.extent.east * 0.5); + assert.equal(tiles[0].extent.west, tile.extent.east * 0.5); + assert.equal(tiles[0].extent.east, tile.extent.east); assert.equal(tiles[0].extent.north, tile.extent.north); assert.equal(tiles[0].extent.south, tile.extent.north * 0.5); + done(); }); }); - it('should get 3 meshs with WFS source and DataSourceProvider', () => { - const tile = new TileMesh(geom, material, featureLayer, extent, zoom); + it('should get 3 meshs with WFS source and DataSourceProvider', (done) => { + const tile = new TileMesh(geom, material, planarlayer, extent, zoom); material.visible = true; nodeLayer.level = 0; tile.parent = { pendingSubdivision: false }; - tile.material.isColorLayerLoaded = () => true; featureLayer.mergeFeatures = false; tile.layerUpdateState = { test: new LayerUpdateState() }; featureLayer.update(context, featureLayer, tile); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((features) => { - assert.equal(features[0].children.length, 3); + assert.equal(features[0].children.length, 4); + done(); }); }); - it('should get 1 mesh with WFS source and DataSourceProvider and mergeFeatures == true', () => { + it('should get 1 mesh with WFS source and DataSourceProvider and mergeFeatures == true', (done) => { const tile = new TileMesh( geom, material, - colorlayer, - new Extent('EPSG:4326', -10, 0, 0, 10), - 4); + planarlayer, + extent, + zoom); tile.material.visible = true; tile.parent = { pendingSubdivision: false }; - tile.material.isColorLayerLoaded = () => true; + featureLayer.source.uid = 8; featureLayer.mergeFeatures = true; featureLayer.update(context, featureLayer, tile); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((features) => { - assert.equal(features[0].children.length, 0); + assert.ok(features[0].children[0].isMesh); + assert.ok(features[0].children[1].isPoints); + assert.equal(features[0].children[0].children.length, 0); + assert.equal(features[0].children[1].children.length, 0); + done(); }); }); - it('should get 1 texture with WFS source and DataSourceProvider', () => { + it('should get 1 texture with WFS source and DataSourceProvider', (done) => { const tile = new TileMesh( geom, material, - colorlayer, - new Extent('EPSG:4326', -10, 10, 0, 10), - 4); - tile.material.visible = true; + planarlayer, + extent, + zoom); + material.visible = true; tile.parent = { pendingSubdivision: false }; - tile.material.isColorLayerLoaded = () => true; - featureLayer.convert = textureConverter.convert; - featureLayer.style = {}; - featureLayer.isColorLayer = true; - featureLayer.isGeometryLayer = false; - featureLayer.update(context, featureLayer, tile); + nodeLayer.level = 0; + tile.material.visible = true; + featureLayer.source.uid = 22; + const colorlayerWfs = new ColorLayer('color', { projection: 'EPSG:3857', + source: featureLayer.source, + style: { + fill: { + color: 'red', + opacity: 0.5, + }, + stroke: { + color: 'white', + width: 2.0, + }, + point: { + color: 'white', + line: 'green', + }, + }, + }); + updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent); + updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent); DataSourceProvider.executeCommand(context.scheduler.commands[0]).then((textures) => { assert.equal(textures.length, 1); - assert.equal(textures[0].coords.zoom, 4); + assert.ok(textures[0].isTexture); + done(); }); }); }); diff --git a/test/unit/extent.js b/test/unit/extent.js index 2b2ddab97f..45e5ba0800 100644 --- a/test/unit/extent.js +++ b/test/unit/extent.js @@ -72,25 +72,24 @@ describe('Extent', function () { const subdivided = toSubdivide.subdivision(); assert.equal(subdivided.length, 4); - - // NW - assert.strictEqual(subdivided[0].west, -10); - assert.strictEqual(subdivided[0].east, 0); + // NE + assert.strictEqual(subdivided[0].west, 0); + assert.strictEqual(subdivided[0].east, 10); assert.strictEqual(subdivided[0].south, 0); assert.strictEqual(subdivided[0].north, 10); - // NE + // SE assert.strictEqual(subdivided[1].west, 0); assert.strictEqual(subdivided[1].east, 10); - assert.strictEqual(subdivided[1].south, 0); - assert.strictEqual(subdivided[1].north, 10); - // SW + assert.strictEqual(subdivided[1].south, -10); + assert.strictEqual(subdivided[1].north, 0); + // NW assert.strictEqual(subdivided[2].west, -10); assert.strictEqual(subdivided[2].east, 0); - assert.strictEqual(subdivided[2].south, -10); - assert.strictEqual(subdivided[2].north, 0); - // SE - assert.strictEqual(subdivided[3].west, 0); - assert.strictEqual(subdivided[3].east, 10); + assert.strictEqual(subdivided[2].south, 0); + assert.strictEqual(subdivided[2].north, 10); + // SW + assert.strictEqual(subdivided[3].west, -10); + assert.strictEqual(subdivided[3].east, 0); assert.strictEqual(subdivided[3].south, -10); assert.strictEqual(subdivided[3].north, 0); }); @@ -128,7 +127,7 @@ describe('Extent', function () { }); it('should convert extent WMTS:WGS84G like expected', function () { - const withValues = new Extent('WMTS:WGS84G', 0, 0, 0).as('EPSG:4326'); + const withValues = new Extent('WMTS:WGS84', 0, 0, 0).as('EPSG:4326'); assert.equal(-180, withValues.west); assert.equal(0, withValues.east); assert.equal(-90, withValues.south); @@ -137,23 +136,23 @@ describe('Extent', function () { it('should convert extent WMTS:PM to EPSG:3857 like expected', function () { const withValues = new Extent('WMTS:PM', 0, 0, 0).as('EPSG:3857'); - assert.equal(-20026376.39, withValues.west); - assert.equal(20026376.39, withValues.east); - assert.equal(-20048966.1, withValues.south); - assert.equal(20048966.1, withValues.north); + assert.equal(-20037508.342789244, withValues.west); + assert.equal(20037508.342789244, withValues.east); + assert.equal(-20037508.342789244, withValues.south); + assert.equal(20037508.342789244, withValues.north); }); it('should convert extent WMTS:PM to EPSG:4326 like expected', function () { - const withValues = new Extent('WMTS:PM', 0, 0, 0).as('EPSG:4326'); - assert.equal(-180, withValues.west); - assert.equal(180, withValues.east); - assert.equal(-85.05112877980659, withValues.south); - assert.equal(85.0511287798066, withValues.north); + const withValues = new Extent('WMTS:PM', 0, 0, 0); + const result = withValues.as('EPSG:4326'); + assert.equal(-180.00000000000003, result.west); + assert.equal(180.00000000000003, result.east); + assert.equal(-85.0511287798066, result.south); + assert.equal(85.0511287798066, result.north); }); it('should convert extent EPSG:4326 like expected', function () { const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]).as('EPSG:3857'); - // console.log('withValues', withValues.as('EPSG:3857')); assert.equal(0, withValues.west); assert.equal(1113194.9079327357, withValues.east); assert.equal(-111325.14286638597, withValues.south); diff --git a/test/unit/layeredmaterial.js b/test/unit/layeredmaterial.js index 5d844a2b63..02ef3430d1 100644 --- a/test/unit/layeredmaterial.js +++ b/test/unit/layeredmaterial.js @@ -13,7 +13,7 @@ describe('material state vs layer state', function () { getLayer: () => nodeLayer, visible: true, }, - getExtentsForSource: () => 0, + getExtentsByProjection: () => 0, }; const layer = { id: 'test', diff --git a/test/unit/layeredmaterialnodeprocessing.js b/test/unit/layeredmaterialnodeprocessing.js index cd8c7ace95..1f77d0f851 100644 --- a/test/unit/layeredmaterialnodeprocessing.js +++ b/test/unit/layeredmaterialnodeprocessing.js @@ -13,7 +13,7 @@ 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)); - const extent = new Extent('EPSG:4326', 0, 10, 0, 10); + const extent = new Extent('EPSG:4326', 0, 11.25, 0, 11.25); const material = {}; // Mock scheduler @@ -32,12 +32,23 @@ describe('updateLayeredMaterialNodeImagery', function () { const source = new Source({ url: 'http://', + projection: 'EPSG:4326', extent, }); const layer = new Layer('foo', { source, + projection: 'EPSG:4326', info: { update: () => {} }, + tileMatrixSets: [ + 'WMTS:WGS84', + 'WMTS:PM', + ], + parent: { tileMatrixSets: [ + 'WMTS:WGS84', + 'WMTS:PM', + ], + }, }); const nodeLayer = new MaterialLayer(material, layer); diff --git a/test/unit/obb.js b/test/unit/obb.js index 54dd1defae..31e5065830 100644 --- a/test/unit/obb.js +++ b/test/unit/obb.js @@ -57,7 +57,7 @@ function assertVerticesAreInOBB(builder, extent) { } describe('Planar tiles OBB computation', function () { - const builder = new PlanarTileBuilder(); + const builder = new PlanarTileBuilder({ projection: 'EPSG:3946', uvCount: 1 }); it('should compute OBB correctly', function () { const extent = new Extent('EPSG:3946', -100, 100, -50, 50); @@ -65,7 +65,7 @@ describe('Planar tiles OBB computation', function () { }); }); describe('Ellipsoid tiles OBB computation', function () { - const builder = new BuilderEllipsoidTile(); + const builder = new BuilderEllipsoidTile({ projection: 'EPSG:4978', uvCount: 1 }); it('should compute globe-level 0 OBB correctly', function () { const extent = new Extent('EPSG:4326', -180, 0, -90, 90); diff --git a/test/unit/provider_url.js b/test/unit/provider_url.js index faba3d87e4..8d29b91ef5 100644 --- a/test/unit/provider_url.js +++ b/test/unit/provider_url.js @@ -7,7 +7,7 @@ const layer = {}; describe('URL creations', function () { it('should correctly replace ${x}, ${y} and ${z} by 359, 512 and 10', function () { - const coords = new Extent('TMS', 10, 512, 359); + var coords = new Extent('WMTS:TMS:4857', 10, 512, 359); layer.url = 'http://server.geo/tms/${z}/${y}/${x}.jpg'; const result = URLBuilder.xyz(coords, layer); assert.equal(result, 'http://server.geo/tms/10/512/359.jpg'); diff --git a/test/unit/source.js b/test/unit/source.js index 8f181ffe2f..54b250a099 100644 --- a/test/unit/source.js +++ b/test/unit/source.js @@ -94,6 +94,7 @@ describe('Sources', function () { const paramsWMTS = { url: 'http://', name: 'name', + projection: 'EPSG:4326', }; it('should throw an error for having no name', function () { @@ -180,6 +181,7 @@ describe('Sources', function () { describe('TMSSource', function () { const paramsTMS = { url: 'http://', + projection: 'EPSG:3857', }; it('should instance and use TMSSource', function () { @@ -191,12 +193,6 @@ describe('Sources', function () { assert.ok(source.extentsInsideLimit([extent, extent])); }); - it('should set the tileMatrixSet to PM', function () { - paramsTMS.projection = 'EPSG:3857'; - const source = new TMSSource(paramsTMS); - assert.strictEqual(source.tileMatrixSet, 'PM'); - }); - it('should respect the tileMatrixSet', function () { paramsTMS.tileMatrixSet = 'FAKE'; const source = new TMSSource(paramsTMS); @@ -209,7 +205,8 @@ describe('Sources', function () { const source = new FileSource({ url: '..', projection: 'EPSG:4326', - extent: [0, 20, 0, 20], + extent: new Extent('EPSG:4326', 0, 20, 0, 20), + zoom: { min: 0, max: 21 }, }); const extent = new Extent('EPSG:4326', 0, 10, 0, 10);