From e53332de474470f490fe6224e997c548bcf661f0 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 14 Dec 2023 22:44:12 -0500 Subject: [PATCH] Plumb StyleImageMetadata --- shieldlib/src/shield.js | 8 ++------ shieldlib/src/shield_renderer.d.ts | 14 ++++++++++++-- shieldlib/src/shield_renderer.ts | 5 +++-- shieldlib/src/types.ts | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/shieldlib/src/shield.js b/shieldlib/src/shield.js index 698cc254b..f8d3c342d 100644 --- a/shieldlib/src/shield.js +++ b/shieldlib/src/shield.js @@ -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 { @@ -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 ); } diff --git a/shieldlib/src/shield_renderer.d.ts b/shieldlib/src/shield_renderer.d.ts index fc9d9ac19..a136a7c2d 100644 --- a/shieldlib/src/shield_renderer.d.ts +++ b/shieldlib/src/shield_renderer.d.ts @@ -1,4 +1,9 @@ -import { Map, MapStyleImageMissingEvent, StyleImage } from "maplibre-gl"; +import { + Map, + MapStyleImageMissingEvent, + StyleImage, + StyleImageMetadata, +} from "maplibre-gl"; import { Bounds, DebugOptions, @@ -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 {}; diff --git a/shieldlib/src/shield_renderer.ts b/shieldlib/src/shield_renderer.ts index b01f40251..3596d0875 100644 --- a/shieldlib/src/shield_renderer.ts +++ b/shieldlib/src/shield_renderer.ts @@ -2,6 +2,7 @@ import { Map as MapLibre, MapStyleImageMissingEvent, StyleImage, + StyleImageMetadata, } from "maplibre-gl"; import { Bounds, @@ -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); } } } diff --git a/shieldlib/src/types.ts b/shieldlib/src/types.ts index e4063e486..5ba35c4c9 100644 --- a/shieldlib/src/types.ts +++ b/shieldlib/src/types.ts @@ -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 { @@ -138,7 +138,7 @@ export interface SpriteConsumer { putSprite( spriteID: string, image: ImageData, - pixelRatio: number, + options: StyleImageMetadata, update: boolean ): void; }