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

Refactor shields with common shapes #480

Merged
merged 4 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ In addition, the following style guidelines are recommended:

In general, this style is not trying to exactly replicate highway shields as seen on signage. Instead, we are trying to extract the key stylistic elements so that the graphics are recognizable as simplifications of their real-world counterparts. Here are some examples of Americana's simplified shields for small-size readability:

| Network | Real-world Shield | Americana Representation |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| NJ Turnpike | <img src="https://upload.wikimedia.org/wikipedia/commons/a/af/New_Jersey_Turnpike_Shield.svg" width="40"/> | <img src="https://raw.githubusercontent.com/ZeLonewolf/openstreetmap-americana/main/icons/shield40_us_nj_njtp_noref.svg" width="40"/> |
| Washington State Route | <img src="https://upload.wikimedia.org/wikipedia/commons/5/52/WA-blank.svg" width="40"/> | <img src="https://raw.githubusercontent.com/ZeLonewolf/openstreetmap-americana/main/icons/shield40_us_wa.svg" width="40"/> |
| Network | Real-world Shield | Americana Representation |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| NJ Turnpike | <img src="https://upload.wikimedia.org/wikipedia/commons/a/af/New_Jersey_Turnpike_Shield.svg" width="40"/> | <img src="https://raw.githubusercontent.com/ZeLonewolf/openstreetmap-americana/main/icons/shield_us_nj_njtp_noref.svg" width="40"/> |
| Washington State Route | <img src="https://upload.wikimedia.org/wikipedia/commons/5/52/WA-blank.svg" width="40"/> | <img src="https://raw.githubusercontent.com/ZeLonewolf/openstreetmap-americana/main/icons/shield_us_wa.svg" width="40"/> |

More complicated shields may be more challenging to simplify. Consider taking some inspiration from the [rebusurance](https://github.com/1ec5/rebusurance) project, which effectivly simplifies a number of complex state shield designs by stretching, compressing, omitting, or simplifying graphic elements.

Expand Down Expand Up @@ -245,6 +245,7 @@ The `loadShields` function in js/shield_defs.js contains a definition object for
- **`textColor`** – The color of the inscribed text to superimpose on the background.
- **`textHaloColor`** – The color of the halo surrounding the inscribed text.
- **`textLayoutConstraint`** – A strategy for constraining the text within the background image, useful for shields of certain shapes. By default, the text will expand to fill a rectangle bounded by the specified padding while maintaining the same aspect ratio.
- **`verticalReflect`** – Set this property to `true` to draw the shield image upside-down.

If special code is necessary to style a specific `ref` in a particular network, `overrideByRef` can be used to define and override any of the above properties. `overrideByRef` is an object mapping `ref` values to partial shield definition objects, containing whichever properties are to be overridden for that particular `ref` value. If necessary, this can be used to override the entire shield definition.

Expand Down
3 changes: 0 additions & 3 deletions icons/shield40_my.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_trapezoid_down_2.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_trapezoid_down_3.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_tw_provincial.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_us_hi_2.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_us_hi_3.svg

This file was deleted.

3 changes: 0 additions & 3 deletions icons/shield40_us_nc_charlotte.svg

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions icons/shield_hex_vert_yellow.svg
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions icons/shield_tri_convex_2.svg
3 changes: 3 additions & 0 deletions icons/shield_tri_convex_3.svg
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 21 additions & 7 deletions src/js/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as ShieldText from "./shield_text.js";
import * as ShieldDraw from "./shield_canvas_draw.js";
import * as Gfx from "./screen_gfx.js";

function loadShield(ctx, shield, bannerCount) {
function loadShield(ctx, shield, bannerCount, verticalReflect) {
var drawCtx = Gfx.getGfxContext(shield.data);
var imgData = drawCtx.createImageData(shield.data.width, shield.data.height);

Expand All @@ -15,11 +15,25 @@ function loadShield(ctx, shield, bannerCount) {

drawCtx.putImageData(imgData, 0, 0);

ctx.drawImage(
drawCtx.canvas,
0,
bannerCount * ShieldDef.bannerSizeH + ShieldDef.topPadding
);
if (verticalReflect == null) {
ctx.drawImage(
drawCtx.canvas,
0,
bannerCount * ShieldDef.bannerSizeH + ShieldDef.topPadding
);
} else {
ctx.save();
ctx.scale(1, -1);
ctx.drawImage(
drawCtx.canvas,
0,
bannerCount * ShieldDef.bannerSizeH +
ShieldDef.topPadding -
drawCtx.canvas.height -
2 * ShieldDraw.PXR
);
ctx.restore();
}
}

function drawBannerPart(ctx, network, drawFunc) {
Expand Down Expand Up @@ -145,7 +159,7 @@ function drawShield(ctx, shieldDef, routeDef) {
bannerCount * ShieldDef.bannerSizeH + ShieldDef.topPadding
);
} else {
loadShield(ctx, shieldArtwork, bannerCount);
loadShield(ctx, shieldArtwork, bannerCount, shieldDef.verticalReflect);
}

return ctx;
Expand Down
Loading