-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from ZeLonewolf/1ec5-status-map
Generate maps of supported states, countries for shields
- Loading branch information
Showing
7 changed files
with
5,209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
import * as fs from "fs"; | ||
import * as ShieldDef from "../js/shield_defs.js"; | ||
|
||
function fillPaths(svg, codes) { | ||
let selectors = new Set(codes.map((code) => `.${code.toLowerCase()}`)); | ||
return svg.replace(".supported", new Array(...selectors).join(", ")); | ||
} | ||
|
||
// Inject a map of each sprite ID to an absolute image URL instead of the usual sprite metadata. | ||
let sprites = JSON.parse( | ||
fs.readFileSync(`${process.cwd()}/dist/sprites/sprite.json`) | ||
); | ||
let shieldImageURLs = Object.fromEntries( | ||
Object.keys(sprites).map((sprite) => [ | ||
sprite, | ||
`https://raw.githubusercontent.com/ZeLonewolf/openstreetmap-americana/main/style/icons/${sprite}.svg`, | ||
]) | ||
); | ||
let shields = ShieldDef.loadShields(shieldImageURLs); | ||
|
||
let usSVG = fs.readFileSync(`${process.cwd()}/scripts/blank_map_us.svg`, { | ||
encoding: "utf8", | ||
}); | ||
usSVG = fillPaths( | ||
usSVG, | ||
Object.keys(shields) | ||
.map((network) => network.match(/^US:(\w\w)(?::|$)/)) | ||
.filter((m) => m) | ||
.map((m) => m[1]) | ||
); | ||
usSVG = usSVG.replace( | ||
/<title>.+?<\/title>/, | ||
"<title>U.S. states with shields supported by OpenStreetMap Americana</title>" | ||
); | ||
fs.writeFileSync(`${process.cwd()}/../doc-img/shield_map_us.svg`, usSVG); | ||
|
||
let worldSVG = fs.readFileSync(`${process.cwd()}/scripts/blank_map_world.svg`, { | ||
encoding: "utf8", | ||
}); | ||
worldSVG = fillPaths( | ||
worldSVG, | ||
Object.keys(shields) | ||
.map((network) => network.match(/^(\w\w)(?::|$)/)) | ||
.filter((m) => m) | ||
.map((m) => m[1]) | ||
); | ||
worldSVG = worldSVG.replace( | ||
/<title>.+?<\/title>/, | ||
"<title>Countries with shields supported by OpenStreetMap Americana</title>" | ||
); | ||
fs.writeFileSync(`${process.cwd()}/../doc-img/shield_map_world.svg`, worldSVG); |