Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Add resizeKernel into the config tileset then disable fastShrinkOnLoad. BM-1146 #3377

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/config-loader/src/json/json.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class ConfigJson {
if (tileSet.type === TileSetType.Raster) {
if (ts.outputs) tileSet.outputs = ts.outputs;
if (ts.background) tileSet.background = ts.background;
if (ts.resizeKernel) tileSet.resizeKernel = ts.resizeKernel;
}

if (ts.format) {
Expand Down
5 changes: 4 additions & 1 deletion packages/config-loader/src/json/parse.tile.set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigTileSetOutputParser, parseRgba, TileSetType } from '@basemaps/config';
import { ConfigTileSetOutputParser, parseRgba, TileResizeKernel, TileSetType } from '@basemaps/config';
import { z } from 'zod';

export function validateColor(str: string): boolean {
Expand Down Expand Up @@ -57,6 +57,8 @@ const zLayerConfig = z
},
);

const TileResizeKernel = z.enum(['nearest', 'mitchell', 'lanczos3', 'lanczos2']);

export const zTileSetConfig = z.object({
type: z.nativeEnum(TileSetType),
id: z.string(),
Expand All @@ -68,6 +70,7 @@ export const zTileSetConfig = z.object({
minZoom: zZoom.optional(),
maxZoom: zZoom.optional(),
format: z.string().optional(),
resizeKernel: z.object({ in: TileResizeKernel, out: TileResizeKernel }).optional(),
outputs: z.array(ConfigTileSetOutputParser).optional(),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/config/tile.set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ConfigLayer extends Partial<Record<EpsgCode, string>> {
maxZoom?: number;
}

export type TileResizeKernel = 'nearest' | 'lanczos3' | 'lanczos2';
export type TileResizeKernel = 'nearest' | 'mitchell' | 'lanczos3' | 'lanczos2';

export interface ConfigTileSetBase extends ConfigBase {
/** Human friendly display name for the tileset */
Expand Down
7 changes: 6 additions & 1 deletion packages/tiler-sharp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ export class TileMakerSharp implements TileMaker {

if (resize) {
const resizeOptions = { fit: Sharp.fit.cover, kernel: resize.scaleX > 1 ? resizeKernel.in : resizeKernel.out };
sharp.resize(resize.width, resize.height, resizeOptions);
if (resize.scale <= 0.1251) {
blacha marked this conversation as resolved.
Show resolved Hide resolved
// If the scale is less than 0.125, we need to disable fastShrinkOnLoad to prevent edge artifacts for topo raster map
sharp.resize(resize.width, resize.height, { ...resizeOptions, fastShrinkOnLoad: false });
} else {
sharp.resize(resize.width, resize.height, resizeOptions);
}
}

if (crop) sharp.extract({ top: crop.y, left: crop.x, width: crop.width, height: crop.height });
Expand Down
2 changes: 1 addition & 1 deletion packages/tiler/src/raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TileMaker {
compose(ctx: TileMakerContext): Promise<{ buffer: Buffer; metrics: Metrics }>;
}

export type ResizeKernelType = 'nearest' | 'lanczos3' | 'lanczos2';
export type ResizeKernelType = 'nearest' | 'mitchell' | 'lanczos3' | 'lanczos2';
blacha marked this conversation as resolved.
Show resolved Hide resolved
export type TileMakerResizeKernel = { in: ResizeKernelType; out: ResizeKernelType };

export interface TileMakerContext {
Expand Down
Loading