diff --git a/src/Core/Style.js b/src/Core/Style.js index 3c714c1ec9..7c43d7075e 100644 --- a/src/Core/Style.js +++ b/src/Core/Style.js @@ -10,11 +10,10 @@ import itowns_stroke_single_before from './StyleChunk/itowns_stroke_single_befor export const cacheStyle = new Cache(); -const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); -const matrix = svg.createSVGMatrix(); +const matrix = document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix(); +const canvas = document.createElement('canvas'); const inv255 = 1 / 255; -const canvas = (typeof document !== 'undefined') ? document.createElement('canvas') : {}; function baseAltitudeDefault(properties, ctx) { return ctx?.coordinates?.z || 0; @@ -1079,7 +1078,7 @@ const CustomStyle = { itowns_stroke_single_before, }; -const customStyleSheet = (typeof document !== 'undefined') ? document.createElement('style') : {}; +const customStyleSheet = document.createElement('style'); customStyleSheet.type = 'text/css'; Object.keys(CustomStyle).forEach((key) => { diff --git a/src/Layer/C3DTilesLayer.js b/src/Layer/C3DTilesLayer.js index 3fadfca3ec..ee48c5d62d 100644 --- a/src/Layer/C3DTilesLayer.js +++ b/src/Layer/C3DTilesLayer.js @@ -30,8 +30,8 @@ const update = process3dTilesNode(); /** * Find tileId of object - * * @param {THREE.Object3D} object - object + * * @returns {number} tileId */ function findTileID(object) { @@ -41,14 +41,13 @@ function findTileID(object) { currentObject = currentObject.parent; result = currentObject.tileId; } - return result; } /** * Check if object3d has feature - * * @param {THREE.Object3D} object3d - object3d to check + * * @returns {boolean} - true if object3d has feature */ function object3DHasFeature(object3d) { @@ -231,11 +230,13 @@ class C3DTilesLayer extends GeometryLayer { * targets picked under specified coordinates. Intersects can be * computed with view.pickObjectsAt(..). See fillHTMLWithPickingInfo() * in 3dTilesHelper.js for an example. + * * @returns {C3DTileFeature} - the closest C3DTileFeature of the intersects array */ getC3DTileFeatureFromIntersectsArray(intersects) { // find closest intersect with an attributes _BATCHID + face != undefined let closestIntersect = null; + for (let index = 0; index < intersects.length; index++) { const i = intersects[index]; if (i.object.geometry && @@ -277,7 +278,6 @@ class C3DTilesLayer extends GeometryLayer { /** * Initialize C3DTileFeatures from tileContent - * * @param {THREE.Object3D} tileContent - tile as THREE.Object3D */ initC3DTileFeatures(tileContent) { @@ -344,8 +344,8 @@ class C3DTilesLayer extends GeometryLayer { /** * Update style of the C3DTFeatures, an allowList of tile id can be passed to only update certain tile. * Note that this function only update THREE.Object3D materials, in order to see style changes you should call view.notifyChange() - * * @param {Array|null} [allowTileIdList] - tile ids to allow in updateStyle computation if null all tiles are updated + * * @returns {boolean} true if style updated false otherwise */ updateStyle(allowTileIdList = null) { diff --git a/test/functional/3dtiles_batch_table.js b/test/functional/3dtiles_batch_table.js index 07dfaf3e7f..6852bea081 100644 --- a/test/functional/3dtiles_batch_table.js +++ b/test/functional/3dtiles_batch_table.js @@ -29,7 +29,7 @@ describe('3dtiles_batch_table', function _() { // Verifies that the batch id, batch table and batch table hierarchy // extension picked information are correct for object at { x: 218, y: 90 } it('should return the batch table and batch hierarchy picked information', - async () => { + async function _it() { // Picks the object at (218,90) and gets its closest c3DTileFeature const pickResult = await page.evaluate( () => { @@ -70,8 +70,8 @@ describe('3dtiles_batch_table', function _() { }, }, }; - const expectedBatchId = 29; - assert.deepStrictEqual(pickResult.batchId, expectedBatchId); + + assert.equal(pickResult.batchId, 29); assert.deepStrictEqual(pickResult.info, expectedPickingInfo); }); }); diff --git a/test/unit/dataSourceProvider.js b/test/unit/dataSourceProvider.js index b1a1fe435f..f88f0d55c5 100644 --- a/test/unit/dataSourceProvider.js +++ b/test/unit/dataSourceProvider.js @@ -21,14 +21,14 @@ import Feature2Mesh from 'Converter/Feature2Mesh'; import LayeredMaterial from 'Renderer/LayeredMaterial'; import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile'; -const holes = require('../data/geojson/holesPoints.geojson.json'); +import holes from '../data/geojson/holesPoints.geojson.json'; describe('Provide in Sources', function () { // /!\ Avoid to overload fetcher because could troubleshoot the other unit tests? // formatTag to avoid it const formatTag = 'dspUnitTest'; supportedFetchers.set(`${formatTag}image/png`, () => Promise.resolve(new THREE.Texture())); - supportedFetchers.set(`${formatTag}application/json`, () => Promise.resolve(holes)); + supportedFetchers.set(`${formatTag}application/json`, () => Promise.resolve(JSON.parse(holes))); supportedParsers.set(`${formatTag}image/png`, supportedParsers.get('image/png')); supportedParsers.set(`${formatTag}application/json`, supportedParsers.get('application/json')); diff --git a/test/unit/feature2mesh.js b/test/unit/feature2mesh.js index cb25096e31..4027c9dcbd 100644 --- a/test/unit/feature2mesh.js +++ b/test/unit/feature2mesh.js @@ -4,9 +4,9 @@ import assert from 'assert'; import GeoJsonParser from 'Parser/GeoJsonParser'; import Feature2Mesh from 'Converter/Feature2Mesh'; -const geojson = require('../data/geojson/holes.geojson.json'); -const geojson2 = require('../data/geojson/simple.geojson.json'); -const geojson3 = require('../data/geojson/points.geojson.json'); +import geojson from '../data/geojson/holes.geojson.json'; +import geojson2 from '../data/geojson/simple.geojson.json'; +import geojson3 from '../data/geojson/points.geojson.json'; proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); diff --git a/test/unit/featureUtils.js b/test/unit/featureUtils.js index 205c002309..99cc0b2557 100644 --- a/test/unit/featureUtils.js +++ b/test/unit/featureUtils.js @@ -4,7 +4,7 @@ import FeaturesUtils from 'Utils/FeaturesUtils'; import Coordinates from 'Core/Geographic/Coordinates'; import { FEATURE_TYPES } from 'Core/Feature'; -const geojson = require('../data/geojson/simple.geojson.json'); +import geojson from '../data/geojson/simple.geojson.json'; describe('FeaturesUtils', function () { const options = { out: { crs: 'EPSG:4326', buildExtent: true, mergeFeatures: false, structure: '3d' } }; diff --git a/test/unit/featuregeometrylayererror.js b/test/unit/featuregeometrylayererror.js index ecfcc6ff36..ea3629f1e2 100644 --- a/test/unit/featuregeometrylayererror.js +++ b/test/unit/featuregeometrylayererror.js @@ -10,9 +10,9 @@ import OBB from 'Renderer/OBB'; import TileMesh from 'Core/TileMesh'; import Renderer from './bootstrap'; -const geojson_big = require('../data/geojson/map_big.geojson.json'); -const geojson_a = require('../data/geojson/map.geojson.json'); -const geojson_small = require('../data/geojson/map_small.geojson.json'); +import geojson_big from '../data/geojson/map_big.geojson.json'; +import geojson_a from '../data/geojson/map.geojson.json'; +import geojson_small from '../data/geojson/map_small.geojson.json'; const files = [geojson_small, geojson_a, geojson_big]; const errors = [3e-4, 5e-2, 35]; diff --git a/test/unit/geojson.js b/test/unit/geojson.js index 107df45833..b5bbd61336 100644 --- a/test/unit/geojson.js +++ b/test/unit/geojson.js @@ -3,9 +3,9 @@ import assert from 'assert'; import GeoJsonParser from 'Parser/GeoJsonParser'; import Extent from 'Core/Geographic/Extent'; -const holes = require('../data/geojson/holes.geojson.json'); -const gpx = require('../data/geojson/gpx.geojson.json'); -const points = require('../data/geojson/points.geojson.json'); +import holes from '../data/geojson/holes.geojson.json'; +import gpx from '../data/geojson/gpx.geojson.json'; +import points from '../data/geojson/points.geojson.json'; proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); diff --git a/test/unit/label.js b/test/unit/label.js index a0c5c7db6d..09e3de6b16 100644 --- a/test/unit/label.js +++ b/test/unit/label.js @@ -12,7 +12,7 @@ import FileSource from 'Source/FileSource'; import { HttpsProxyAgent } from 'https-proxy-agent'; import Renderer from './bootstrap'; -const geojson = require('../data/geojson/simple.geojson.json'); +import geojson from '../data/geojson/simple.geojson.json'; describe('LabelLayer', function () { let layer; diff --git a/test/unit/vectortiles.js b/test/unit/vectortiles.js index 80d9366395..2a049eeab2 100644 --- a/test/unit/vectortiles.js +++ b/test/unit/vectortiles.js @@ -124,7 +124,7 @@ describe('Vector tiles', function () { }).catch(done); }); - it('loads the style from a file', (done) => { + it('loads the style from a file', function _(done) { const source = new VectorTilesSource({ style: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/vectortiles/style.json', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {},