From c8d3ce6fb6a1a973e904b7b6ed234fc6bacd49f5 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 15 Feb 2023 15:48:09 +0100 Subject: [PATCH] update unit tests --- src/Converter/Feature2Mesh.js | 12 ++++++------ test/unit/vectortiles.js | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index a8a98eb778..14dee38a45 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -221,7 +221,7 @@ function featureToPoint(feature, options) { const context = { globals, properties: () => geometry.properties }; // const style = new Style(feature.style).drawingStylefromContext(context); // const style = new Style(options.layer.style).drawingStylefromContext(context); - const style = new Style((options.layer && options.layer.style) || options.collection.style).drawingStylefromContext(context); + const style = new Style(options.layer?.style || options.collection.style).drawingStylefromContext(context); const start = geometry.indices[0].offset; const count = geometry.indices[0].count; @@ -269,7 +269,7 @@ function featureToLine(feature, options) { // TODO CREATE material for each feature // options.lineMaterial.linewidth = feature.style.stroke.width; - options.lineMaterial.linewidth = (options.layer && options.layer.style.stroke.width) || options.collection.style.stroke.width; + options.lineMaterial.linewidth = options.layer?.style.stroke.width || options.collection?.style?.stroke.width; const globals = { stroke: true }; if (feature.geometries.length > 1) { const countIndices = (count - feature.geometries.length) * 2; @@ -279,7 +279,7 @@ function featureToLine(feature, options) { for (const geometry of feature.geometries) { const context = { globals, properties: () => geometry.properties }; // const style = new Style(feature.style).drawingStylefromContext(context); - const style = new Style(options.layer.style).drawingStylefromContext(context); + const style = new Style(options.layer?.style).drawingStylefromContext(context); const start = geometry.indices[0].offset; // To avoid integer overflow with indice value (16 bits) @@ -312,7 +312,7 @@ function featureToLine(feature, options) { const context = { globals, properties: () => feature.geometries[0].properties }; // const style = new Style(feature.style).drawingStylefromContext(context); // const style = new Style(options.layer.style).drawingStylefromContext(context); - const style = new Style((options.layer && options.layer.style) || options.collection.style).drawingStylefromContext(context); + const style = new Style(options.layer?.style || options.collection.style).drawingStylefromContext(context); fillColorArray(colors, count, toColor(style.stroke.color)); geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true)); @@ -356,7 +356,7 @@ function featureToPolygon(feature, options) { } const context = { globals, properties: () => geometry.properties }; // const style = new Style(feature.style).drawingStylefromContext(context); - const style = new Style(options.layer.style).drawingStylefromContext(context); + const style = new Style(options.layer?.style).drawingStylefromContext(context); const lastIndice = geometry.indices.slice(-1)[0]; const end = lastIndice.offset + lastIndice.count; @@ -532,7 +532,7 @@ function featureToMesh(feature, options) { break; case FEATURE_TYPES.POLYGON: // if (feature.style.fill.extrusion_height) { - if (options.layer.style.fill.extrusion_height) { + if (options.layer && options.layer.style.fill.extrusion_height) { mesh = featureToExtrudedPolygon(feature, options); } else { mesh = featureToPolygon(feature, options); diff --git a/test/unit/vectortiles.js b/test/unit/vectortiles.js index 17acf35b3d..fb62d8ba37 100644 --- a/test/unit/vectortiles.js +++ b/test/unit/vectortiles.js @@ -5,6 +5,7 @@ import VectorTileParser from 'Parser/VectorTileParser'; import VectorTilesSource from 'Source/VectorTilesSource'; import Extent from 'Core/Geographic/Extent'; import urlParser from 'Parser/MapBoxUrlParser'; +import Style from 'Core/Style'; describe('Vector tiles', function () { // this PBF file comes from https://github.com/mapbox/vector-tile-js @@ -140,8 +141,8 @@ describe('Vector tiles', function () { }, }); source.whenReady.then(() => { - const styleLand_zoom_3 = source.styles.land.drawingStylefromContext({ globals: { zoom: 3 }, properties: () => {} }); - const styleLand_zoom_5 = source.styles.land.drawingStylefromContext({ globals: { zoom: 5 }, properties: () => {} }); + const styleLand_zoom_3 = new Style(source.styles.land).drawingStylefromContext({ globals: { zoom: 3 }, properties: () => {} }); + const styleLand_zoom_5 = new Style(source.styles.land).drawingStylefromContext({ globals: { zoom: 5 }, properties: () => {} }); assert.equal(styleLand_zoom_3.fill.color, 'rgb(255,0,0)'); assert.equal(styleLand_zoom_3.fill.opacity, 1); assert.equal(styleLand_zoom_5.fill.color, 'rgb(255,0,0)');