Skip to content

Commit

Permalink
Added Asian Highway Network shields
Browse files Browse the repository at this point in the history
Added shields for the Asian Highway Network that depend on the country. Added GeoJSON files for line-in-polygon tests.
  • Loading branch information
1ec5 committed Jan 31, 2023
1 parent 2df639c commit 53147cc
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 9 deletions.
45 changes: 45 additions & 0 deletions icons/shield_in_ah_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions icons/shield_in_ah_3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions icons/shield_in_ah_4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stat, copyFile, mkdir } from "node:fs/promises";
import { stat, copyFile, cp, mkdir } from "node:fs/promises";
import { pathToFileURL } from "node:url";

import esbuild from "esbuild";
Expand All @@ -20,12 +20,13 @@ const maybeLocalConfig = async (name = "local.config.js") => {
};

const buildWith = async (key, buildOptions) => {
await mkdir("dist", { recursive: true });
await mkdir("dist/features", { recursive: true });
await Promise.all(
["index.html", "shieldtest.html", "favicon.ico"].map((f) =>
copyFile(`src/${f}`, `dist/${f}`)
)
);
await cp("features", "dist/features", {recursive: true});

const localConfig = await maybeLocalConfig();

Expand Down
4 changes: 4 additions & 0 deletions scripts/status_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function fillPaths(svg, codes) {
// Routes in United States insular areas use US prefix with the U.S.
selectors.add(".ust");
}
// The Asian Highway Network isn't a real country.
if (selectors.has(".ah")) {
selectors.delete(".ah");
}
return svg.replace(".supported", new Array(...selectors).join(",\n"));
}

Expand Down
6 changes: 6 additions & 0 deletions src/js/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ function getShieldDef(routeDef) {
...shieldDef.overrideByRef[routeDef.ref],
};
}
if (shieldDef.overrideByName) {
shieldDef = {
...shieldDef,
...shieldDef.overrideByName[routeDef.wayName],
};
}

//Determine whether a route without a ref gets drawn
if (
Expand Down
26 changes: 26 additions & 0 deletions src/js/shield_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,32 @@ export function loadShields() {

// ASIA

// Asian Highway Network
shields["AsianHighway"] = roundedRectShield(
Color.shields.blue,
Color.shields.white
);
shields["AsianHighway"].overrideByName = {
green: roundedRectShield(Color.shields.green, Color.shields.white),
green_in: {
spriteBlank: ["shield_in_ah_2", "shield_in_ah_3", "shield_in_ah_4"],
textColor: Color.shields.white,
padding: {
left: 2,
right: 2,
top: 2,
bottom: 7,
},
},
white: roundedRectShield(Color.shields.white, Color.shields.black),
white_id: roundedRectShield(
Color.shields.white,
Color.shields.green,
Color.shields.black
),
};
shields["AH"] = shields["AsianHighway"];

// Armenia
shields["am:national"] = roundedRectShield(
Color.shields.blue,
Expand Down
69 changes: 62 additions & 7 deletions src/layer/highway_shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,71 @@ export const namedRouteNetworks = [
"US:TX:Harris:HCTRA",
];

let AsianHighwayBorders = {};

export async function fetchFeatures(baseURL) {
if (Object.keys(AsianHighwayBorders).length !== 0) {
return;
}

let fetchFile = async function (name) {
let response = await fetch(`features/${name}.geojson`);
if (response.ok) {
AsianHighwayBorders[name] = await response.json();
} else {
throw response;
}
};
await Promise.all([
"az-cn-ir", "id", "in", "jp-kr",
].map(f => fetchFile(f)));
}

export function getImageNameExpression(routeIndex) {
const nullIsland = {type: "Polygon", coordinates: [[[0, 0], [0, 0], [0, 0]]]};

return [
"concat",
"shield\n",
"let",
"route",
["get", "route_" + routeIndex],
[
"match",
["get", "route_" + routeIndex],
namedRouteNetworks.map((n) => n + "="),
["concat", "\n", ["get", "name"]],
"",
"concat",
"shield\n",
["var", "route"],
[
"match",
["var", "route"],
namedRouteNetworks.map((n) => n + "="),
["concat", "\n", ["get", "name"]],
"",
],
[
"match",
["slice", ["var", "route"], 0, ["index-of", "=", ["var", "route"]]],
["AsianHighway", "AH"],
[
"concat",
"\n",
[
"case",
// Azerbaijan, China, Iran
["within", AsianHighwayBorders["az-cn-ir"] || nullIsland],
"green",
// Japan, South Korea
["within", AsianHighwayBorders["jp-kr"] || nullIsland],
"white",
// Indonesia
["within", AsianHighwayBorders.id || nullIsland],
"white_id",
// India
["within", AsianHighwayBorders.in || nullIsland],
"green_in",
// Armenia, Cambodia, Malaysia, Myanmar, Philippines, Russia, Thailand, Vietnam
"blue",
],
],
"",
],
],
];
}
Expand All @@ -43,6 +97,7 @@ export function parseImageName(imageName) {
return { imageName, network, ref, name };
}

await fetchFeatures();
let shieldTextField = ["format"];
for (var i = 1; i <= 6; i++) {
shieldTextField.push(routeConcurrency(i));
Expand Down

0 comments on commit 53147cc

Please sign in to comment.