Skip to content

Commit

Permalink
Correct data.length for MVTLayer polygons (visgl#5853)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Jun 16, 2021
1 parent 087fb46 commit aca530c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/layers/src/geojson-layer/geojson-layer-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function createLayerPropsFromBinary(geojsonBinary, uniqueIdProperty, enco
layerProps.lines._pathType = 'open';

layerProps.polygons.data = {
length: polygons.primitivePolygonIndices.value.length,
startIndices: polygons.primitivePolygonIndices.value,
length: polygons.polygonIndices.value.length - 1,
startIndices: polygons.polygonIndices.value,
attributes: {
getPolygon: polygons.positions,
pickingColors: {
Expand All @@ -98,7 +98,7 @@ export function createLayerPropsFromBinary(geojsonBinary, uniqueIdProperty, enco
}

layerProps.polygonsOutline.data = {
length: polygons.primitivePolygonIndices.value.length,
length: polygons.primitivePolygonIndices.value.length - 1,
startIndices: polygons.primitivePolygonIndices.value,
attributes: {
getPath: polygons.positions,
Expand Down
57 changes: 57 additions & 0 deletions test/modules/geo-layers/mvt-layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,60 @@ test('MVTLayer#triangulation', async t => {

t.end();
});

for (const tileset of ['mvt-tiles', 'mvt-with-hole']) {
test(`MVTLayer#data.length ${tileset}`, async t => {
const viewport = new WebMercatorViewport({
longitude: -100,
latitude: 40,
zoom: 3,
pitch: 0,
bearing: 0
});

let binaryDataLength;
let geoJsonDataLength;
let requests = 0;
const onAfterUpdate = ({layer}) => {
if (!layer.isLoaded) {
return;
}
const geoJsonLayer = layer.internalState.subLayers[0];
const polygons = geoJsonLayer.state.layerProps.polygons;
if (layer.props.binary) {
binaryDataLength = polygons.data.length;
requests++;
} else {
geoJsonDataLength = polygons.data.length;
requests++;
}

if (requests === 2) {
t.equals(geoJsonDataLength, binaryDataLength, 'should have equal length');
}
};

// To avoid caching use different URLs
const url1 = [`./test/data/${tileset}/{z}/{x}/{y}.mvt?test1`];
const url2 = [`./test/data/${tileset}/{z}/{x}/{y}.mvt?test2`];
const props = {
onTileError: error => {
if (!(error.message && error.message.includes('404'))) {
throw error;
}
},
loadOptions: {
mvt: {
workerUrl: null
}
}
};
const testCases = [
{props: {binary: false, data: url1, ...props}, onAfterUpdate},
{props: {binary: true, data: url2, ...props}, onAfterUpdate}
];

await testLayerAsync({Layer: MVTLayer, viewport, testCases, onError: t.notOk});
t.end();
});
}

0 comments on commit aca530c

Please sign in to comment.