Skip to content

Commit

Permalink
fix(layers): Fix MVTLayer + pickMultipleObjects (#9246)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Nov 14, 2024
1 parent 27d2010 commit 81371bf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
9 changes: 5 additions & 4 deletions modules/layers/src/geojson-layer/geojson-binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ export function calculatePickingColors(
};
for (const key in pickingColors) {
const featureIds = geojsonBinary[key].globalFeatureIds.value;
pickingColors[key] = new Uint8ClampedArray(featureIds.length * 3);
pickingColors[key] = new Uint8ClampedArray(featureIds.length * 4);
const pickingColor = [];
for (let i = 0; i < featureIds.length; i++) {
encodePickingColor(featureIds[i], pickingColor);
pickingColors[key][i * 3 + 0] = pickingColor[0];
pickingColors[key][i * 3 + 1] = pickingColor[1];
pickingColors[key][i * 3 + 2] = pickingColor[2];
pickingColors[key][i * 4 + 0] = pickingColor[0];
pickingColors[key][i * 4 + 1] = pickingColor[1];
pickingColors[key][i * 4 + 2] = pickingColor[2];
pickingColors[key][i * 4 + 3] = 255;
}
}

Expand Down
8 changes: 4 additions & 4 deletions modules/layers/src/geojson-layer/geojson-layer-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function createLayerPropsFromBinary(
...points.attributes,
getPosition: points.positions,
instancePickingColors: {
size: 3,
size: 4,
value: customPickingColors.points!
}
},
Expand All @@ -94,7 +94,7 @@ export function createLayerPropsFromBinary(
...lines.attributes,
getPath: lines.positions,
instancePickingColors: {
size: 3,
size: 4,
value: customPickingColors.lines!
}
},
Expand All @@ -111,7 +111,7 @@ export function createLayerPropsFromBinary(
...polygons.attributes,
getPolygon: polygons.positions,
pickingColors: {
size: 3,
size: 4,
value: customPickingColors.polygons!
}
},
Expand All @@ -131,7 +131,7 @@ export function createLayerPropsFromBinary(
...polygons.attributes,
getPath: polygons.positions,
instancePickingColors: {
size: 3,
size: 4,
value: customPickingColors.polygons!
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/bench/layer.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export default function layerBench(suite) {
})
.add('calculate instance picking colors', () => {
const numInstances = 1e6;
const target = new Uint8ClampedArray(numInstances * 3);
const target = new Uint8ClampedArray(numInstances * 4);
testLayer.internalState = {};
testLayer.calculateInstancePickingColors({value: target, size: 3}, {numInstances});
testLayer.calculateInstancePickingColors({value: target, size: 4}, {numInstances});
});
}
11 changes: 9 additions & 2 deletions test/modules/layers/data/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export const geoJSONData = [
];

// prettier-ignore
export const pickingColorsSample = Uint8ClampedArray.from([
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0
export const pickingColorsSample = Uint8ClampedArray.from([
1, 0, 0, 255,
1, 0, 0, 255,
1, 0, 0, 255,
1, 0, 0, 255,
2, 0, 0, 255,
2, 0, 0, 255,
2, 0, 0, 255,
2, 0, 0, 255,
]);

0 comments on commit 81371bf

Please sign in to comment.