Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(layers): Fix MVTLayer + pickMultipleObjects #9246

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
]);
Loading