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

Replace shield icons for Mexican federal highways #1096

Merged
merged 7 commits into from
Jun 22, 2024
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
4 changes: 0 additions & 4 deletions icons/shield_mx_mx.svg

This file was deleted.

4 changes: 4 additions & 0 deletions icons/shield_mx_mx_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions icons/shield_mx_mx_3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions icons/shield_mx_mx_4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion shieldlib/src/shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TextPlacement } from "./shield_text";
import { StyleImage } from "maplibre-gl";

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

function compoundShieldSize(
r: ShieldRenderingContext,
Expand All @@ -30,7 +31,7 @@ function compoundShieldSize(
}

export function isValidRef(ref: string): boolean {
return ref !== null && ref.length !== 0 && ref.length <= 6;
return ref !== null && ref.length !== 0 && ref.length <= maxRefLength;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/js/shield_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,13 @@ export function loadShields() {

// Carreteras Federales
shields["MX:MX"] = {
spriteBlank: "shield_mx_mx",
spriteBlank: ["shield_mx_mx_2", "shield_mx_mx_3", "shield_mx_mx_4"],
textLayout: textConstraint("ellipse"),
padding: {
left: 2,
right: 2,
top: 3,
bottom: 2,
left: 1,
right: 1,
top: 5,
bottom: 4,
},
};
[
Expand Down
2 changes: 1 addition & 1 deletion src/shieldtest.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<thead>
<tr>
<th>Network</th>
<th colspan="14">Graphic</th>
<th colspan="16">Graphic</th>
<th>Performance</th>
</tr>
</thead>
Expand Down
3 changes: 3 additions & 0 deletions src/shieldtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ let networks = [
"CA:PE",
"US:FL:Toll",
"CA:BC",
"MX:MX",
"IN:NH",
"PK:motorway",
"US:US",
Expand Down Expand Up @@ -260,6 +261,8 @@ let refs = [
"A 562",
"1138-2",
"A26/A7",
"GUA 10D",
"SS18var",
];

export function getShieldCanvas(network, ref, name) {
Expand Down
10 changes: 5 additions & 5 deletions test/spec/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const handler = shieldRenderer.getStyleImageMissingHandler();

handler({ id: "shield\nBAB\n5\n\n" });
handler({ id: "shield\nUS:RI\n\n\n" });
handler({ id: "shield\nUS:RI\nABC123\n\n" });
handler({ id: "shield\nUS:RI\nEquator\n\n" });
handler({ id: "shield\nUS:RI\nABC1234\n\n" });
handler({ id: "shield\nUS:RI\nLatitude\n\n" });
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
handler({ id: "shield\nrwn\n\n\n" });
handler({ id: "foo" });

Expand All @@ -51,9 +51,9 @@ describe("shield", function () {
expect(isBlankSprite("shield\nUS:RI\n\n\n")).to.be.true;
});
it("rejects a long ref", function () {
expect(mockRepo.hasSprite("shield\nUS:RI\nABC123\n\n")).to.be.true;
expect(isBlankSprite("shield\nUS:RI\nABC123\n\n")).to.be.false;
expect(isBlankSprite("shield\nUS:RI\nEquator\n\n")).to.be.true;
expect(mockRepo.hasSprite("shield\nUS:RI\nABC1234\n\n")).to.be.true;
expect(isBlankSprite("shield\nUS:RI\nABC1234\n\n")).to.be.false;
expect(isBlankSprite("shield\nUS:RI\nLatitude\n\n")).to.be.true;
ZeLonewolf marked this conversation as resolved.
Show resolved Hide resolved
});
});
});