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 and Pessimistress committed Nov 21, 2024
1 parent 5db714f commit 95c4e2a
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 @@ -70,13 +70,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 @@ -74,7 +74,7 @@ export function createLayerPropsFromBinary(
...points.attributes,
getPosition: points.positions,
instancePickingColors: {
size: 3,
size: 4,
value: customPickingColors.points!
}
},
Expand All @@ -90,7 +90,7 @@ export function createLayerPropsFromBinary(
...lines.attributes,
getPath: lines.positions,
instancePickingColors: {
size: 3,
size: 4,
value: customPickingColors.lines!
}
},
Expand All @@ -107,7 +107,7 @@ export function createLayerPropsFromBinary(
...polygons.attributes,
getPolygon: polygons.positions,
pickingColors: {
size: 3,
size: 4,
value: customPickingColors.polygons!
}
},
Expand All @@ -127,7 +127,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 @@ -127,8 +127,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 @@ -40,6 +40,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 95c4e2a

Please sign in to comment.