Skip to content

Commit

Permalink
Fix pickObjects when using binary data (#8253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Nov 11, 2023
1 parent b16f515 commit e2b1fd8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
9 changes: 7 additions & 2 deletions modules/core/src/lib/deck-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,13 @@ export default class DeckPicker {
};

info = getLayerPickingInfo({layer: pickInfo.pickedLayer as Layer, info, mode});
if (!uniqueInfos.has(info.object)) {
uniqueInfos.set(info.object, info);

// info.object may be null if the layer is using non-iterable data.
// Fall back to using <layer_id>[<index>] as identifier.
// info.layer is always populated because it's a picked pixel
const pickedObjectKey = info.object ?? `${info.layer!.id}[${info.index}]`;
if (!uniqueInfos.has(pickedObjectKey)) {
uniqueInfos.set(pickedObjectKey, info);
}
}

Expand Down
91 changes: 90 additions & 1 deletion test/modules/core/lib/pick-layers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,95 @@ const TEST_CASES = [
]
}
},
{
id: 'scatterplotLayer-binary',
props: {
layers: [
new ScatterplotLayer({
data: {
length: DATA.points.length,
attributes: {
getPosition: {
value: new Float64Array(DATA.points.flatMap(d => d.COORDINATES)),
size: 2
},
getRadius: {value: new Float32Array(DATA.points.map(d => d.SPACES)), size: 1}
}
},
pickable: true,
radiusScale: 30,
radiusMinPixels: 1,
radiusMaxPixels: 30
})
]
},
pickingMethods: {
pickObject: [
{
parameters: {
x: 60,
y: 160
},
results: {
count: 1
}
},
{
parameters: {
x: 90,
y: 350
},
results: {
count: 0
}
}
],
pickObjects: [
{
parameters: {
x: 300,
y: 300,
width: 100,
height: 100
},
results: {
count: 34
}
},
{
parameters: {
x: 50,
y: 50,
width: 10,
height: 10
},
results: {
count: 0
}
}
],
pickMultipleObjects: [
{
parameters: {
x: 250,
y: 273
},
results: {
count: 2
}
},
{
parameters: {
x: 300,
y: 300
},
results: {
count: 0
}
}
]
}
},
{
id: 'scatterplotLayer-masked',
props: {
Expand Down Expand Up @@ -686,7 +775,7 @@ test(`pickingTest`, t => {

if (pickInfos.length > 1) {
t.equal(
new Set(pickInfos.map(x => x.object)).size,
new Set(pickInfos.map(x => x.object ?? x.index)).size,
pickInfos.length,
'Returned distinct picked objects'
);
Expand Down

0 comments on commit e2b1fd8

Please sign in to comment.