Skip to content

Commit

Permalink
fix(POI Masps): add pixel ratio option for image
Browse files Browse the repository at this point in the history
Allow to support HDI displays
  • Loading branch information
KevinFabre-ods committed Dec 7, 2023
1 parent c11c6f0 commit eab5b84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/visualizations/src/components/MapPoi/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@ export default class MapPOI {
* Load images into the map.
* Remove automatically any images previously loaded that are no longer defined in the images object.
*/
loadImages(images?: Record<string, string>) {
loadImages(images?: { [key: string]: string } & { pixelRatio?: number }) {
if (!images) return;
this.queue((map) => {
const { pixelRatio, ...rest } = images;
const loadedImages = map.listImages();
const imagesIds = Object.keys(images);
const imagesIds = Object.keys(rest);

const imagesToRemove = difference(loadedImages, imagesIds);
const imagesToAdd = difference(imagesIds, loadedImages);
Expand All @@ -345,7 +346,7 @@ export default class MapPOI {
// eslint-disable-next-line no-console
console.warn(`Fail to load image: ${imageId}`);
} else {
map.addImage(imageId, image);
map.addImage(imageId, image, { pixelRatio });
}
});
});
Expand Down
4 changes: 3 additions & 1 deletion packages/visualizations/src/components/MapPoi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface PoiMapOptions {
sourceLink?: Source;
cooperativeGestures?: boolean | GestureOptions;
/** Images to load by the Map. keys are image ids */
images?: Record<string, string>;
images?: { [key: string]: string } & { pixelRatio: number };
}

export type PoiMapStyleOption = Partial<Pick<StyleSpecification, 'sources' | 'layers'>>;
Expand Down Expand Up @@ -94,6 +94,8 @@ export type CircleLayer = BaseLayer & {

export type SymbolLayer = BaseLayer & {
type: SymbolLayerSpecification['type'];
/** Scales the original size of the icon by the provided factor. */
// iconSize: number,
/** id of the image to use as icon-image */
iconImageId: string;
/**
Expand Down

0 comments on commit eab5b84

Please sign in to comment.