Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 17, 2023
1 parent 40541a1 commit c8d3ce6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions test/unit/vectortiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)');
Expand Down

0 comments on commit c8d3ce6

Please sign in to comment.