Skip to content

Commit 53147cc

Browse files
committed
Added Asian Highway Network shields
Added shields for the Asian Highway Network that depend on the country. Added GeoJSON files for line-in-polygon tests.
1 parent 2df639c commit 53147cc

8 files changed

Lines changed: 236 additions & 9 deletions

File tree

icons/shield_in_ah_2.svg

Lines changed: 45 additions & 0 deletions
Loading

icons/shield_in_ah_3.svg

Lines changed: 45 additions & 0 deletions
Loading

icons/shield_in_ah_4.svg

Lines changed: 45 additions & 0 deletions
Loading

scripts/build.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { stat, copyFile, mkdir } from "node:fs/promises";
1+
import { stat, copyFile, cp, mkdir } from "node:fs/promises";
22
import { pathToFileURL } from "node:url";
33

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

2222
const buildWith = async (key, buildOptions) => {
23-
await mkdir("dist", { recursive: true });
23+
await mkdir("dist/features", { recursive: true });
2424
await Promise.all(
2525
["index.html", "shieldtest.html", "favicon.ico"].map((f) =>
2626
copyFile(`src/${f}`, `dist/${f}`)
2727
)
2828
);
29+
await cp("features", "dist/features", {recursive: true});
2930

3031
const localConfig = await maybeLocalConfig();
3132

scripts/status_map.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function fillPaths(svg, codes) {
1313
// Routes in United States insular areas use US prefix with the U.S.
1414
selectors.add(".ust");
1515
}
16+
// The Asian Highway Network isn't a real country.
17+
if (selectors.has(".ah")) {
18+
selectors.delete(".ah");
19+
}
1620
return svg.replace(".supported", new Array(...selectors).join(",\n"));
1721
}
1822

src/js/shield.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ function getShieldDef(routeDef) {
301301
...shieldDef.overrideByRef[routeDef.ref],
302302
};
303303
}
304+
if (shieldDef.overrideByName) {
305+
shieldDef = {
306+
...shieldDef,
307+
...shieldDef.overrideByName[routeDef.wayName],
308+
};
309+
}
304310

305311
//Determine whether a route without a ref gets drawn
306312
if (

src/js/shield_defs.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,32 @@ export function loadShields() {
32383238

32393239
// ASIA
32403240

3241+
// Asian Highway Network
3242+
shields["AsianHighway"] = roundedRectShield(
3243+
Color.shields.blue,
3244+
Color.shields.white
3245+
);
3246+
shields["AsianHighway"].overrideByName = {
3247+
green: roundedRectShield(Color.shields.green, Color.shields.white),
3248+
green_in: {
3249+
spriteBlank: ["shield_in_ah_2", "shield_in_ah_3", "shield_in_ah_4"],
3250+
textColor: Color.shields.white,
3251+
padding: {
3252+
left: 2,
3253+
right: 2,
3254+
top: 2,
3255+
bottom: 7,
3256+
},
3257+
},
3258+
white: roundedRectShield(Color.shields.white, Color.shields.black),
3259+
white_id: roundedRectShield(
3260+
Color.shields.white,
3261+
Color.shields.green,
3262+
Color.shields.black
3263+
),
3264+
};
3265+
shields["AH"] = shields["AsianHighway"];
3266+
32413267
// Armenia
32423268
shields["am:national"] = roundedRectShield(
32433269
Color.shields.blue,

src/layer/highway_shield.js

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,71 @@ export const namedRouteNetworks = [
77
"US:TX:Harris:HCTRA",
88
];
99

10+
let AsianHighwayBorders = {};
11+
12+
export async function fetchFeatures(baseURL) {
13+
if (Object.keys(AsianHighwayBorders).length !== 0) {
14+
return;
15+
}
16+
17+
let fetchFile = async function (name) {
18+
let response = await fetch(`features/${name}.geojson`);
19+
if (response.ok) {
20+
AsianHighwayBorders[name] = await response.json();
21+
} else {
22+
throw response;
23+
}
24+
};
25+
await Promise.all([
26+
"az-cn-ir", "id", "in", "jp-kr",
27+
].map(f => fetchFile(f)));
28+
}
29+
1030
export function getImageNameExpression(routeIndex) {
31+
const nullIsland = {type: "Polygon", coordinates: [[[0, 0], [0, 0], [0, 0]]]};
32+
1133
return [
12-
"concat",
13-
"shield\n",
34+
"let",
35+
"route",
1436
["get", "route_" + routeIndex],
1537
[
16-
"match",
17-
["get", "route_" + routeIndex],
18-
namedRouteNetworks.map((n) => n + "="),
19-
["concat", "\n", ["get", "name"]],
20-
"",
38+
"concat",
39+
"shield\n",
40+
["var", "route"],
41+
[
42+
"match",
43+
["var", "route"],
44+
namedRouteNetworks.map((n) => n + "="),
45+
["concat", "\n", ["get", "name"]],
46+
"",
47+
],
48+
[
49+
"match",
50+
["slice", ["var", "route"], 0, ["index-of", "=", ["var", "route"]]],
51+
["AsianHighway", "AH"],
52+
[
53+
"concat",
54+
"\n",
55+
[
56+
"case",
57+
// Azerbaijan, China, Iran
58+
["within", AsianHighwayBorders["az-cn-ir"] || nullIsland],
59+
"green",
60+
// Japan, South Korea
61+
["within", AsianHighwayBorders["jp-kr"] || nullIsland],
62+
"white",
63+
// Indonesia
64+
["within", AsianHighwayBorders.id || nullIsland],
65+
"white_id",
66+
// India
67+
["within", AsianHighwayBorders.in || nullIsland],
68+
"green_in",
69+
// Armenia, Cambodia, Malaysia, Myanmar, Philippines, Russia, Thailand, Vietnam
70+
"blue",
71+
],
72+
],
73+
"",
74+
],
2175
],
2276
];
2377
}
@@ -43,6 +97,7 @@ export function parseImageName(imageName) {
4397
return { imageName, network, ref, name };
4498
}
4599

100+
await fetchFeatures();
46101
let shieldTextField = ["format"];
47102
for (var i = 1; i <= 6; i++) {
48103
shieldTextField.push(routeConcurrency(i));

0 commit comments

Comments
 (0)