Skip to content

Commit aca530c

Browse files
authored
Correct data.length for MVTLayer polygons (visgl#5853)
1 parent 087fb46 commit aca530c

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

modules/layers/src/geojson-layer/geojson-layer-props.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export function createLayerPropsFromBinary(geojsonBinary, uniqueIdProperty, enco
7979
layerProps.lines._pathType = 'open';
8080

8181
layerProps.polygons.data = {
82-
length: polygons.primitivePolygonIndices.value.length,
83-
startIndices: polygons.primitivePolygonIndices.value,
82+
length: polygons.polygonIndices.value.length - 1,
83+
startIndices: polygons.polygonIndices.value,
8484
attributes: {
8585
getPolygon: polygons.positions,
8686
pickingColors: {
@@ -98,7 +98,7 @@ export function createLayerPropsFromBinary(geojsonBinary, uniqueIdProperty, enco
9898
}
9999

100100
layerProps.polygonsOutline.data = {
101-
length: polygons.primitivePolygonIndices.value.length,
101+
length: polygons.primitivePolygonIndices.value.length - 1,
102102
startIndices: polygons.primitivePolygonIndices.value,
103103
attributes: {
104104
getPath: polygons.positions,

test/modules/geo-layers/mvt-layer.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,60 @@ test('MVTLayer#triangulation', async t => {
457457

458458
t.end();
459459
});
460+
461+
for (const tileset of ['mvt-tiles', 'mvt-with-hole']) {
462+
test(`MVTLayer#data.length ${tileset}`, async t => {
463+
const viewport = new WebMercatorViewport({
464+
longitude: -100,
465+
latitude: 40,
466+
zoom: 3,
467+
pitch: 0,
468+
bearing: 0
469+
});
470+
471+
let binaryDataLength;
472+
let geoJsonDataLength;
473+
let requests = 0;
474+
const onAfterUpdate = ({layer}) => {
475+
if (!layer.isLoaded) {
476+
return;
477+
}
478+
const geoJsonLayer = layer.internalState.subLayers[0];
479+
const polygons = geoJsonLayer.state.layerProps.polygons;
480+
if (layer.props.binary) {
481+
binaryDataLength = polygons.data.length;
482+
requests++;
483+
} else {
484+
geoJsonDataLength = polygons.data.length;
485+
requests++;
486+
}
487+
488+
if (requests === 2) {
489+
t.equals(geoJsonDataLength, binaryDataLength, 'should have equal length');
490+
}
491+
};
492+
493+
// To avoid caching use different URLs
494+
const url1 = [`./test/data/${tileset}/{z}/{x}/{y}.mvt?test1`];
495+
const url2 = [`./test/data/${tileset}/{z}/{x}/{y}.mvt?test2`];
496+
const props = {
497+
onTileError: error => {
498+
if (!(error.message && error.message.includes('404'))) {
499+
throw error;
500+
}
501+
},
502+
loadOptions: {
503+
mvt: {
504+
workerUrl: null
505+
}
506+
}
507+
};
508+
const testCases = [
509+
{props: {binary: false, data: url1, ...props}, onAfterUpdate},
510+
{props: {binary: true, data: url2, ...props}, onAfterUpdate}
511+
];
512+
513+
await testLayerAsync({Layer: MVTLayer, viewport, testCases, onError: t.notOk});
514+
t.end();
515+
});
516+
}

0 commit comments

Comments
 (0)