Skip to content

Commit

Permalink
DEV-8542 - pass the url for GridMap instead of processing it (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-mazepas authored Jun 10, 2024
1 parent c41d487 commit 1497a6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
32 changes: 3 additions & 29 deletions packages/data-sdk/src/connector/data/TelemetryUniverseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,41 +458,15 @@ export class TelemetryUniverseData
const latestLocalization = ev.data.response.map;

if (latestLocalization) {
const canvas = document.createElement("canvas");
const image = await this.fetchImage(latestLocalization.url);
canvas.width = image.width;
canvas.height = image.height;

const ctx = canvas.getContext("2d", {
willReadFrequently: true,
});
if (ctx) {
ctx.drawImage(image, 0, 0);
}
const pixelData = ctx?.getImageData(
0,
0,
image.width,
image.height
);
const mapData: number[] = [];
const alphaData: number[] = [];
if (pixelData) {
for (let i = 0; i < pixelData.data.length; i += 4) {
const r = pixelData.data[i];
const a = pixelData.data[i + 3];
mapData.push(r);
alphaData.push(a);
}
}
const gridValue = {
width: latestLocalization.width,
height: latestLocalization.height,
worldToLocal: latestLocalization.worldToLocal,
resolution: latestLocalization.resolution,
origin: latestLocalization.origin,
alpha: alphaData,
data: mapData,
url: latestLocalization.url,
//alpha: alphaData,
//data: mapData,
};
mapDataCache[dp.url!] = JSON.parse(JSON.stringify(gridValue));
callback(gridValue);
Expand Down
5 changes: 3 additions & 2 deletions packages/data-sdk/src/connector/model/IUniverseGridMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IUniverseGridMap {
height: number;
resolution: number;
origin: ITransform;
data: number[];
alpha: number[];
url?: string;
data?: number[];
alpha?: number[];
}

0 comments on commit 1497a6e

Please sign in to comment.