From 0442bbf41b64990c2cdbd3d5bd591f4bd10fa9f5 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Fri, 17 Feb 2023 12:23:07 +0100 Subject: [PATCH] refactor: Generate gains ability to have extract mapshaper commands Makes generate more generic --- website/src/pages/api/v0.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/website/src/pages/api/v0.ts b/website/src/pages/api/v0.ts index 1a3a4e06..f26c0a02 100644 --- a/website/src/pages/api/v0.ts +++ b/website/src/pages/api/v0.ts @@ -29,10 +29,12 @@ const generate = async ({ format, shpFilenames, simplify, + mapshaperCommands, }: { format: "topojson" | "svg"; shpFilenames: string[]; simplify: number; + mapshaperCommands?: string[]; }) => { const input = await (async () => { const props = shpFilenames.flatMap((shpFilename) => { @@ -60,12 +62,7 @@ const generate = async ({ simplify ? `-simplify ${simplify} keep-shapes` : "", "-clean", `-proj ${format === "topojson" ? "wgs84" : "somerc"}`, - // svg coloring, otherwise is all bblack - shapes.has("cantons") - ? `-style fill='#e6e6e6' stroke='#999' target='cantons'` - : "", - shapes.has("lakes") ? `-style fill='#a1d0f7' target='lakes'` : "", - `-o output.${format} format=${format} target=*`, + ...(mapshaperCommands || []), ].join("\n"); console.log("### Mapshaper commands ###"); @@ -99,6 +96,14 @@ export default async function handler( shpFilenames: [...options.shapes].map((shapeName) => { return path.join(cwd, "public", "swiss-maps", year, `${shapeName}.shp`); }), + mapshaperCommands: [ + // svg coloring, otherwise is all bblack + shapes.has("cantons") + ? `-style fill='#e6e6e6' stroke='#999' target='cantons'` + : "", + shapes.has("lakes") ? `-style fill='#a1d0f7' target='lakes'` : "", + `-o output.${format} format=${format} target=*`, + ], }); if (query.download !== undefined) {