Skip to content

Commit

Permalink
fix: Correctly type simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Feb 17, 2023
1 parent 0442bbf commit 11ad9ac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions website/src/pages/api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const parseOptions = (req: NextApiRequest, res: NextApiResponse) => {
if (query.shapes) {
draft.shapes = new Set<Shape>(query.shapes.split(",") as $FixMe);
}
if (query.simplify) {
draft.simplify = query.simplify;
}
});

return options;
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/api/v0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const generate = async ({
}: {
format: "topojson" | "svg";
shpFilenames: string[];
simplify: number;
simplify: string;
mapshaperCommands?: string[];
}) => {
const input = await (async () => {
Expand Down
15 changes: 9 additions & 6 deletions website/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Options {
projection: "wgs84" | "cartesian";
dimensions: { width: number; height: number };
year: string;
simplify: number;
simplify: string;
shapes: Set<Shape>;
color: SupportedColorSchema;
withName: boolean;
Expand All @@ -29,7 +29,7 @@ export const defaultOptions: Options = {
projection: "wgs84",
dimensions: { width: 900, height: 600 },
year: "2022",
simplify: 0,
simplify: "0%",
shapes: new Set<Shape>(["country", "cantons", "lakes"]),
color: "default",
withName: true,
Expand All @@ -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(","),
})}`;
}
Expand All @@ -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({
Expand All @@ -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: "",
})}`;
Expand Down

0 comments on commit 11ad9ac

Please sign in to comment.