Skip to content

Commit

Permalink
Add code path through shield.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeLonewolf committed Nov 2, 2023
1 parent c73143e commit 2c353b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
9 changes: 5 additions & 4 deletions shieldlib/src/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ function drawShieldText(r, ctx, shieldDef, routeDef) {
return ctx;
}

export function missingIconLoader(r, routeDef, spriteID) {
export function missingIconLoader(r, routeDef, spriteID, update) {
let ctx = generateShieldCtx(r, routeDef);
if (ctx == null) {
// Want to return null here, but that gives a corrupted display. See #243
console.warn("Didn't produce a shield for", JSON.stringify(routeDef));
ctx = r.gfxFactory.createGraphics({ width: 1, height: 1 });
}
storeSprite(r, spriteID, ctx);
storeSprite(r, spriteID, ctx, update);
}

function storeSprite(r, id, ctx) {
function storeSprite(r, id, ctx, update) {
const imgData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
r.spriteRepo.putSprite(
id,
Expand All @@ -185,7 +185,8 @@ function storeSprite(r, id, ctx) {
height: ctx.canvas.height,
data: imgData.data,
},
r.px(1)
r.px(1),
update
);
}

Expand Down
4 changes: 3 additions & 1 deletion shieldlib/src/shield_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ class MaplibreGLSpriteRepository implements SpriteRepository {
spriteID: string,
image: ImageData,
pixelRatio: number,
update?: boolean
update: boolean
): void {
if (update) {
console.log(`update ${spriteID}`);
this.map.updateImage(spriteID, image);
} else {
console.log(`add ${spriteID}`);
this.map.addImage(spriteID, image, { pixelRatio: pixelRatio });
}
}
Expand Down
7 changes: 6 additions & 1 deletion shieldlib/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export interface SpriteProducer {
getSprite(spriteID: string): StyleImage;
}
export interface SpriteConsumer {
putSprite(spriteID: string, image: ImageData, pixelRatio: number): void;
putSprite(
spriteID: string,
image: ImageData,
pixelRatio: number,
update: boolean
): void;
}
export type SpriteRepository = SpriteProducer & SpriteConsumer;
export interface ShieldDefinitions {
Expand Down
2 changes: 1 addition & 1 deletion shieldlib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface SpriteConsumer {
spriteID: string,
image: ImageData,
pixelRatio: number,
update?: boolean
update: boolean
): void;
}

Expand Down

0 comments on commit 2c353b3

Please sign in to comment.