Skip to content

Commit

Permalink
refactor: Generate gains ability to have extract mapshaper commands
Browse files Browse the repository at this point in the history
Makes generate more generic
  • Loading branch information
ptbrowne committed Feb 17, 2023
1 parent 483de33 commit 0442bbf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions website/src/pages/api/v0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 ###");
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0442bbf

Please sign in to comment.