Skip to content

Commit

Permalink
Merge branch 'main' into clay-shields-refactor-special-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
claysmalley authored Jun 1, 2024
2 parents 79fcd73 + 7b75a99 commit e0baed8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 36 deletions.
4 changes: 4 additions & 0 deletions icons/place_dot_in_circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions icons/shield_us_al_foley.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions icons/shield_us_ut_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions icons/shield_us_ut_3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions shieldlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ You should create one definition entry for each network. The entry key must matc
"top": 3,
"bottom": 3
},
"spriteBlank": "name_of_image_1",
"spriteBlank": ["name_of_image_2", "name_of_image_3", "name_of_image_4"],
"noref": {
"spriteBlank": "name_of_image_2"
"spriteBlank": "name_of_image_noref"
}
"shapeBlank": {
"drawFunc": "pentagon",
Expand Down Expand Up @@ -168,7 +168,8 @@ You should create one definition entry for each network. The entry key must matc
- **`textColor`**: determines what color to draw the `ref` on the shield.
- **`textHaloColor`**: color to draw a knockout halo around the `ref` text.
- **`padding`**: padding around the `ref`, which allows you to squeeze the text into a smaller space within the shield.
- **`spriteBlank`**: specify the name of an image in the sprite sheet to use as the shield background. This can either be a single string or an array of strings if there are multiple options for different width. If it's an array of strings, they must be ordered from narrowest to widest, and the engine will choose the narrowest shield graphic that fits the text at a reasonable size.
- **`spriteBlank`**: specify the name of an image in the sprite sheet to use as the shield background. This can either be a single string or an array of strings if there are multiple options for different width.
- If `spriteBlank` is an array of strings, they must be ordered from narrowest to widest, and the filenames must be suffixed with a consecutive range of integers, representing the optimal number of characters to display in each icon.
- **`noref`**: specify alternate attributes to apply in the event that no `ref` is supplied. This allows you to use one graphic for numbered routes and a separate unitary graphic for non-numbered routes within the same network. Supports **`spriteBlank`**, **`colorLighten`**, and **`colorDarken`**.
- **`shapeBlank`**: specify that a shield should be drawn as a common shape (rectangle, ellipse, pentagon, etc), with colors and dimensions as specified. See the [drawn shield shapes](#defining-drawn-shield-shapes) section for available drawing options.
- **`banners`**: specify that one or more short text strings (up to 4 characters) should be drawn above the shield. This is specified as an array, and text will be drawn in order from top to bottom. Below is an example of bannered shields with up to three banners:
Expand Down Expand Up @@ -234,7 +235,7 @@ This effect can be achieved by overriding the text and sprite color in the route

```json
"US:GA": {
"spriteBlank": ["shield_us_ga_narrow", "shield_us_ga_wide"],
"spriteBlank": ["shield_us_ga_2", "shield_us_ga_3"],
"textColor": "black",
"overrideByRef": {
"520": {
Expand Down
30 changes: 17 additions & 13 deletions shieldlib/src/shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
import { TextPlacement } from "./shield_text";
import { StyleImage } from "maplibre-gl";

const narrowCharacters = /[1IJijl .-]/g;

function compoundShieldSize(
r: ShieldRenderingContext,
dimension: Dimension,
Expand Down Expand Up @@ -51,20 +53,22 @@ function getRasterShieldBlank(
let bounds: Dimension;

if (Array.isArray(shieldDef.spriteBlank)) {
for (var i = 0; i < shieldDef.spriteBlank.length; i++) {
shieldArtwork = r.spriteRepo.getSprite(shieldDef.spriteBlank[i]);
// Certain narrow characters count as two-thirds of a character
let narrowCharacterCount = (routeDef.ref.match(narrowCharacters) ?? [])
.length;
let refLength = Math.ceil(routeDef.ref.length - narrowCharacterCount / 3);

// Choose icon based on optimal character length at end of filename
let finalIndex = shieldDef.spriteBlank.length - 1;
let optimalCharacters = shieldDef.spriteBlank.map((blank) =>
parseInt(blank.split("_").reverse()[0])
);
let spriteIndex =
refLength > optimalCharacters[finalIndex]
? finalIndex
: Math.max(0, optimalCharacters.indexOf(refLength));

bounds = compoundShieldSize(r, shieldArtwork.data, bannerCount);
textPlacement = ShieldText.layoutShieldTextFromDef(
r,
routeDef.ref,
shieldDef,
bounds
);
if (textPlacement.fontPx > r.px(Gfx.fontSizeThreshold)) {
break;
}
}
shieldArtwork = r.spriteRepo.getSprite(shieldDef.spriteBlank[spriteIndex]);
} else {
shieldArtwork = r.spriteRepo.getSprite(shieldDef.spriteBlank);
}
Expand Down
11 changes: 10 additions & 1 deletion src/js/shield_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ export function loadShields() {

shields["US:I:Alternate"] = banneredShield(shields["US:I"], ["ALT"]);
shields["US:I:Future"] = banneredShield(shields["US:I"], ["FUT"]);
shields["US:I:Spur"] = banneredShield(shields["US:I"], ["SPUR"]);
shields["US:I:Truck"] = banneredShield(shields["US:I"], ["TRK"]);
shields["US:I:Express"] = banneredShield(shields["US:I"], ["EXPR"]);
shields["US:I:Express:Toll"] = shields["US:I:Express"];
Expand Down Expand Up @@ -781,6 +782,14 @@ export function loadShields() {
Color.shields.yellow
))
);
shields["US:AL:Baldwin:Baldwin_Beach_Express"] = {
...roundedRectShield(Color.shields.green, Color.shields.white),
ref: "BBX",
};
shields["US:AL:Baldwin:Foley_Beach_Express"] = {
spriteBlank: "shield_us_al_foley",
notext: true,
};

// Arizona
shields["US:AZ:Scenic"] = {
Expand Down Expand Up @@ -2728,7 +2737,7 @@ export function loadShields() {
padding: {
left: 4,
right: 4,
top: 5.5,
top: 6,
bottom: 5,
},
};
Expand Down
42 changes: 29 additions & 13 deletions src/layer/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ const minorLocationStepFilter = [
[">=", ["get", "rank"], 1],
];

const iconImage = [
"match",
["get", "capital"],
2,
"place_star_in_circle",
3,
"place_star",
4,
"place_star",
5,
"place_dot_in_circle",
6,
"place_dot_in_circle",
"place_dot",
];

function filterPlace(type) {
return ["==", ["get", "class"], type];
}
Expand All @@ -53,7 +69,7 @@ export const village = {
[12, 12],
],
},
"icon-image": "place_dot",
"icon-image": iconImage,
"icon-size": {
base: 1.0,
stops: [
Expand Down Expand Up @@ -100,7 +116,7 @@ export const town = {
[12, 18],
],
},
"icon-image": "place_dot",
"icon-image": iconImage,
"icon-size": {
base: 1.2,
stops: [
Expand Down Expand Up @@ -159,17 +175,7 @@ export const city = {
[11, 24],
],
},
"icon-image": [
"match",
["get", "capital"],
2,
"place_star_in_circle",
3,
"place_star",
4,
"place_star",
"place_dot",
],
"icon-image": iconImage,
"icon-size": {
base: 1.2,
stops: [
Expand Down Expand Up @@ -451,4 +457,14 @@ export const legendEntries = [
layers: populatedPlaceLayers,
filter: ["==", ["get", "capital"], 4],
},
{
description: "Local capital",
layers: populatedPlaceLayers,
filter: ["==", ["get", "capital"], 5],
},
{
description: "County seat or equivalent",
layers: populatedPlaceLayers,
filter: ["==", ["get", "capital"], 6],
},
];

0 comments on commit e0baed8

Please sign in to comment.