Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MAPSJS-2783: Fix dynamic technique keys for array buffers.
Browse files Browse the repository at this point in the history
Dynamic technique keys are generated using JSON.stringify on the
technique property values. However ArrayBuffers (used for texture
properties) return always the same string "{}", causing a collision
in the dynamic technique cache between different techniques.

This is solved by converting array buffers to arrays before stringifying.

Signed-off-by: Andres Mandado <[email protected]>
  • Loading branch information
atomicsulfate committed Apr 26, 2021
1 parent 720a32d commit e04d289
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions @here/harp-datasource-protocol/lib/StyleSetEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ export class StyleSetEvaluator {
.map(([_attrName, attrValue]) => {
if (attrValue === undefined) {
return "U";
} else if (typeof attrValue === "object") {
return JSON.stringify(attrValue, (key, value) => {
// ArrayBuffers cannot be directly stringified, convert them to arrays.
return value instanceof ArrayBuffer ? new Uint8Array(value) : value;
});
} else {
return JSON.stringify(attrValue);
}
Expand Down
24 changes: 24 additions & 0 deletions @here/harp-datasource-protocol/test/StyleSetEvaluatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,30 @@ describe("StyleSetEvaluator", function () {
assert.deepEqual(techniquesTileA[2], techniquesTileB[0]);
assert.deepEqual(techniquesTileA[0], techniquesTileC[1]);
});

it("technique cache key changes for different array buffers", function () {
const texturedStyle: StyleSet = [
{
technique: "fill",
when: "kind == 'park'",
attr: {
map: ["get", "map"]
}
}
];

const buffer1 = new Uint8Array([1, 2, 3, 4]).buffer;
const buffer2 = new Uint8Array([4, 3, 2, 1]).buffer;

const techniquesTileA = (() => {
const ev = new StyleSetEvaluator({ styleSet: texturedStyle });
ev.getMatchingTechniques(new MapEnv({ kind: "park", map: { buffer: buffer1 } }));
ev.getMatchingTechniques(new MapEnv({ kind: "park", map: { buffer: buffer2 } }));
return ev.decodedTechniques;
})();

assert.equal(techniquesTileA.length, 2);
});
});
describe('definitions / "ref" operator support', function () {
const sampleStyleDeclaration: Style = {
Expand Down

0 comments on commit e04d289

Please sign in to comment.