Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ShieldJSON to specify a map of banners on a base shield instead of requiring separate entries #1073

Merged
merged 59 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
73598d1
Implement banner maps
ZeLonewolf May 19, 2024
7103ca1
Merge branch 'main' into zlw-banner-map
ZeLonewolf May 19, 2024
78c25dd
Formatter
ZeLonewolf May 19, 2024
ee38238
Merge branch 'main' into zlw-banner-map
ZeLonewolf May 20, 2024
8c409e0
Merge branch 'main' into zlw-banner-map
ZeLonewolf May 30, 2024
89bb74e
Update shield_defs.js
ZeLonewolf May 30, 2024
f69ce57
Consolidate banners for US:I
ZeLonewolf May 30, 2024
d02d86a
Alabama truck routes
ZeLonewolf May 30, 2024
7640be3
Merge branch 'main' into zlw-banner-map
ZeLonewolf May 30, 2024
7118dfd
Add banners for US:AZ
ZeLonewolf May 30, 2024
06c3e5e
Add banners for US:DE routes
ZeLonewolf May 30, 2024
b70aaf9
code format
ZeLonewolf May 31, 2024
9672bac
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 1, 2024
1dc541f
FL truck route
ZeLonewolf Jun 1, 2024
8e7dc7a
Add Georgia banners
ZeLonewolf Jun 1, 2024
30d9bb3
Revert accidental changes
ZeLonewolf Jun 1, 2024
15c5055
Idaho business routes
ZeLonewolf Jun 1, 2024
37336d0
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 1, 2024
7729bd2
Kentucky
ZeLonewolf Jun 1, 2024
a18a2d9
Louisiana
ZeLonewolf Jun 1, 2024
0f1ea1d
Maryland
ZeLonewolf Jun 1, 2024
16a92ec
Merge branch 'main' into zlw-banner-map
claysmalley Jun 1, 2024
08f040b
Maine
ZeLonewolf Jun 1, 2024
d563d73
Merge branch 'zlw-banner-map' of github.com:ZeLonewolf/openstreetmap-…
ZeLonewolf Jun 1, 2024
bc0dff7
Michigan
ZeLonewolf Jun 1, 2024
8d7bc46
Missouri
ZeLonewolf Jun 1, 2024
187276e
Fix formatting
ZeLonewolf Jun 1, 2024
0c53b5a
North Carolina
ZeLonewolf Jun 1, 2024
9ca4f13
North Dakota
ZeLonewolf Jun 1, 2024
3848b88
Nebraska
ZeLonewolf Jun 1, 2024
4abd9a2
New Hampshire
ZeLonewolf Jun 1, 2024
963aa6d
New Jersey
ZeLonewolf Jun 1, 2024
8df339d
New York
ZeLonewolf Jun 1, 2024
7aa0d47
Ohio
ZeLonewolf Jun 1, 2024
9ad1ad7
Oklahoma
ZeLonewolf Jun 1, 2024
65ab136
Oregon
ZeLonewolf Jun 1, 2024
9aa2077
PA and SC
ZeLonewolf Jun 1, 2024
c5ce6a2
South Dakota
ZeLonewolf Jun 1, 2024
5759d19
Tennessee
ZeLonewolf Jun 1, 2024
3ec8203
Texas
ZeLonewolf Jun 1, 2024
f1afce5
Virgina
ZeLonewolf Jun 1, 2024
4cd493d
Vermont
ZeLonewolf Jun 1, 2024
042f0d9
Washington state
ZeLonewolf Jun 1, 2024
202a236
Indonesia
ZeLonewolf Jun 1, 2024
9715115
Bump shieldlib version
ZeLonewolf Jun 1, 2024
e9bbe83
Add bannerMap to docs
ZeLonewolf Jun 1, 2024
dded6d6
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 3, 2024
2c595cc
Update src/js/shield_defs.js
ZeLonewolf Jun 4, 2024
013f636
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 5, 2024
3ce0ab7
Update shield_defs.js
ZeLonewolf Jun 5, 2024
fd6fb81
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 5, 2024
d2e8826
Update shield_defs.js
ZeLonewolf Jun 5, 2024
97fb4a4
Update shield_defs.js
ZeLonewolf Jun 5, 2024
a04de92
Update shield_defs.js
ZeLonewolf Jun 5, 2024
38aeaf8
prettier
ZeLonewolf Jun 5, 2024
f653f84
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jun 20, 2024
c4be9fd
Merge branch 'main' into zlw-banner-map
ZeLonewolf Jul 17, 2024
4824343
Merge branch 'main' into zlw-banner-map
ZeLonewolf Aug 4, 2024
2b48f32
Merge branch 'main' into zlw-banner-map
claysmalley Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions shieldlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ You should create one definition entry for each network. The entry key must matc
}
},
"banners": ["ALT"],
"bannerMap": {
"ThisNetwork:Truck": ["TRK"],
"ThisNetwork:Truck:Bypass": ["TRK", "BYP"]
},
"bannerTextColor": "#000",
"bannerTextHaloColor": "#FFF",
"textLayout": {
Expand Down Expand Up @@ -176,6 +180,7 @@ You should create one definition entry for each network. The entry key must matc

![Bannered routes near Downington, PA](https://wiki.openstreetmap.org/w/images/f/f8/Downington_bannered_routes_Americana.png)

- **`bannerMap`**: a map of network-to-banner arrays listing networks that should have the same style but with specified banners.
- **`bannerTextColor`**: specify the color of the banner text.
- **`bannerTextHaloColor`**: specify the color of the banner knockout halo.
- **`textLayout`**: specify how text should be inscribed within the padded bounds of the shield. The text will be drawn at the maximum size allowed by this constraint. See the [text layout functions](#text-layout-functions) section for text layout options.
Expand Down
25 changes: 25 additions & 0 deletions shieldlib/src/shield_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RouteDefinition,
RouteParser,
ShapeBlankParams,
ShieldDefinition,
ShieldDefinitions,
ShieldOptions,
ShieldSpecification,
Expand Down Expand Up @@ -104,6 +105,30 @@ export class AbstractShieldRenderer {
/** Specify which shields to draw and with what graphics */
protected setShields(shieldSpec: ShieldSpecification) {
this._renderContext.options = shieldSpec.options;

// Unpack any banner maps and compose them as separate network entries in-memory
for (const [key, shieldDef] of Object.entries(shieldSpec.networks)) {
if (!shieldDef) {
continue; // Skip if shieldDef is null or undefined
}

// Check to see if it has a bannerMap
if (shieldDef.bannerMap) {
// If it does, loop through each entry in the bannerMap
for (const [bannerKey, banners] of Object.entries(
shieldDef.bannerMap
)) {
// Make a copy of the ShieldDefinition and attach the banners
const banneredShieldDef: ShieldDefinition = {
...shieldDef,
banners: banners,
};
// Insert this modified ShieldDefinition into the global network list
shieldSpec.networks[bannerKey] = banneredShieldDef;
}
}
}

this._renderContext.shieldDef = shieldSpec.networks;
this._fontSpec = "1em " + shieldSpec.options.shieldFont;
console.log("ShieldJSON loaded");
Expand Down
4 changes: 4 additions & 0 deletions shieldlib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export interface ShieldDefinitionBase {
textLayout?: TextLayout;
/** Banners to be drawn above a shield */
banners?: string[];
/** Map of additional networks that are bannered variants of this one */
bannerMap?: {
[key: string]: string[];
};
/** If true, no next should be drawn on this shield */
notext?: boolean;
/** Maximum size of shield text */
Expand Down
Loading