From 11ad9acc05d81e46035c1dad177c88d981f425dd Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Fri, 17 Feb 2023 12:31:14 +0100 Subject: [PATCH] fix: Correctly type simplify --- website/src/pages/api/_utils.ts | 3 +++ website/src/pages/api/generate.ts | 2 +- website/src/pages/api/v0.ts | 2 +- website/src/shared.ts | 15 +++++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/website/src/pages/api/_utils.ts b/website/src/pages/api/_utils.ts index 2c99443e..41acb519 100644 --- a/website/src/pages/api/_utils.ts +++ b/website/src/pages/api/_utils.ts @@ -52,6 +52,9 @@ export const parseOptions = (req: NextApiRequest, res: NextApiResponse) => { if (query.shapes) { draft.shapes = new Set(query.shapes.split(",") as $FixMe); } + if (query.simplify) { + draft.simplify = query.simplify; + } }); return options; diff --git a/website/src/pages/api/generate.ts b/website/src/pages/api/generate.ts index 834292e5..266d64d4 100644 --- a/website/src/pages/api/generate.ts +++ b/website/src/pages/api/generate.ts @@ -28,7 +28,7 @@ const generateFromShapefiles = async ({ format: "topojson" | "svg"; year: string; shpFilenames: string[]; - simplify?: number; + simplify?: string; }) => { const input = await (async () => { const props = shpFilenames.flatMap((shpFilename) => { diff --git a/website/src/pages/api/v0.ts b/website/src/pages/api/v0.ts index f26c0a02..e70c19cd 100644 --- a/website/src/pages/api/v0.ts +++ b/website/src/pages/api/v0.ts @@ -33,7 +33,7 @@ const generate = async ({ }: { format: "topojson" | "svg"; shpFilenames: string[]; - simplify: number; + simplify: string; mapshaperCommands?: string[]; }) => { const input = await (async () => { diff --git a/website/src/shared.ts b/website/src/shared.ts index a40173d1..6e5d3f12 100644 --- a/website/src/shared.ts +++ b/website/src/shared.ts @@ -18,7 +18,7 @@ export interface Options { projection: "wgs84" | "cartesian"; dimensions: { width: number; height: number }; year: string; - simplify: number; + simplify: string; shapes: Set; color: SupportedColorSchema; withName: boolean; @@ -29,7 +29,7 @@ export const defaultOptions: Options = { projection: "wgs84", dimensions: { width: 900, height: 600 }, year: "2022", - simplify: 0, + simplify: "0%", shapes: new Set(["country", "cantons", "lakes"]), color: "default", withName: true, @@ -39,14 +39,17 @@ export const defaultOptions: Options = { * Returns the URL to the TopoJSON file, used in the Preview component * to render the map in the browser. */ -export function previewSourceUrl(options: Options, version = "generate"): string { +export function previewSourceUrl( + options: Options, + version = "generate" +): string { const { projection, year, shapes, simplify } = options; return `/api/${version}?${qs.encode({ format: "topojson", projection, year, - simplify: `${100 - simplify}%`, + simplify: `${100 - parseInt(simplify)}%`, shapes: [...shapes.values()].join(","), })}`; } @@ -55,7 +58,7 @@ export function previewSourceUrl(options: Options, version = "generate"): string * Returns an URL where the user can download the map. These URLs are used by * the Download TopoJSON / SVG buttons. */ - export function downloadUrl(options: Options, version = "generate"): string { +export function downloadUrl(options: Options, version = "generate"): string { const { format, projection, dimensions, year, shapes, simplify } = options; return `/api/${version}?${qs.encode({ @@ -64,7 +67,7 @@ export function previewSourceUrl(options: Options, version = "generate"): string width: dimensions.width, height: dimensions.height, year, - simplify: `${100 - simplify}%`, + simplify: `${100 - parseInt(simplify)}%`, shapes: [...shapes.values()].join(","), download: "", })}`;