Skip to content

Commit

Permalink
Merge branch 'master' into feat/cogify-add-background-color-support
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Dec 23, 2024
2 parents be702cb + 8072eb9 commit d95ad68
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 35 deletions.
1 change: 0 additions & 1 deletion packages/config-loader/src/json/json.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ 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: 1 addition & 4 deletions 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, TileResizeKernel, TileSetType } from '@basemaps/config';
import { ConfigTileSetOutputParser, parseRgba, TileSetType } from '@basemaps/config';
import { z } from 'zod';

export function validateColor(str: string): boolean {
Expand Down Expand Up @@ -57,8 +57,6 @@ 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 @@ -70,7 +68,6 @@ 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' | 'mitchell' | 'lanczos3' | 'lanczos2';
export type TileResizeKernel = 'nearest' | 'lanczos3' | 'lanczos2';

export interface ConfigTileSetBase extends ConfigBase {
/** Human friendly display name for the tileset */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Categories = [
'Rural Aerial Photos',
'Scanned Aerial Imagery',
'Event',
'Topographic',
'Bathymetry',
'Elevation',
];
Expand Down
2 changes: 1 addition & 1 deletion packages/landing/src/components/map.label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IControl } from 'maplibre-gl';

import { Config, GaEvent, gaEvent } from '../config.js';

export const LabelsDisabledLayers = new Set(['topographic', 'topolite']);
export const LabelsDisabledLayers = new Set(['topographic', 'topolite', 'topo-raster']);

export class MapLabelControl implements IControl {
map?: maplibregl.Map;
Expand Down
41 changes: 20 additions & 21 deletions packages/landing/src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,26 @@ export class Basemaps extends Component<unknown, { isLayerSwitcherEnabled: boole
};

updateBounds = (bounds: maplibregl.LngLatBoundsLike): void => {
if (Config.map.tileMatrix !== GoogleTms) {
// Transform bounds to current tileMatrix
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
const upperLeft = lngLatBounds.getNorthEast();
const lowerRight = lngLatBounds.getSouthWest();
const zoom = this.map.getZoom();
const upperLeftLocation = locationTransform(
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
const lowerRightLocation = locationTransform(
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
bounds = [
[upperLeftLocation.lon, upperLeftLocation.lat],
[lowerRightLocation.lon, lowerRightLocation.lat],
];
}
// Transform bounds to current tileMatrix
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
const upperLeft = lngLatBounds.getNorthEast();
const lowerRight = lngLatBounds.getSouthWest();
const zoom = this.map.getZoom();
const upperLeftLocation = locationTransform(
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
const lowerRightLocation = locationTransform(
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
bounds = [
[upperLeftLocation.lon, upperLeftLocation.lat],
[lowerRightLocation.lon, lowerRightLocation.lat],
];

this.map.fitBounds(bounds);
};

Expand Down
7 changes: 7 additions & 0 deletions packages/landing/src/config.map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ function addDefaultLayers(output: Map<string, LayerInfo>): void {
category: 'Basemaps',
},

{
id: 'topo-raster::topo-raster',
title: 'NZ Topo Gridless Maps',
projections: new Set([EpsgCode.Nztm2000, EpsgCode.Google]),
category: 'Basemaps',
},

{
id: 'elevation',
title: 'Elevation',
Expand Down
7 changes: 1 addition & 6 deletions packages/tiler-sharp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ export class TileMakerSharp implements TileMaker {

if (resize) {
const resizeOptions = { fit: Sharp.fit.cover, kernel: resize.scaleX > 1 ? resizeKernel.in : resizeKernel.out };
if (resize.scale <= 0.1251) {
// 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);
}
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' | 'mitchell' | 'lanczos3' | 'lanczos2';
export type ResizeKernelType = 'nearest' | 'lanczos3' | 'lanczos2';
export type TileMakerResizeKernel = { in: ResizeKernelType; out: ResizeKernelType };

export interface TileMakerContext {
Expand Down

0 comments on commit d95ad68

Please sign in to comment.