Skip to content

Commit

Permalink
Plumb StyleImageMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeLonewolf committed Dec 15, 2023
1 parent 8453a8d commit e53332d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
8 changes: 2 additions & 6 deletions shieldlib/src/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import * as ShieldText from "./shield_text";
import * as ShieldDraw from "./shield_canvas_draw";
import * as Gfx from "./screen_gfx";
import {
drawBanners,
drawBannerHalos,
getBannerCount,
} from "./shield_banner";
import { drawBanners, drawBannerHalos, getBannerCount } from "./shield_banner";

function compoundShieldSize(r, dimension, bannerCount) {
return {
Expand Down Expand Up @@ -185,7 +181,7 @@ function storeSprite(r, id, ctx, update) {
height: ctx.canvas.height,
data: imgData.data,
},
r.px(1),
{ pixelRatio: r.px(1) },
update
);
}
Expand Down
14 changes: 12 additions & 2 deletions shieldlib/src/shield_renderer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Map, MapStyleImageMissingEvent, StyleImage } from "maplibre-gl";
import {
Map,
MapStyleImageMissingEvent,
StyleImage,
StyleImageMetadata,
} from "maplibre-gl";
import {
Bounds,
DebugOptions,
Expand Down Expand Up @@ -62,6 +67,11 @@ export declare class InMemorySpriteRepository implements SpriteRepository {
sprites: {};
getSprite(spriteID: string): StyleImage;
hasSprite(spriteID: string): boolean;
putSprite(spriteID: string, image: ImageData): void;
putSprite(
spriteID: string,
image: ImageData,
options: StyleImageMetadata,
update: boolean
): void;
}
export {};
5 changes: 3 additions & 2 deletions shieldlib/src/shield_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Map as MapLibre,
MapStyleImageMissingEvent,
StyleImage,
StyleImageMetadata,
} from "maplibre-gl";
import {
Bounds,
Expand Down Expand Up @@ -66,14 +67,14 @@ class MaplibreGLSpriteRepository implements SpriteRepository {
putSprite(
spriteID: string,
image: ImageData,
pixelRatio: number,
options: StyleImageMetadata,
update: boolean
): void {
if (update) {
this.map.removeImage(spriteID);
this.map.addImage(spriteID, image);
} else {
this.map.addImage(spriteID, image, { pixelRatio: pixelRatio });
this.map.addImage(spriteID, image, options);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions shieldlib/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleImage } from "maplibre-gl";
import { StyleImage, StyleImageMetadata } from "maplibre-gl";

/** Defines the set of routes that a shield applies to */
export interface RouteDefinition {
Expand Down Expand Up @@ -138,7 +138,7 @@ export interface SpriteConsumer {
putSprite(
spriteID: string,
image: ImageData,
pixelRatio: number,
options: StyleImageMetadata,
update: boolean
): void;
}
Expand Down

0 comments on commit e53332d

Please sign in to comment.